/**
 * Tests the concurrent access settings of the class.
 *
 * DataHandle of previously added data obtained with getData() should remains valid
 * even if the data in the container is replaced with new data.
 */
TEST_F(DataContainerTest, concurrentAccessTest) {
    this->_dc0->addData("data1", this->_data);
    DataHandle dh = this->_dc0->getData("data1");
    AbstractData *someData = new ImageData(2, cgt::svec3(1,2,1), 4);
    this->_dc0->addData("data1", someData);

    EXPECT_EQ(someData, this->_dc0->getData("data1").getData());
    EXPECT_NE(_data, this->_dc0->getData("data1").getData());
    EXPECT_EQ(_data, dh.getData());
}
	void* charDataHandle(const char* s) 
	{
		DataHandle* h = new DataHandle;
		size_t len = strlen(s);
		char* d = (char*)malloc(len + 1);
		//strcpy_s(d, len + 1, s);
		strcpy(d, s);
		h->set((void*)d, 0, GRAB);
		return (void*)h;
	}
Ejemplo n.º 3
0
static void*
parameterNotFound(const char* name, const char* file, int line)
{
	DataHandle* handle = new DataHandle;
	std::string error = "parameter ";
	error += name;
	error += " not found";
	ExecutionStatus status(error.c_str(), file, line);
	handle->set(0, &status);
	return (void*)handle;
}
Ejemplo n.º 4
0
static void*
unknownObject(const char* obj, const char* name, const char* file, int line)
{
	DataHandle* handle = new DataHandle;
	std::string error = "unknown ";
	error += obj;
	error += " '";
	error += name;
	error += "'";
	ExecutionStatus status(error.c_str(), file, line);
	handle->set(0, &status);
	return (void*)handle;
}
	void* copyOfObjectHandle(void* ptr)
	{
		try {
			CAST_PTR(anObjectHandle, ptr_obj, ptr);
			return (void*)ptr_obj->copy();
		}
		catch (LocalisedException& le) {
			ExecutionStatus status(le.what(), le.file(), le.line());
			DataHandle* handle = new DataHandle;
			handle->set(0, &status);
			return (void*)handle;
		}
	}
Ejemplo n.º 6
0
void*
cGT_norm(const void* ptr_x)
{
	try {
		CAST_PTR(DataHandle, h_x, ptr_x);
		aDataContainer& x = objectFromHandle<aDataContainer>(h_x);
		double* result = (double*)malloc(sizeof(double));
		*result = x.norm();
		DataHandle* handle = new DataHandle;
		handle->set(result, 0, GRAB);
		return (void*)handle;
	}
	CATCH;
}
Ejemplo n.º 7
0
void*
cGT_dataItems(const void* ptr_x)
{
	try {
		CAST_PTR(DataHandle, h_x, ptr_x);
		aDataContainer& x = objectFromHandle<aDataContainer>(h_x);
		int* result = (int*)malloc(sizeof(int));
		*result = x.items();
		DataHandle* handle = new DataHandle;
		handle->set(result, 0, GRAB);
		return (void*)handle;
	}
	CATCH;
}
Ejemplo n.º 8
0
 static iterator
 startIteration (DataHandle sourceHandle)
   {
     REQUIRE (sourceHandle);
     Pos first = sourceHandle->firstResult();
     return iterator (sourceHandle, first);
   }
Ejemplo n.º 9
0
void*
cGT_dot(const void* ptr_x, const void* ptr_y)
{
	try {
		CAST_PTR(DataHandle, h_x, ptr_x);
		CAST_PTR(DataHandle, h_y, ptr_y);
		aDataContainer& x = objectFromHandle<aDataContainer>(h_x);
		aDataContainer& y = objectFromHandle<aDataContainer>(h_y);
		complex_double_t* result =
			(complex_double_t*)malloc(sizeof(complex_double_t));
		*result = x.dot(y);
		DataHandle* handle = new DataHandle;
		handle->set(result, 0, GRAB);
		return (void*)handle;
	}
	CATCH;
}
Ejemplo n.º 10
0
unsigned char *kGUI::LoadFile(const char *filename,unsigned long *filesize)
{
    unsigned char *fm;
    unsigned long fs;
    DataHandle dh;

    if(filesize)
        filesize[0]=0;
    dh.SetFilename(filename);
    if(dh.Open()==false)
    {
        printf("Error: cannot open file '%s'\n",filename);
        return(0);	/* file not found or empty file */
    }

    fs=dh.GetLoadableSize();
    /* allocate space for file to load info */
    fm=new unsigned char[fs+1];
    if(!fm)
    {
        dh.Close();
        return(0);
    }
    fm[fs]=0;	/* allocate an extra byte and put a null at the end */
    dh.Read(fm,fs);
    dh.Close();
    if(filesize)
    {
        //todo: if filesize>32 bits, then assert, else return ok
        filesize[0]=fs;
    }
    return(fm);
}
Ejemplo n.º 11
0
bool kGUIProt::LoadSeed(kGUIRandom *r,unsigned int offset)
{
	unsigned int i;
	unsigned char keychar;
	long long keyfilesize;
	long long keystartindex=m_keystart+offset;
	DataHandle dh;

	r->InitSeed();

	if(!m_keyfile)
	{
		if(!m_keyfilename.GetLen())
			return(false);				/* no filename set */

		dh.SetFilename(m_keyfilename.GetString());
		if(dh.Open()==false)
			return(false);

		keyfilesize=dh.GetSize();
	}
	else
		keyfilesize=m_keyfilesize;

	/* if start index>filesize then bring it back inside */
	while(keystartindex>=keyfilesize)
		keystartindex-=keyfilesize;

	if(!m_keyfile)
		dh.Seek(keystartindex);

	for(i=0;i<m_keylen;++i)
	{
		/* read in bytes and set random key */
		if(!m_keyfile)
		{
			/* read 1 byte from the keyfile */
			dh.Read(&keychar,(unsigned long)1);
		}
		else
			keychar=m_keyfile[keystartindex];

		r->AddEntropy(keychar);
		if(++keystartindex==keyfilesize)
		{
			keystartindex=0;
			if(!m_keyfile)
				dh.Seek((unsigned long long)0);
		}
	}
	if(!m_keyfile)
		dh.Close();
	return(true);
}
    void TransferFunctionProperty::setImageHandle(DataHandle imageHandle) {
        cgtAssert(
            imageHandle.getData() == 0 || dynamic_cast<const ImageData*>(imageHandle.getData()) != 0, 
            "The data in the image handle must either be 0 or point to a valid ImageData object!");

        if (_autoFitWindowToData && imageHandle.getData() != 0) {
            if (const ImageData* id = dynamic_cast<const ImageData*>(imageHandle.getData())) {
            	const ImageRepresentationLocal* localRep = id->getRepresentation<ImageRepresentationLocal>();
                if (localRep != 0) {
                    const Interval<float>& ii = localRep->getNormalizedIntensityRange();
                    _transferFunction->setIntensityDomain(cgt::vec2(ii.getLeft(), ii.getRight()));
                }
            }
        }

        _imageHandle = imageHandle;
        _dirtyHistogram = true;
        s_imageHandleChanged.emitSignal();
    }
Ejemplo n.º 13
0
/*---------------------------------------------------------------------------------*/
void engine::setConfig(Config *cfg_,bool sg){
  cfg = cfg_;
  num_threads = cfg->getNumThreads();
  local_nb = cfg->getXLocalBlocks();
  int mb =  cfg->getYBlocks();
  int nb =  cfg->getXBlocks();
  int ny = cfg->getYDimension() / mb;
  int nx = cfg->getXDimension() / nb;
  int P = cfg->getProcessors();
  DataHandle dh;
  DataVersion dv;
  IDuctteipTask t;
  IListener l;

  long dps = ny * nx * sizeof(double) + dh.getPackSize() + 4*dv.getPackSize();
  dt_log.setParams(cfg->getProcessors(),dps,l.getPackSize(),t.getPackSize());
  LOG_INFO(1,"");
  if ( simulation ) {
    dps = sizeof(double) + dh.getPackSize() + 4*dv.getPackSize();
  }
  LOG_INFO(LOG_MULTI_THREAD,"DataPackSize:%ld=%d*%d*8+%d+%d\n",dps,ny,nx,dh.getPackSize(),4*dv.getPackSize());
  if ( memory_policy == ALL_USER_ALLOCATED)
    data_memory = new MemoryManager (  nb * mb ,1 );
  else
    data_memory = new MemoryManager (  nb * mb / P  ,dps );
  LOG_INFO(LOG_MULTI_THREAD,"data meory:%p\n",data_memory);
  //int ipn = cfg->getIPN();
  if ( !sg){
    thread_manager = new ThreadManager<Options> ( num_threads );//,0* (me % ipn )  * 16/ipn) ;
    LOG_INFO(LOG_MULTI_THREAD,"nt=%d.\n",num_threads);
  }
  else{
    printf("No SuperGlue created , pure-mpi=%d.\n",config.pure_mpi);
  }
  
  //show_affinity();
  dlb.initDLB();
  dlb_mode = cfg->getDLB();
}
Ejemplo n.º 14
0
 friend void
 iterNext (DataHandle& source, Pos& pos)
   {
     ASSERT (source);
     source->nextResult(pos);
   }
Ejemplo n.º 15
0
OZF2GPXMap::OZF2GPXMap(const char *fn)
{
	kGUIString ozfn;
	DataHandle dh;
	int linenum;
	kGUIString line;
	kGUIStringSplit ss;
	int index;
	int z;
	int nf;
	unsigned char *fp;
	unsigned long filesize;
	OZ2FHEADER_DEF *oh;
	double maxlat,maxlon;
	double maxx,maxy;

	m_coords=0;

	dh.SetFilename(fn);
	if(dh.Open()==false)
		return;	/* couldn't load file */

	linenum=0;
	do
	{
		dh.ReadLine(&line);
		nf=ss.Split(&line,",");

		if(linenum==2)
		{
			int sl;
			static char dirchar[]={ DIRCHAR };

			ozfn.SetString(fn);	/* extract path from filename */
			sl=ozfn.GetLen()-1;
			/* cut off last subdir */
			while(sl>0)
			{
				if(ozfn.GetChar(sl)==dirchar[0])
				{
					++sl;
					break;
				}
				--sl;
			};
			ozfn.Clip(sl);
			ozfn.Append(line.GetString());
		}
		else if(linenum==4)
		{
			/* datum */
			if(!strcmp(ss.GetWord(0)->GetString(),"WGS 84"))
			{
				/* ok */
			}
			else
			{
				dh.Close();
				return;
			}
			//if (! FindOziDatumToWGS84 (strDatum.c_str (), m_pDatumTransformation)) {
			//	m_pDatumTransformation = NULL;
			//	ReportWarning ("Some unsupported datum is used: '%s'. No datum conversion performed.", strDatum.c_str ());
		}
		else
		{
			if(!strcmp(ss.GetWord(0)->GetString(),"Map Projection"))
			{
				/* todo */
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPNUM"))
			{
				m_coords=new OZF2Corners[ss.GetWord(1)->GetInt()];
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPXY"))
			{
				/* pixel position */
				index=atoi(ss.GetWord(1)->GetString())-1;
				m_coords[index].x=atoi(ss.GetWord(2)->GetString());
				m_coords[index].y=atoi(ss.GetWord(3)->GetString());
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPLL"))
			{
				/* latitude/longitude position */
				index=atoi(ss.GetWord(1)->GetString())-1;
				m_coords[index].lon=atof(ss.GetWord(2)->GetString());
				m_coords[index].lat=atof(ss.GetWord(3)->GetString());
			}
		}
		++linenum;
	}while(dh.Eof()==false);
	dh.Close();

	/* calculate bounding rectanle for lat/lon */
	m_minlat=m_coords[0].lat;
	maxlat=m_coords[0].lat;
	m_minlon=m_coords[0].lon;
	maxlon=m_coords[0].lon;
	m_minx=m_coords[0].x;
	maxx=m_coords[0].x;
	m_miny=m_coords[0].y;
	maxy=m_coords[0].y;
	for(index=1;index<4;++index)
	{
		if(m_coords[index].lat<m_minlat)
		{
			m_minlat=m_coords[index].lat;
			m_miny=m_coords[index].y;
		}
		if(m_coords[index].lat>maxlat)
		{
			maxlat=m_coords[index].lat;
			maxy=m_coords[index].y;
		}

		if(m_coords[index].lon<m_minlon)
		{
			m_minlon=m_coords[index].lon;
			m_minx=m_coords[index].x;
		}
		if(m_coords[index].lon>maxlon)
		{
			maxlon=m_coords[index].lon;
			maxx=m_coords[index].x;
		}
	}

	/* assume linear for now until I figure out the projection */
	m_slx=(maxlon-m_minlon)/(maxx-m_minx);
	m_sly=(maxlat-m_minlat)/(maxy-m_miny);
	m_lsx=(maxx-m_minx)/(maxlon-m_minlon);
	m_lsy=(maxy-m_miny)/(maxlat-m_minlat);

	for(index=0;index<4;++index)
	{
		GPXCoord c;
		int sx,sy;

		c.Set(m_coords[index].lat,m_coords[index].lon);
		ToMap(&c,&sx,&sy);
		DebugPrint("Coord testing %f,%f %d,%d - %d,%d",m_coords[index].lat,m_coords[index].lon,m_coords[index].x,m_coords[index].y,sx,sy);
	}

	/* load the map file with the tiles */
	fp=kGUI::LoadFile(ozfn.GetString(),&filesize);
	if(!fp)
		return;	/* couldn't load file */

	m_filedata=fp;	/* save pointer to data so destructor will free it up upon exiting */
	oh=(OZ2FHEADER_DEF *)fp;
	
	if(oh->wSignature!=0x7778)
		return;	/* not valid format */

	assert ((oh->wPlanes==1) && (oh->wBitsPerPixel==8),"Unsupported bitmap format" );

	SetTileSize(64,64);

	/* parse the tile data */

	const int dwMasterTblOffset = * reinterpret_cast<const int *> (fp + filesize - 4);
	const int * const pdwMasterTbl = reinterpret_cast<const int *> (fp + dwMasterTblOffset);

	const int zoomlevels = (filesize - 4 - dwMasterTblOffset)/4;
	SetZoomLevels(1,zoomlevels);
	m_bitmaps.Alloc(zoomlevels);
	z=zoomlevels-1;
	for (int zoomlevel = 0; zoomlevel < zoomlevels; ++ zoomlevel)
	{
		OZ2FBITMAP_DEF *ih = (OZ2FBITMAP_DEF *) (fp + pdwMasterTbl [zoomlevel]);

		m_bitmaps.SetEntry(z,ih);
		SetSize(z,ih->dwImageWidth,ih->dwImageHeight);
		--z;
	}
}
Ejemplo n.º 16
0
int main(int argc, char* argv[])
{
    int i;
    int nums;
    FDATA fdata;
    Hash AddHash;
    BigFile DestBigFile;
    BigFile SourceBigFile;
    BigFileEntry *bfe;
    int numok,numnew,numupdated;
    int sourcetype;
    bool update;
    char *p1=0;
    char *p2=0;
    char *p3=0;
    int tosspath=0;
    DataHandle addhandle;
    int vargc;
    char **vargv;
    vargc=argc;
    vargv=argv;

    /* handle encrypted file */
    kGUIProt DestProt;
    bool usedestprot;
    kGUIProt SourceProt;
    bool usesourceprot;
    kGUISystemBig sysbig;

    kGUI::SetSystem(&sysbig);
    signal(SIGINT, sigint_handler);
    optcompress=false;
    optrecursive=true;
    optverify=false;
    optdelete=false;
    optmissing=false;
    usedestprot=false;
    usesourceprot=false;

#if 0
    p1="/source/kgui/_data.big";
    p2="/source/kgui/big";
    p3="/source/kgui/big/";
    optverify=true;
#endif

    for(i=1; i<vargc; ++i)
    {
        if(vargv[i][0]=='-')
        {
            switch(vargv[i][1])
            {
            case 'c':
                optcompress=true;
                break;
            case 'd':
                optdelete=true;
                break;
            case 'm':
                optmissing=true;	/* delete missing files from subdir */
                break;
            case 'v':
                optverify=true;
                break;
            case 'r':
                optrecursive=false;
                break;
            case 'k':
                if(vargv[i][2]=='d')	/* encryption key on destination file */
                {
                    printf("using dest key\n");
                    if(DestProt.SetKey(vargv[i+1],atoi(vargv[i+2]),atoi(vargv[i+3]),true)==false)
                    {
                        printf("Error loading dest keyfile '%s'\n",vargv[i+1]);
                        return(0);
                    }
                    usedestprot=true;
                    i+=3;
                }
                else if(vargv[i][2]=='s') /* encryption key on source file */
                {
                    printf("using source key\n");
                    if(SourceProt.SetKey(vargv[i+1],atoi(vargv[i+2]),atoi(vargv[i+3]),true)==false)
                    {
                        printf("Error loading source keyfile '%s'\n",vargv[i+1]);
                        return(0);
                    }
                    usesourceprot=true;
                    i+=3;
                }
                optrecursive=false;
                break;
            default:
                printf("Unknown parm '%s'\n",vargv[i]);
                return(0);
                break;
            }
        }
        else
        {
            if(!p1)
                p1=vargv[i];
            else if(!p2)
                p2=vargv[i];
            else if(!p3)
            {
                p3=vargv[i];
                tosspath=(int)strlen(p3);
            }
            else
            {
                printf("Unknown parm '%s'\n",vargv[i]);
                return(0);
            }
        }
    }

    /* need at least 1 parm */
    if(!p1)
    {
        printf("kguibig: (c) 2005 Kevin Pickelll\n");
        printf("usage: kguibig bigfile.big path [root]\n");
        printf(" -c = compress\n");
        printf(" -v = verify\n");
        printf(" -r = don't recurse\n");
        printf(" -k[d,s] = filename offset len // source/dest key\n");
        return(0);
    }

    DestBigFile.SetFilename(p1);
    if(usedestprot==true)
        DestBigFile.SetEncryption(&DestProt);
    DestBigFile.Load(true);
    if(DestBigFile.IsBad()==true)
    {
        printf("Dest file exists and is not a bigfile, or decryption key is incorrect!\n");
        return(0);
    }

    /* list, verify or compress ? */
    if(!p2)
    {
        if(optcompress)
        {
        }
        else
        {
            unsigned long crc;
            unsigned long vfsize;
            BigFileEntry *sfe;
            unsigned char copybuf[65536];
            DataHandle checkhandle;

            /* verify or list */
            nums=DestBigFile.GetNumEntries();
            for(i=0; ((i<nums) && (g_userabort==false)); ++i)
            {
                sfe=(BigFileEntry *)DestBigFile.GetEntry(i);

                if(optverify)
                {
                    /* check crc and print if no match */
                    printf("%d%c",i,13);
                    vfsize=sfe->m_size;

                    crc=0;
                    DestBigFile.CopyArea(&checkhandle,sfe->m_offset,sfe->m_size,sfe->m_time);
                    checkhandle.Open();
                    while(vfsize>sizeof(copybuf))
                    {
                        checkhandle.Read(&copybuf,(unsigned long)sizeof(copybuf));
                        crc=DestBigFile.CrcBuffer(crc,copybuf,sizeof(copybuf));
                        vfsize-=sizeof(copybuf);
                    };
                    /* write remainder */
                    if(vfsize>0)
                    {
                        checkhandle.Read(&copybuf,vfsize);
                        crc=DestBigFile.CrcBuffer(crc,copybuf,vfsize);
                    }
                    checkhandle.Close();
                    if(crc!=sfe->m_crc)
                        printf("CRC Error on file '%s' %06x<>%06x\n",sfe->GetName()->GetString(),(int)crc,sfe->m_crc);
                }
                else	/* assume list if verify is not set */
                    printf("%s, len=%d,crc=%06x\n",sfe->GetName()->GetString(),sfe->m_size,sfe->m_crc);
            }
        }
        return(0);
    }

    AddHash.Init(16,sizeof(FDATA));

    /* is p2 a bigfile? */
    if(strstr(p2,".big"))
    {

        SourceBigFile.SetFilename(p2);
        if(usesourceprot==true)
            SourceBigFile.SetEncryption(&SourceProt);
        SourceBigFile.Load(true);
        if(SourceBigFile.IsBad()==false)
            sourcetype=SOURCE_BIG;
        else
        {
            printf("Source file exists and is not a bigfile, or decryption key is incorrect!\n");
            return(0);
        }
    }
    else if(kGUI::IsDir(p2)==false)
    {
        fdata.time=kGUI::SysFileTime(p2);
        //fdata.root=p3;
        AddHash.Add(p2,&fdata);
        sourcetype=SOURCE_FILE;
    }
    else
    {
        unsigned int df;

        const char *name;
        kGUIDir dir;

        printf("loading directory!\n");
        dir.LoadDir(p2,true,true);
        for(df=0; df<dir.GetNumFiles(); ++df)
        {
            name=dir.GetFilename(df);
            fdata.time=kGUI::SysFileTime(name);
            AddHash.Add(name,&fdata);
        }
//		scandir(&AddHash,p2);
        sourcetype=SOURCE_DIR;
    }
    /* now, look for differences between bigfile and files in the addhash list */

    numok=0;
    numnew=0;
    numupdated=0;

    /* todo: optdelete function */

    /* add from source bigfile to dest bigfile will not work */
    /* if source is encrypted so I need to rewrite addfile to use a datahandle */
    /* instead of a filestream */

    if(sourcetype==SOURCE_BIG)
    {
        BigFileEntry *sfe;

        nums=SourceBigFile.GetNumEntries();
        for(i=0; ((i<nums) && (g_userabort==false)); ++i)
        {
            sfe=(BigFileEntry *)SourceBigFile.GetEntry(i);
            bfe=DestBigFile.Locate(sfe->GetName()->GetString());
            if(!bfe)
            {
//				printf("File '%s' not in destination set!\n",she->m_string);
                update=true;
                ++numnew;
            }
            else
            {
                if(sfe->m_time==bfe->m_time)
                {
                    update=false;
                    ++numok;
                }
                else
                {
                    int deltatime;

                    deltatime=abs(sfe->m_time-bfe->m_time);
                    if(deltatime==46400 || deltatime==3600)
                    {
                        update=false;
                        ++numok;
                    }
                    else
                    {
                        printf("File '%s' %d,%d times are different!(%d)\n",sfe->GetName()->GetString(),sfe->m_time,bfe->m_time,deltatime);
                        ++numupdated;
                        update=true;
                    }
                }
            }

            if(update==true)
            {
                SourceBigFile.CopyArea(&addhandle,sfe->m_offset,sfe->m_size,sfe->m_time);
//				addsize=sfe->m_size;
//				addtime=sfe->m_time;
//				fseek(addhandle,sfe->m_offset,SEEK_SET);

                /* add the file to the bigfile */
                DestBigFile.AddFile(sfe->GetName()->GetString(),&addhandle,false);
            }
        }
        DestBigFile.UpdateDir();
    }
    else
    {
        HashEntry *she;
        FDATA *sfdata;

        nums=AddHash.GetNum();
        she=AddHash.GetFirst();
        for(i=0; ((i<nums) && (g_userabort==false)); ++i)
        {
            sfdata=(FDATA *)she->m_data;

            bfe=DestBigFile.Locate(she->m_string+tosspath);
            if(!bfe)
            {
//				printf("File '%s' not in destination set!\n",she->m_string+tosspath);
                ++numnew;
                update=true;
            }
            else
            {
                if(sfdata->time==bfe->m_time)
                {
                    update=false;
                    ++numok;
                }
                else
                {
                    int deltatime;

                    deltatime=(abs((int)sfdata->time-bfe->m_time));
                    if(deltatime==46400 || deltatime==3600)
                    {
                        update=false;
                        ++numok;
                    }
                    else
                    {
                        printf("File '%s' %d,%d times are different!(%d)\n",she->m_string+tosspath,(int)sfdata->time,bfe->m_time,deltatime);
                        ++numupdated;
                        update=true;
                    }
                }
            }
            if(update==true)
            {
                addhandle.SetFilename(she->m_string);
                /* add the file to the bigfile */
                DestBigFile.AddFile(she->m_string+tosspath,&addhandle,false);
            }

            she=she->m_next;
        }
        DestBigFile.UpdateDir();
    }
    printf("numok=%d,numnew=%d,numupdated=%d\n",numok,numnew,numupdated);

    return 0;
}