Exemplo n.º 1
0
	std::string toString<stringmap>(const stringmap &v)
	{
		std::ostringstream oss;
		oss << "std::map( ";
		for (stringmap::const_iterator it = v.begin(); it != v.end(); ++it) {
			oss << it->first << " = " << it->second;

			stringmap::const_iterator jt(it);
			if (++jt != v.end()) oss << ", ";
		}
		oss << " )";
		return oss.str();
	}
Exemplo n.º 2
0
 std::vector<std::string> extract_keys_from_string_map
     (stringmap const& keyword_dictionary
     )
 {
     std::vector<std::string> keywords;
     stringmap_iterator i_keyword_dictionary = keyword_dictionary.begin();
     for
         (
         ;i_keyword_dictionary != keyword_dictionary.end()
         ;++i_keyword_dictionary
         )
         {
         keywords.push_back((*i_keyword_dictionary).first);
         }
     return keywords;
 }
Exemplo n.º 3
0
void insert_element(stringmap &map, const Node &node, pthread_rwlock_t *lock, ofstream &fout){
  bool to_write = false;
  string key;

  try{
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    key = name + version;
  }catch(...){
    return;
  }

  pthread_rwlock_rdlock(lock);
    if(map.find(key) == map.end()){
      to_write = true;
    }
  pthread_rwlock_unlock(lock);


  if(to_write){
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    string key = name + version;

    pthread_rwlock_wrlock(lock);

    map.insert(make_pair(key, ""));

    Emitter out;
    out << BeginSeq;
    out << node;
    out << EndSeq;
    fout << out.c_str() << endl;


    if(node["status"].as<string>() != "ok"){
      broken++;
    }

    total++;

    pthread_rwlock_unlock(lock);
  }
}
Exemplo n.º 4
0
void
show
(
   const std::string & tag,
   const stringmap<VALUETYPE> & container
)
{
   fprintf
   (
      stdout,
      "- xpc::stringmap '%s':\n"
      "-    Name:                    '%s'\n"
      "-    Size:                     %d\n"
      ,
      tag.c_str(),
      container.name().c_str(),
      int(container.size())
   );
   std::for_each(container.begin(), container.end(), show_pair<VALUETYPE>);
}
stringmap merge(stringmap a, stringmap b)
{
	stringmap tmp(a);
	tmp.insert(b.begin(),b.end());
	return tmp;
}
Exemplo n.º 6
0
void insert_element(stringmap &map, const Node &node, pthread_rwlock_t *lock, ofstream &fout, string date){
  bool to_write = false;
  string key;

  try{
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    key = name + version;
  }catch(...){
    return;
  }

  pthread_rwlock_rdlock(lock);
    if(map.find(key) == map.end()){
      to_write = true;
    }
  pthread_rwlock_unlock(lock);


  if(to_write){
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    string number = node["number"].as<string>();
    string key = name + version;
    string status = node["status"].as<string>();

    string set;

    if(status == "ok"){

      ostringstream out_set;
      out_set << "[";

      auto install =  node["installationset"];

      for(size_t i = 0; i < install.size(); i++){
        out_set << "{";
        out_set << "\"" << install[i]["package"] << "\"" << ":" << "\"" << install[i]["version"] << "\"";
        out_set << "}";

        if(i + 1 != install.size()){
          out_set << ",";
        }
      }

      out_set << "]";

      set = out_set.str();
    }else{

      ostringstream out_set;
      auto reasons = node["reasons"];
      out_set << "[";

      for(size_t i = 0; i < reasons.size(); i++){
        out_set << "{";

        auto missing = reasons[i]["missing"];
        auto pkg = missing["pkg"];
          //YAML::Emitter out;
          //out << node["reasons"];
          //cout << out.c_str() << endl;
          //exit(-1);
        //}
        auto depchains = missing["depchains"];

        string unsat = pkg["unsat-dependency"].as<string>();
        string version_unsat = pkg["version"].as<string>();

        out_set << "\"unsat\": \"" << unsat << "\", ";
        out_set << "\"version\": \"" << version_unsat << "\"";
        out_set << "}";

        if(i + 1 != reasons.size()){
          out_set << ",";
        }
      }
      out_set << "]";
      set = out_set.str();
    }



//- reasons:
    //- missing:
        //pkg:
          //unsat-dependency: system.collections.generic (>= 1)
          //version: 2
          //package: windows.applicationmodel.datatransfer
        //depchains:
          //- depchain:
              //- version: 1
                //depends: windows.graphics.printing (>= 1)
                //package: windows.graphics.printing.optiondetails
              //- depends: windows.applicationmodel.datatransfer (>= 1)
                //version: 2
                //package: windows.graphics.printing

  //reasons:
    //- missing:
        //pkg:
          //version: 18
          //unsat-dependency: node-authorizenet (>= 1)
          //package: 42-cent




    string str_status;
    
    if(status == "ok"){
      str_status = "true";
    }else{
      str_status = "false";
    }

    ostringstream out;
    out << "{\"name\": " << "\"" << name << "\"";
    out << ", \"version\": " << "\"" << version << "\"";
    out << ", \"number\": " << "\"" << number << "\"";
    out << ", \"status\": " << "\"" << str_status << "\"";
    out << ", \"date\": " << "{ $date: \"" << date << "T00:00:00Z" << "\"}";
    out << ", \"set\": " << set << "}";


    pthread_rwlock_wrlock(lock);

    fout << out.str() << endl;

    if(status != "ok"){
      broken++;
    }

    total++;
    map.insert(make_pair(key, ""));

    pthread_rwlock_unlock(lock);
  }
}