コード例 #1
0
ファイル: CSRformat.cpp プロジェクト: CooperLiu/openbabel
void CSRFormat::WriteCSRHeader(ostream &ofs,OBMol &mol)
{
    char *molnames;
    int nmol, natom;

    molnames = PadString((char*)mol.GetTitle(),100);

    nmol = 1;
    natom = mol.NumAtoms();

    WriteSize(4*sizeof(char),ofs);
    ofs.write("V33 ",strlen("V33 ")*sizeof(char));
    WriteSize(4*sizeof(char),ofs);

    WriteSize(2*sizeof(int),ofs);
    ofs.write((char*)&natom,sizeof(int));
    ofs.write((char*)&nmol,sizeof(int));
    WriteSize(2*sizeof(int),ofs);

    WriteSize(100*sizeof(char),ofs);
    ofs.write(molnames,100*sizeof(char));
    WriteSize(100*sizeof(char),ofs);

    WriteSize(sizeof(int),ofs);
    ofs.write((char*)&natom,sizeof(int));
    WriteSize(sizeof(int),ofs);

    delete [] molnames;
}
コード例 #2
0
ファイル: node.cpp プロジェクト: PeterZhouSZ/hyperion
nat32 Node::Write(io::OutVirt<io::Binary> & out) const
{
 nat32 ret = 0;
  // Header...
   nat32 bs = WriteSize();
   nat32 os = TotalWriteSize();
   nat8 zb = 0;

   ret += out.Write("HON",3);
   ret += out.Write(MagicString(),3);
   ret += out.Write(&bs,4);
   ret += out.Write(&zb,1);
   ret += out.Write(&os,4);
   ret += out.Write(&zb,1);
;
  // Child count...
   nat32 childCount = ChildCount();
   ret += out.Write(&childCount,4);

  // Children...
   if (child)
   {
    Node * targ = child;
    do
    {
     ret += targ->Write(out);
     targ = targ->Next();
    } while (!targ->First());
   }   

 if (ret!=bs) out.SetError(true);
 return ret;
}
コード例 #3
0
ファイル: opennurbs_zlib.cpp プロジェクト: Bardo91/pcl
bool ON_BinaryArchive::WriteCompressedBuffer(
        size_t sizeof__inbuffer,  // sizeof uncompressed input data
        const void* inbuffer  // uncompressed input data
        )
{
  size_t compressed_size = 0;
  bool rc = false;

  if ( !WriteMode() )
    return false;
  if ( sizeof__inbuffer > 0 && 0 == inbuffer )
    return false;


  // number of bytes of uncompressed data

  if (!WriteSize(sizeof__inbuffer))
    return false;
  if ( 0 == sizeof__inbuffer )
    return true;

  // 32 bit crc of uncompressed data
  const unsigned int buffer_crc = ON_CRC32( 0, sizeof__inbuffer, inbuffer );
  if (!WriteInt(buffer_crc))
    return false;

  unsigned char method = (sizeof__inbuffer > 128) ? 1 : 0;
  if ( method ) {
    if ( !CompressionInit() ) {
      CompressionEnd();
      method = 0;
    }
  }
  if ( !WriteChar(method) )
    return false;

  switch ( method )
  {
  case 0: // uncompressed
    rc = WriteByte(sizeof__inbuffer, inbuffer);
    if ( rc )
    {
      compressed_size = sizeof__inbuffer;
    }
    break;

  case 1: // compressed
    compressed_size = WriteDeflate( sizeof__inbuffer, inbuffer );
    rc = ( compressed_size > 0 ) ? true : false;
    CompressionEnd();
    break;
  }


  return rc;
}
コード例 #4
0
ファイル: CSRformat.cpp プロジェクト: CooperLiu/openbabel
void CSRFormat::WriteCSRCoords(ostream &ofs,OBMol &mol)
{
    int the_size,jconf;
    double x,y,z,energy;
    char title[100];
    char *tag;

    the_size = sizeof(int) + sizeof(double) + (80 * sizeof(char));

    jconf = 1;
    energy = -2.584565;

    snprintf(title, 80, "%s:%d",mol.GetTitle(),MolCount);
    tag = PadString(title,80);

    WriteSize(the_size,ofs);
    ofs.write((char*)&jconf,sizeof(int));
    ofs.write((char*)&energy,sizeof(double));
    ofs.write(tag,80*sizeof(char));
    WriteSize(the_size,ofs);

    WriteSize(mol.NumAtoms()*sizeof(double),ofs);

    OBAtom *atom;
    vector<OBAtom*>::iterator i;
    for (atom = mol.BeginAtom(i); atom; atom = mol.NextAtom(i))
    {
        x = atom->x();
        ofs.write((char*)&x,sizeof(double));
    }
    WriteSize(mol.NumAtoms()*sizeof(double),ofs);

    WriteSize(mol.NumAtoms()*sizeof(double),ofs);
    for (atom = mol.BeginAtom(i); atom; atom = mol.NextAtom(i))
    {
        y = atom->y();
        ofs.write((char*)&y,sizeof(double));
    }
    WriteSize(mol.NumAtoms()*sizeof(double),ofs);

    WriteSize(mol.NumAtoms()*sizeof(double),ofs);
    for (atom = mol.BeginAtom(i); atom; atom = mol.NextAtom(i))
    {
        z = atom->z();
        ofs.write((char*)&z,sizeof(double));
    }
    WriteSize(mol.NumAtoms()*sizeof(double),ofs);

    delete [] tag;
}
コード例 #5
0
int SrvrSaveWorldToFile( FILE *pFile, INDEX iWorld )
{
	PWORLD pWorld = GetSetMember( WORLD, &g.worlds, iWorld );
	int sz = 0, tmp, cnt;
	int worldpos;
	int linesize, linepos;
	int nlines;
	PFLATLAND_MYLINESEG *linearray;
	int wallsize, wallpos;
	int nwalls;
	PWALL *wallarray;
	int sectorsize, sectorpos;
	int nsectors;
	PSECTOR *sectorarray;
	int namesize, namepos;
	int nnames;
	PNAME *namearray;
	int texturesize, texturepos;
	int ntextures;
	PFLATLAND_TEXTURE *texturearray;

#ifdef LOG_SAVETIMING
	uint32_t begin, start = GetTickCount();
	begin = start;
#endif
	linearray   = GetLinearLineArray( pWorld->lines, &nlines );
	wallarray   = GetLinearWallArray( pWorld->walls, &nwalls );
	sectorarray = GetLinearSectorArray( pWorld->sectors, &nsectors );
	namearray   = GetLinearNameArray( pWorld->names, &nnames );
	texturearray = GetLinearTextureArray( pWorld->textures, &ntextures );

#ifdef LOG_SAVETIMING
	Log1( "Built arrays: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	fwrite( "FLAT", 1, 4, pFile );
	//-------------------------------------------------
	// Version 0: did not save "FLAT" tag - assumes version 1 info
	// Version 1: had extra nInto - sector reference for wall links...
	// Version 2: didn't compute sector origins, need to fix 
	// Version 3: lacked having sector ID saved
	// Version 4: lacked a text name per sector
	//   new section introduced - NAME ... referenced name sets
	//   for (walls?) and sectors.
	// version 5: lacked a count of lines in names - assume one line. 
	// Version 6: added flags to name type
	// version 7: (see version 8 notes for changes from 7)
	// version 8: Added Texture information (default texture for prior versions)
	//            internal added sector point sets (computed on load)
	//            internal added line reference count (computed on load)
	//            added current grid sizes/ grid color (saved in flatland)
	// version 9: flipped image upside down so +Y is 'top' and -Y is 'low'
	//            any version less than this must mult Y by -1 on load.
	// version 10: going to add sizes per section(added), and consider
	//            splitting off 'section' handlers keyed on 
	//            section names - will need coordination though :/ .. not added
	// (current - no changes to save or load)
	// version 11: 
	//-------------------------------------------------
	tmp = CURRENTSAVEVERSION;  

	// writesize( pWorld )
	worldpos = ftell( pFile );
	fwrite( &sz, 1, sizeof( sz ), pFile ); 
	sz = 0;

	Log1( "Saving version %d", tmp );
	sz += fwrite( &tmp, 1, sizeof( tmp ), pFile );

	//----- write lines -------
	sz += fwrite( "LINE", 1, 4, pFile );
	WriteSize( line );
	linesize += fwrite( &nlines, 1, sizeof(nlines), pFile );
	for( cnt = 0; cnt < nlines; cnt++ )
	{
		LINESEGFILE lsf;
      SetRay( &lsf.r, &linearray[cnt]->r );
      lsf.start = linearray[cnt]->dFrom;
      lsf.end   = linearray[cnt]->dTo;
		linesize += fwrite( &lsf, 1, sizeof( LINESEGFILE ), pFile );
	}
	UpdateSize( line );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Lines: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "WALL", 1, 4, pFile );
	WriteSize( wall );
	wallsize += fwrite( &nwalls, 1, sizeof(nwalls), pFile );
	for( cnt = 0; cnt < nwalls; cnt++ )
	{
		FILEWALLV2 WriteWall;
		PWALL pwall = wallarray[cnt];
		WriteWall.flags = pwall->flags;

		tmp = WriteWall.nSector = FindInArray( (POINTER*)sectorarray, nsectors, GetUsedSetMember( SECTOR, &pWorld->sectors, pwall->iSector ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced sector... save will fail %d", cnt );

		tmp = WriteWall.nLine = FindInArray( (POINTER*)linearray, nlines, GetUsedSetMember( FLATLAND_MYLINESEG, &pWorld->lines, pwall->iLine ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced line... save will fail %d", cnt );

		if( pwall->iWallInto != INVALID_INDEX )
		{
			tmp = WriteWall.nWallInto = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallInto ) );
			if( tmp < 0 )
				Log1( "Failed to find referenced wall into... save will fail %d", cnt );
		}
		else
			WriteWall.nWallInto = -1;

		tmp = WriteWall.nWallStart = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallStart ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced starting wall... save will fail %d", cnt );

		tmp = WriteWall.nWallEnd = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallEnd ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced ending wall... save will fail %d", cnt );

		wallsize += fwrite( &WriteWall, 1, sizeof( WriteWall ), pFile );	
	}
	UpdateSize( wall );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Walls: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "SECT", 1, 4, pFile );
	WriteSize( sector );
	sectorsize += fwrite( &nsectors, 1, sizeof( nsectors ), pFile );
	for( cnt = 0; cnt < nsectors; cnt++ )
	{
		FILESECTORV8 WriteSector;
		WriteSector.nName = FindInArray( (POINTER*)namearray, nnames, GetUsedSetMember( NAME, &pWorld->names, sectorarray[cnt]->iName ) );
		//WriteSector.nID = sectorarray[cnt]->nID;
		WriteSector.flags = sectorarray[cnt]->flags;
		SetRay( &WriteSector.r, &sectorarray[cnt]->r );
		tmp = WriteSector.nwall = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, sectorarray[cnt]->iWall ) );
		if( tmp < 0 )
			Log1( "Failed to find wall referenced by sector.. save failing %d", cnt );
		WriteSector.nTexture = FindInArray( (POINTER*)texturearray, ntextures, GetUsedSetMember( FLATLAND_TEXTURE, &pWorld->textures, sectorarray[cnt]->iTexture ) );
		if( tmp < 0 )
			Log1( "Failed to find texture referenced by sector.. save failing %d", cnt );
		sectorsize += fwrite( &WriteSector, 1, sizeof( WriteSector ), pFile );
	}
	UpdateSize( sector );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Sectors: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "NAME", 1, 4, pFile );
	WriteSize( name );
	namesize += fwrite( &nnames, 1, sizeof( nnames ), pFile );
	for( cnt = 0; cnt < nnames; cnt++ )
	{
		int l;
		uint16_t lines = namearray[cnt]->lines;
		namesize += fwrite( &namearray[cnt]->flags, 1, sizeof( namearray[cnt]->flags ), pFile );
		namesize += fwrite( &lines, 1, sizeof( lines ), pFile );
		for( l = 0; l < lines; l++ )
		{
			namesize += fwrite( &namearray[cnt]->name[l].length, 1, sizeof( namearray[cnt]->name[l].length ), pFile );
			namesize += fwrite( namearray[cnt]->name[l].name, 1, namearray[cnt]->name[l].length, pFile );
		}
	}
	UpdateSize( name );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Names: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "TEXT", 1, 4, pFile );

	WriteSize( texture );

	texturesize += fwrite( &ntextures, 1, sizeof( ntextures ), pFile );
	for( cnt = 0; cnt < ntextures; cnt++ )
	{
		char flag;
		int nName = FindInArray( (POINTER*)namearray, nnames, GetUsedSetMember( NAME, &pWorld->names, texturearray[cnt]->iName ) );
		texturesize += fwrite( &nName, 1, sizeof( nName ), pFile );
		flag = texturearray[cnt]->flags.bColor;
		texturesize += fwrite( &flag, 1, sizeof( flag ), pFile );
		// if flag is set - write cdata 
		if( flag )
		{
			texturesize += fwrite( &texturearray[cnt]->data.color, 1, sizeof( CDATA ), pFile );
		}				
	}

	UpdateSize( texture );

#ifdef LOG_SAVETIMING
	Log1( "Wrote Textures: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	{
		int endpos;
		endpos = ftell( pFile );
		fseek( pFile, worldpos, SEEK_SET );
		fwrite( &sz, 1, sizeof( sz ), pFile );
		fseek( pFile, endpos, SEEK_SET );
	}

#ifdef LOG_SAVETIMING
	Log1( "Wrote File: %d", GetTickCount() - begin );
#endif

	Release( texturearray );
	Release( namearray );
	Release( sectorarray );
	Release( wallarray );
	Release( linearray );
#ifdef LOG_SAVETIMING
	Log1( "Released arrays: %d", GetTickCount() - start );
#endif

	return sz;
}
コード例 #6
0
ファイル: node.cpp プロジェクト: PeterZhouSZ/hyperion
nat32 Node::TotalWriteSize() const
{
 return WriteSize();
}