static void sendEstateOwnerMessage(
	LLMessageSystem* msg,
	const std::string& request,
	const LLUUID& invoice,
	const strings_t& strings)
{
	llinfos << "Sending estate request '" << request << "'" << llendl;
	msg->newMessage("EstateOwnerMessage");
	msg->nextBlockFast(_PREHASH_AgentData);
	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
	msg->nextBlock("MethodData");
	msg->addString("Method", request);
	msg->addUUID("Invoice", invoice);
	if(strings.empty())
	{
		msg->nextBlock("ParamList");
		msg->addString("Parameter", NULL);
	}
	else
	{
		strings_t::const_iterator it = strings.begin();
		strings_t::const_iterator end = strings.end();
		for(; it != end; ++it)
		{
			msg->nextBlock("ParamList");
			msg->addString("Parameter", *it);
		}
	}
	msg->sendReliable(gAgent.getRegion()->getHost());
}
Exemplo n.º 2
0
void load(fs_t& fs) {
    // this is just some silly test code - find a random model
    std::auto_ptr<techtrees_t> techtrees(new techtrees_t(fs));
    const strings_t techtrees_ = techtrees->get_techtrees();
    const std::string techtree_ = techtrees_[rand()%techtrees_.size()];
    techtree.reset(new techtree_t(fs,techtree_));
    const strings_t factions = techtree->get_factions();
    const std::string faction_ = factions[rand()%factions.size()];
    faction_t& faction = techtree->get_faction(faction_);
    const strings_t units = fs.list_dirs(faction.path+"/units");
    const std::string unit_ = units[rand()%units.size()];
    const std::string unit = faction.path+"/units/"+unit_;
    const std::string xml_name = unit+"/"+unit_+".xml";
    const strings_t models = fs.list_files(unit+"/models");
    std::string g3d;
    for(strings_t::const_iterator i=models.begin(); i!=models.end(); i++)
        if(i->find(".g3d") == (i->size()-4)) {
            g3d = unit + "/models/" + *i;
            break;
        }
    if(!g3d.size()) data_error("no G3D models in "<<unit<<"/models");
    std::cout << "loading "<<g3d<<std::endl;
    fs_file_t::ptr_t g3d_file(fs.get(g3d));
    istream_t::ptr_t gstream(g3d_file->reader());
    model = std::auto_ptr<model_g3d_t>(new model_g3d_t(*gstream));
    // and load it
    std::cout << "loading "<<xml_name<<std::endl;
    fs_file_t::ptr_t xml_file(fs.get(xml_name));
    istream_t::ptr_t xstream(xml_file->reader());
    unit_type = std::auto_ptr<unit_type_t>(new unit_type_t(faction,unit_));
    unit_type->load_xml(*xstream);
    //new ui_xml_editor_t(*unit_type);
}
Exemplo n.º 3
0
        std::vector<std::pair<ncv::string_t, ncv::string_t> > make_grad_configs(
                ncv::size_t& irows, ncv::size_t& icols, ncv::size_t& outputs, ncv::color_mode& color)
        {
                // evaluate the analytical gradient vs. the finite difference approximation for various:
                //      * convolution layers
                //      * convolution connection types
                //      * pooling layers
                //      * fully connected layers
                //      * activation layers
                std::set<string_t> descs;
                for (size_t n_layers = 0; n_layers <= cmd_max_layers; n_layers ++)
                {
                        for (const string_t& actv_layer_id : actv_layer_ids)
                        {
                                for (const string_t& pool_layer_id : pool_layer_ids)
                                {
                                        for (const string_t& conv_layer_id : conv_layer_ids)
                                        {
                                                for (const string_t& full_layer_id : full_layer_ids)
                                                {
                                                        const string_t desc = make_model_description(
                                                                n_layers,
                                                                actv_layer_id,
                                                                pool_layer_id,
                                                                conv_layer_id,
                                                                full_layer_id);

                                                        descs.insert(desc);
                                                }
                                        }
                                }
                        }
                }

                const strings_t loss_ids = ncv::get_losses().ids();

                // create the <model description, loss id> configuration
                std::vector<std::pair<ncv::string_t, ncv::string_t> > result;
                for (const string_t& desc : descs)
                {
                        // pick a random loss (enough, because all the loss functions are tested separately)
                        random_t<size_t> rng(0, loss_ids.size());

                        const string_t loss_id = loss_ids[rng() % loss_ids.size()];
                        result.emplace_back(desc, loss_id);
                }

                // OK
                irows = cmd_irows;
                icols = cmd_icols;
                outputs = cmd_outputs;
                color = cmd_color;
                return result;
        }
Exemplo n.º 4
0
int 
readDataSentence(istream &f, strings_t &s, int &expected)
{
  strings_t line;
  s.clear();
  while (f.good())
    if (readDataLine(f, s, expected))
      break;
  while (f.good())
    if (! readDataLine(f, s, expected))
      break;
  if (expected)
    return s.size() / expected;
  return 0;
}
Exemplo n.º 5
0
void
readTemplateFile(const char *fname, strings_t &templateVector)
{
  ifstream f(fname);
  if (! f.good())
    {
      cerr << "ERROR: Cannot open " << fname << " for reading." << endl;
      exit(10);
    }
  while(f.good())
    {
      int c = skipSpace(f);
      while (c == '#')
        {
          while (f.good() && c!='\n' && c!='\r')
            c = f.get();
          f.unget();
          c = skipSpace(f);
        }
      string s;
      getline(f,s);
      if (! s.empty())
        {
          checkTemplate(s);
          templateVector.push_back(s);        
        }
    }
  if (! f.eof())
    {
      cerr << "ERROR: Cannot read " << fname << " for reading." << endl;
      exit(10);
    }
}
Exemplo n.º 6
0
int
readDataLine(istream &f, strings_t &line, int &expected)
{
  int obtained = 0;
  while (f.good())
    {
      int c = skipBlank(f);
      if (c == '\n' || c == '\r')
        break;
      string s;
      f >> s;
      if (! s.empty())
        {
          line.push_back(s);
          obtained += 1;
        }
    }
  int c = f.get();
  if (c == '\r' && f.get() != '\n')
    f.unget();
  if (obtained > 0)
    {
      if (expected <= 0)
        expected = obtained;
      else if (expected > 0 && expected != obtained)
        {
          cerr << "ERROR: expecting " << expected 
               << " columns in data file." << endl;
          exit(10);
        }
    }
  else
    skipSpace(f);
  return obtained;
}
Exemplo n.º 7
0
void Option::set(const strings_t &values) {
  string value;

  for (unsigned i = 1; i < values.size(); i++) {
    if (i != 1) value += " ";
    value += values[i];
  }

  set(value);
}
Exemplo n.º 8
0
techtree_t::techtree_t(fs_t& fs,const std::string& name):
	mgr_t(fs), xml_loadable_t(name),
	path(fs.canocial(std::string("techs")+"/"+name)) {
	{
		const strings_t subdirs = fs.list_dirs(path+"/factions");
		for(strings_t::const_iterator i=subdirs.begin(); i!=subdirs.end(); i++)
			if(fs.exists(path+"/factions/"+*i+"/"+*i+".xml")) {
				factions.push_back(*i);
				faction_refs.push_back(ref_t(*this,FACTION,*i));
			}
		if(!factions.size())
			data_error("techtree "<<name<<" contains no factions");
	}{
		const strings_t subdirs = fs.list_dirs(path+"/resources");
		for(strings_t::const_iterator i=subdirs.begin(); i!=subdirs.end(); i++)
			if(fs.exists(path+"/resources/"+*i+"/"+*i+".xml")) {
				resources.push_back(*i);
				resource_refs.push_back(ref_t(*this,RESOURCE,*i));
			}
		if(!resources.size())
			data_error("techtree "<<name<<" contains no resources");
	}
	fs_file_t::ptr_t f(fs.get(path+"/"+name+".xml"));
	istream_t::ptr_t in(f->reader());
	load_xml(*in);
}
Exemplo n.º 9
0
ClobFile::ClobFile(std::string _path, Instructions _instructions, strings_t _data) {
    path = _path;
    instructions = _instructions;

    header = {0, _instructions.size(), _data.size()};

    for (auto _d : _data) {
        DataEntry_t entry;
        entry.string = _d;
        entry.length = entry.string.size();
        data.push_back(entry);
    }
}
Exemplo n.º 10
0
void tuner_t::map(const indices_t& indices, strings_t& values) const
{
        assert(indices.size() == m_params.size());
        assert(values.size() == m_params.size());

        for (size_t i = 0; i < m_params.size(); ++ i)
        {
                const auto& param = m_params[i];

                assert(indices[i] < param.m_values.size());
                values[i] = param.m_values[indices[i]];
        }
}
Exemplo n.º 11
0
json_t tuner_t::json(const strings_t& values) const
{
        assert(values.size() == m_params.size());

        json_t json;
        for (size_t i = 0; i < m_params.size(); ++ i)
        {
                const auto& param = m_params[i];
                const auto& value = values[i];

                json[param.m_name] = value;
        }

        return json;
}
Exemplo n.º 12
0
string
expandTemplate(string tpl, const strings_t &s, int columns, int pos)
{
  string e;
  int rows = s.size() / columns;
  const char *t = tpl.c_str();
  const char *p = t;
  
  static const char *BOS[4] = { "_B-1", "_B-2", "_B-3", "_B-4"};
  static const char *EOS[4] = { "_B+1", "_B+2", "_B+3", "_B+4"};

  while (*p)
    {
      if (p[0]=='%' && p[1]=='x' && p[2]=='[')
        {
          if (p > t)
            e.append(t, p-t);
          // parse %x[A,B] assuming syntax has been verified
          char *n;
          int a = strtol(p+3, &n, 10);
          while (n[0] && n[0]!=',')
            n += 1;
          int b = strtol(n+1, &n, 10);
          while (n[0] && n[0]!=']')
            n += 1;
          p = n;
          t = n+1;
          // catenate
          a += pos;
          if (b>=0 && b<columns)
            {
              if (a>=0 && a<rows)
                e.append(s[a*columns+b]);
              else if (a<0)
                e.append(BOS[min(3,-a-1)]);
              else if (a>=rows)
                e.append(EOS[min(3,a-rows)]);
            }
        }
      p += 1;
    }
  if (p > t)
    e.append(t, p-t);
  return e;
}
Exemplo n.º 13
0
static size_t _index_of(const strings_t& c,const std::string& s,const char* ctx) {
	const size_t i = std::distance(c.begin(),std::find(c.begin(),c.end(),s));
	if(i == c.size()) data_error("could not find "<<ctx<<" "<<s);
	return i;
}
Exemplo n.º 14
0
techtrees_t::techtrees_t(fs_t& fs): fs_handle_t(fs) {
	const strings_t subdirs = fs.list_dirs("techs");
	for(strings_t::const_iterator i=subdirs.begin(); i!=subdirs.end(); i++)
		if(fs.exists(std::string("techs")+"/"+*i+"/"+*i+".xml"))
			techtrees.push_back(*i);
}
Exemplo n.º 15
0
int main(int argc,const char* argv[])
{
    int result=0;
    const char* program = argv[0];

    const char* types[typeMax];
    types[typeUnknown  ] = "unknown";
    types[typeDirectory] = "directory";
    types[typeImage    ] = "image";
    types[typeXML      ] = "xml";
    types[typeDoc      ] = "doc";
    types[typeCode     ] = "code";
    types[typeFile     ] = "file";

    char const* keywords[kwMAX];
    memset(keywords,0,sizeof(keywords));
    keywords[kwHELP    ] = "help";
    keywords[kwVERSION ] = "version";
    keywords[kwVERBOSE ] = "verbose";
    keywords[kwDRYRUN  ] = "dryrun";
    keywords[kwDST     ] = "dst";
    keywords[kwADJUST  ] = "adjust";
    keywords[kwTZ      ] = "tz";
    keywords[kwDELTA   ] = "delta";

    map<std::string,string> shorts;
    shorts["-?"] = "-help";
    shorts["-h"] = "-help";
    shorts["-v"] = "-verbose";
    shorts["-V"] = "-version";
    shorts["-d"] = "-dst";
    shorts["-a"] = "-adjust";
    shorts["-t"] = "-tz";
    shorts["-D"] = "-delta";
    shorts["-s"] = "-delta";
    shorts["-X"] = "-dryrun";

    Options options ;
    options.help    = sina(keywords[kwHELP   ],argv) || argc < 2;
    options.verbose = sina(keywords[kwVERBOSE],argv);
    options.dryrun  = sina(keywords[kwDRYRUN ],argv);
    options.version = sina(keywords[kwVERSION],argv);
    options.dst     = sina(keywords[kwDST    ],argv);
    options.dryrun  = sina(keywords[kwDRYRUN ],argv);

    for ( int i = 1 ; !result && i < argc ; i++ ) {
        const char* arg   = argv[i++];
        if ( shorts.count(arg) ) arg = shorts[arg].c_str();

        const char* value = argv[i  ];
        int        ivalue = ::atoi(value?value:"0");
        int         key   = ::find(arg,keywords,kwMAX);
        int         needv = key < kwMAX && key > (-kwNOVALUE);

        if (!needv ) i--;
        if ( needv && !value) key = kwNEEDVALUE;

        switch ( key ) {
            case kwDST      : options.dst     = true ; break;
            case kwHELP     : options.help    = true ; break;
            case kwVERSION  : options.version = true ; break;
            case kwDRYRUN   : options.dryrun  = true ; break;
            case kwVERBOSE  : options.verbose = true ; break;
            case kwTZ       : Position::tz_      = parseTZ(value);break;
            case kwADJUST   : Position::adjust_  = ivalue;break;
            case kwDELTA    : Position::deltaMax_= ivalue;break;
            case kwNEEDVALUE: fprintf(stderr,"error: %s requires a value\n",arg); result = resultSyntaxError ; break ;
            case kwSYNTAX   : default:
            {
                int  type   = getFileType(arg,options) ;
                if ( options.verbose ) printf("%s %s ",arg,types[type]) ;
                if ( type == typeImage ) {
                    time_t t    = readImageTime(std::string(arg)) ;
                    char*  path = realpath(arg,NULL);
                    if  ( t && path ) {
                        if ( options.verbose) printf("%s %ld %s",path,(long int)t,asctime(localtime(&t)));
                        gFiles.push_back(path);
                    }
                    if ( path ) :: free((void*) path);
                }
                if ( type == typeUnknown ) {
                    fprintf(stderr,"error: illegal syntax %s\n",arg);
                    result = resultSyntaxError ;
                }
                if ( options.verbose ) printf("\n") ;
            }break;
        }
    }

    if ( options.help    ) ::help(program,keywords,kwMAX,options.verbose);
    if ( options.version ) ::version(program);

    if ( !result ) {
        sort(gFiles.begin(),gFiles.end(),mySort);
        if ( options.dst ) Position::dst_ = 3600;
        if ( options.verbose ) {
            int t = Position::tz();
            int d = Position::dst();
            int a = Position::adjust();
            int A = Position::Adjust();
            int s = A     ;
            int h = s/3600;
                s-= h*3600;
                s = abs(s);
            int m = s/60  ;
                s-= m*60  ;
            printf("tz,dsl,adjust = %d,%d,%d total = %dsecs (= %d:%d:%d)\n",t,d,a,A,h,m,s);
        }
        for ( size_t p = 0 ; !options.dryrun && p < gFiles.size() ; p++ ) {
            std::string arg = gFiles[p] ;
            std::string stamp ;
            try {
                time_t t       = readImageTime(arg,&stamp) ;
                Position* pPos = searchTimeDict(gTimeDict,t,Position::deltaMax_);
                Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(gFiles[p]);
                if ( image.get() ) {
                    image->readMetadata();
                    Exiv2::ExifData& exifData = image->exifData();
#if 0
                    /*
					char* keys[]={ "Exif.Image.GPSTag"
						         , "Exif.GPSInfo.GPSProcessingMethod"
					             , "Exif.GPSInfo.GPSAltitudeRef"
							     , "Exif.GPSInfo.GPSVersionID"
                                 , "Exif.GPSInfo.GPSProcessingMethod"
                                 , "Exif.GPSInfo.GPSVersionID"
                                 , "Exif.GPSInfo.GPSMapDatum"
                                 , "Exif.GPSInfo.GPSLatitude"
                                 , "Exif.GPSInfo.GPSLongitude"
                                 , "Exif.GPSInfo.GPSAltitude"
                                 , "Exif.GPSInfo.GPSAltitudeRef"
                                 , "Exif.GPSInfo.GPSLatitudeRef"
                                 , "Exif.GPSInfo.GPSLongitudeRef"
                                 , "Exif.GPSInfo.GPSDateStamp"
                                 , "Exif.GPSInfo.GPSTimeStamp"
					};
					static int bPrint = true ;
					for ( int k = 0 ; k < 15 ;   k++ ) {
						try {
							if ( bPrint ) printf("erasing %s\n",keys[k]);
							Exiv2::ExifKey  key = Exiv2::ExifKey(keys[k]);
							Exiv2::ExifData::iterator kk = exifData.findKey(key);
							if ( kk != exifData.end() ) exifData.erase(kk);
						} catch (...) {};
					}
					bPrint = false;
                    */
#endif
#if 0
					Exiv2::ExifData::const_iterator end = exifData.end();
					for (Exiv2::ExifData::iterator i = exifData.begin(); i != end; ++i) {
						char name[100];
						strcpy(name,i->key().c_str());
						// std::cout << "sniff " << i->key() << std::endl;
						if ( strstr(name,"GPS") )  {
							Exiv2::ExifData::iterator pos;
							Exiv2::ExifKey exifKey = Exiv2::ExifKey(name);
							pos = exifData.findKey(exifKey);
							while( pos != exifData.end()) {
								exifData.erase(pos);
							}
						}
					}
#endif
					if ( pPos ) {
						/*
						   struct _stat buf;
   int result;
   char timebuf[26];
   char* filename = "crt_stat.c";
   errno_t err;

   // Get data associated with "crt_stat.c":
   result = _stat( filename, &buf );

   int _utime(
   const char *filename,
   struct _utimbuf *times
);
   */

                        exifData["Exif.GPSInfo.GPSProcessingMethod" ] = "65 83 67 73 73 0 0 0 72 89 66 82 73 68 45 70 73 88"; // ASCII HYBRID-FIX
                        exifData["Exif.GPSInfo.GPSVersionID"        ] = "2 2 0 0";
                        exifData["Exif.GPSInfo.GPSMapDatum"         ] = "WGS-84";

                        exifData["Exif.GPSInfo.GPSLatitude"         ] = Position::toExifString(pPos->lat(),true,true);
                        exifData["Exif.GPSInfo.GPSLongitude"        ] = Position::toExifString(pPos->lon(),true,false);
                        exifData["Exif.GPSInfo.GPSAltitude"         ] = Position::toExifString(pPos->ele());

                        exifData["Exif.GPSInfo.GPSAltitudeRef"      ] = pPos->ele()<0.0?"1":"0";
						exifData["Exif.GPSInfo.GPSLatitudeRef"      ] = pPos->lat()>0?"N":"S";
						exifData["Exif.GPSInfo.GPSLongitudeRef"     ] = pPos->lon()>0?"E":"W";

                        exifData["Exif.GPSInfo.GPSDateStamp"        ] = stamp;
                        exifData["Exif.GPSInfo.GPSTimeStamp"        ] = Position::toExifTimeStamp(stamp);
						exifData["Exif.Image.GPSTag"                ] = 4908;

						printf("%s %s % 2d\n",arg.c_str(),pPos->toString().c_str(),pPos->delta());
                    } else {
                        printf("%s *** not in time dict ***\n",arg.c_str());
                    }
                    image->writeMetadata();
				}
            } catch ( ... ) {};
        }
    }

    return result ;
}
Exemplo n.º 16
0
// file utilities
bool readDir(const char* path,Options& options)
{
    bool bResult = false;

#ifdef _MSC_VER
    DWORD attrs    =  GetFileAttributes(path);
    bool  bOKAttrs =  attrs != INVALID_FILE_ATTRIBUTES;
    bool  bIsDir   = (attrs  & FILE_ATTRIBUTE_DIRECTORY) ? true : false ;

    if( bOKAttrs && bIsDir ) {
        bResult = true ;

        char     search[_MAX_PATH+10];
        strcpy_s(search,_MAX_PATH,path);
        strcat_s(search,_MAX_PATH,"\\*");

        WIN32_FIND_DATA ffd;
        HANDLE  hFind = FindFirstFile(search, &ffd);
        BOOL    bGo = hFind != INVALID_HANDLE_VALUE;

        if ( bGo ) {
            while ( bGo ) {
                if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                    // _tprintf(TEXT("  %s   <DIR>\n"), ffd.cFileName);
                }
                else
                {
                    std::string pathName = makePath(path,std::string(ffd.cFileName));
                    if ( getFileType(pathName,options) == typeImage ) {
                        gFiles.push_back( pathName );
                    }
                }
                bGo = FindNextFile(hFind, &ffd) != 0;
            }
            // CloseHandle(hFind);
        }
    }
#else
    DIR*    dir = opendir (path);
    if (dir != NULL)
    {
        bResult = true;
        struct dirent*  ent;

        // print all the files and directories within directory
        while ((ent = readdir (dir)) != NULL)
        {
            std::string pathName = makePath(path,ent->d_name);
            struct stat  buf     ;
            lstat(path, &buf );
            if ( ent->d_name[0] != '.' ) {

                // printf("reading %s => %s\n",ent->d_name,pathName.c_str());
                if ( getFileType(pathName,options) == typeImage ) {
                    gFiles.push_back( pathName );
                }
            }
        }
        closedir (dir);
    }
#endif
    return bResult ;
}
Exemplo n.º 17
0
string_t
shift( strings_t & strs ) {
    string_t first = strs.front();
    strs.erase( strs.begin() );
    return first;
} // shift