当前位置: 首页>>代码示例>>C++>>正文


C++ filebuf类代码示例

本文整理汇总了C++中filebuf的典型用法代码示例。如果您正苦于以下问题:C++ filebuf类的具体用法?C++ filebuf怎么用?C++ filebuf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了filebuf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: iconv

filebuf IconvWrapper::convert(const filebuf& input)
{
	size_t ret = 0;

	char* BUFFER;
	size_t BUFFSIZE;

	size_t inbytesleft = 0;
	size_t outbytesleft = 0;
	char* input_ptr = 0;
	char* output_ptr = 0;

	char* output = 0; // The final result will go here...
	size_t output_size = 0;

	// How much data should be put avaiable to iconv?
	// How about twice as much as input's length?
	inbytesleft = input.len();
	BUFFSIZE = 2 * inbytesleft;
	outbytesleft = BUFFSIZE;

	// Get memory to hold our converted data.
	BUFFER = new char[ BUFFSIZE ];

	input_ptr = (char*)input.current;
	output_ptr = BUFFER;

	ret = iconv(	cd,
			&input_ptr, &inbytesleft, 
			&output_ptr, &outbytesleft);
	if (ret == size_t(-1)) {
		delete[] BUFFER;
		throw IconvError("While converting...");
	} 

	// Got here? So everything went fine.

	// Copy data to a more memory-efficient location
	output_size = BUFFSIZE - outbytesleft;
	output = new char[output_size];
	memcpy(output, BUFFER, output_size);
	delete[] BUFFER;

	return filebuf(output, output_size);
}
开发者ID:tmacam,项目名称:CrawlingBeast,代码行数:45,代码来源:unicodebugger.cpp

示例2: decompress

filebuf decompress(filebuf data)
{
	/* This code is based on zLib's usage example, available 
	 * at http://www.zlib.net/zlib_how.html
	 */

	// Zlib stuff
	int ret;
	z_stream strm;
	unsigned int have;
	// Outputing stuff
	size_t OUTBUF_LEN = DECOMPRESS_RESERVE; 
	char outbuf[OUTBUF_LEN];
	std::vector<char> accbuf; // accumulator buffer
	accbuf.reserve(DECOMPRESS_RESERVE);

	
	if (data.len() == 0) {
		// Empty filebufs result in empty filebufs.
		return filebuf();
	}

	/* allocate inflate state */
	const int windowBits = 15 + 16; /* 15 is the default value for 
					 * windownBits in inflateInit().
					 *
					 * Bits+16 means "use gzip" in
					 * zlib >= 1.2. Use 32 instead
					 * of 16 to force automatic header
					 * detection for gzip/zlib.
					 */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = data.len();
	strm.next_in = Z_NULL;

	ret = inflateInit2(&strm, windowBits);
	if (ret != Z_OK){
		throw ZLibException("in inflateInit2", ret);
	}

	strm.avail_in = data.len();
	strm.next_in = (unsigned char*) data.current;

	/* decompress until deflate stream ends or an error happens */
	do {
		/* Remember: all input data _is_ available! All we can and
		 * must do is loop until zlib reports that it has
		 * finished or an error occurs.
		 */

		/* run inflate() on input until output buffer not full */
		do {

			strm.avail_out = OUTBUF_LEN;
			strm.next_out = (unsigned char*) outbuf;

			ret = inflate(&strm, Z_NO_FLUSH);
			// make sure state not clobbered
			if (ret == Z_STREAM_ERROR) {
				throw ZLibException("in inflate", ret);
			}
			switch (ret) {
				case Z_NEED_DICT:
					ret = Z_DATA_ERROR; // and fall through
				case Z_DATA_ERROR:
				case Z_MEM_ERROR:
					(void)inflateEnd(&strm);
					throw ZLibException("in inflate", ret);
			}

			have = OUTBUF_LEN - strm.avail_out;

			accbuf.insert(	accbuf.end(),
					outbuf,
					&outbuf[have]);
		} while (strm.avail_out == 0);

		/* done when inflate() says it's done */

	} while(ret != Z_STREAM_END);

	/* clean up */
	(void)inflateEnd(&strm);

	/* Ugly and lazy copy to an array */
	char* final_buffer = new char[accbuf.size()];
	std::copy(accbuf.begin(), accbuf.end(), final_buffer);

	return filebuf(final_buffer, accbuf.size());

}
开发者ID:tmacam,项目名称:CrawlingBeast,代码行数:93,代码来源:zfilebuf.cpp

示例3: swap

inline void swap(filebuf& x, filebuf& y)
{
    x.swap(y);
}
开发者ID:dimitry-ishenko,项目名称:camel,代码行数:4,代码来源:filebuf.hpp

示例4: parseKeyFramer

static void parseKeyFramer( MeshModel *root ){
	_log( "KeyFramer" );
	enterChunk();
	string file_3ds;
	unsigned short rev,curr_time=0;
	while( int id=nextChunk() ){
		switch( id ){
		case 0xb009:	//CURR_TIME
			in.sgetn( (char*)&curr_time,2 );
			_log( "CURR_TIME: "+itoa(curr_time) );
			break;
		case 0xb00a:	//KFHDR
			in.sgetn( (char*)&rev,2 );
			file_3ds=parseString();
			in.sgetn( (char*)&anim_len,2 );
			_log( "KFHDR: revision="+itoa(rev)+" 3dsfile="+file_3ds+" anim_len="+itoa(anim_len) );
			break;
		case 0xb002:	//object keyframer data...
			parseMeshInfo( root,curr_time );
			break;
		}
	}

	if( !collapse ){
		root->setAnimator( d_new Animator( root,anim_len ) );
	}

	leaveChunk();
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:29,代码来源:loader_3ds.cpp

示例5:

MeshModel *Loader_3DS::load( const string &filename,const Transform &t,int hint ){

	conv_tform=t;
	conv=flip_tris=false;
	if( conv_tform!=Transform() ){
		conv=true;
		if( conv_tform.m.i.cross(conv_tform.m.j).dot(conv_tform.m.k)<0 ) flip_tris=true;
	}

	collapse=!!(hint&MeshLoader::HINT_COLLAPSE);
	animonly=!!(hint&MeshLoader::HINT_ANIMONLY);

	if( !in.open( filename.c_str(),ios_base::in|ios_base::binary ) ){
		return 0;
	}

	MeshModel *root=parseFile();
	in.close();

	materials_map.clear();
	name_map.clear();
	id_map.clear();

	return root;
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:25,代码来源:loader_3ds.cpp

示例6: nextChunk

static int nextChunk(){
	in.pubseekoff( chunk_end,ios_base::beg );
	if( chunk_end==parent_end.back() ) return 0;
	unsigned short id;int len;
	in.sgetn( (char*)&id,2 );
	in.sgetn( (char*)&len,4 );
	chunk_end=(int)in.pubseekoff( 0,ios_base::cur )+len-6;
	return id;
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:9,代码来源:loader_3ds.cpp

示例7: main

int main(){
	a.open("target.txt", std::ios::in);
	d.open("dse.txt", std::ios::in);
	r.open("relation0.txt", std::ios::in);
	istream ia(&a), id(&d), ir(&r);
	string sa, sd, sr;
	len = 0; arg_num = -1; dse_num = -1;
	while (getline(ia, sa)){
		getline(id, sd);
		sa = sa.substr(0, sa.size() -1 );
//		cout<<sa<<","<<sd<<endl;
		if (sa.size() <= 1){
			memset(ans, 0, sizeof(ans));
			while (sr.size() > 1){
				string dseID, argID;
				uint i = sr.find_first_of('\t');
				dseID = sr.substr(0, i);
				argID= sr.substr(i+1, sr.size()-i-2);
				int x = toDigit(dseID), y = toDigit(argID);
				for (int i = 0; i < dse[x].size(); i ++)
					for (int j = 0; j < arg[y].size(); j ++)
						ans[dse[x][i]][arg[y][j]] = 1;
			}
			for (int i = 0; i < len; i ++){
				cout<<ans[i][0];
				for (int j = 1; j < len; j ++){
					cout<<"\t"<<ans[i][j];
				}
				cout<<"\n";
			}
			cout<<"\n";
			len = 0; arg_num = -1; dse_num = -1;

		}else{
//			sa = sa.substr(0, sa.size() - 1);
			sd = sd.substr(0, sd.size() - 1);
			string token, part, tl, al, dl;
			uint i = sa.find_last_of('\t');
			al = sa.substr(i+1, sa.size()-i-1);
			i = sd.find_last_of('\t');
			dl = sd.substr(i+1, sd.size()-i-1);
//			cerr<<al<<","<<dl<<","<<endl;
			if (al == "B"){
				arg_num ++;
				arg[arg_num].clear(); arg[arg_num].push_back(len);
			}
			if (dl == "B"){
				dse_num ++;
				dse[dse_num].clear(); dse[dse_num].push_back(len);
			}
			if (al == "I"){arg[arg_num].push_back(len);}
			if (dl == "I"){dse[dse_num].push_back(len);}
			len ++;
		}
	}
}
开发者ID:vegetable68,项目名称:deep-recurrent,代码行数:56,代码来源:sep.cpp

示例8: parseVertList

static void parseVertList(){
	unsigned short cnt;
	in.sgetn( (char*)&cnt,2 );
	_log( "VertList cnt="+itoa(cnt) );
	while( cnt-- ){
		Surface::Vertex v;
		in.sgetn( (char*)&v.coords,12 );
		if( conv ) v.coords=conv_tform * v.coords;
		MeshLoader::addVertex( v );
	}
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:11,代码来源:loader_3ds.cpp

示例9: parseFaceMat

static void parseFaceMat(){
	string name=parseString();
	_log( "FaceMat: "+name );
	Brush mat=materials_map[name];
	unsigned short cnt;
	in.sgetn( (char*)&cnt,2 );
	while( cnt-- ){
		unsigned short face;
		in.sgetn( (char*)&face,2 );
		faces[face].brush=mat;
	}
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:12,代码来源:loader_3ds.cpp

示例10: main

int main(){
	attitude.open("MPQA2.0_processed/attitude_alignannos.txt", std::ios::in);
	dse.open("MPQA2.0_processed/dse_alignannos.txt", std::ios::in);
	target.open("MPQA2.0_processed/target_alignannos.txt", std::ios::in);

	istream ia(&attitude), id(&dse), it(&target);
	string sa, sd, st;
	while (getline(id, sd){
		getline(ia, sa);
		getline(it, st);
		if (st != "") st += '\t';
		int last = 0, targetid = 0;
		while (st.find("id", last) != -1){
			int nxt = st.find("id", last);
			string tar = "";
			for (int j = nxt + 3; j != st.size() && st[j] != '\t'; j ++)
				tar += st[j];
			int
		}
		last = 0;
		int dseid = 0;
		if (sd != "") sd += '\t';
		while (sd.find_first_of('\t', last) != -1){
			int nxt = sd.find_first_of('\t', last);
			string subsd = sd.substr(last, nxt - 1);
			int loc = subsd.find("attrlink");
			loc += 9;
			string attr = "";
			for (int j = loc; j != subsd.length() && subsd[j] != ';'; j ++) attr += subsd[j];
			last = nxt + 1;
		}
		if (st == "") cout<<"\n";
		else{
			st = st.substr(0, st.size() - 1);
			sa = sa.substr(0, sa.size() - 1);
			sd = sd.substr(0, sd.size() - 1);
			string token, part, tl, al, dl;
			uint i = st.find_first_of('\t');
			token = st.substr(0, i);
			uint j = st.find_first_of('\t', i+1);
			part = st.substr(i+1,j-i-1);
			//cout << part << endl;
			i = st.find_last_of('\t');
			tl = st.substr(i+1, st.size()-i-1);
			i = sa.find_last_of('\t');
			al = sa.substr(i+1, sa.size()-i-1);
			i = sd.find_last_of('\t');
			dl = sd.substr(i+1, sd.size()-i-1);
			cout<<token<<"\t"<<part<<"\t"<<tl<<"\t"<<al<<"\t"<<dl<<endl;
		}
	}
}
开发者ID:vegetable68,项目名称:deep-recurrent,代码行数:52,代码来源:getRelation.cpp

示例11: parseMapList

static void parseMapList(){
	_log( "MapList" );
	unsigned short cnt;
	in.sgetn( (char*)&cnt,2 );
	for( int k=0;k<cnt;++k ){
		float uv[2];
		in.sgetn( (char*)uv,8 );
		Surface::Vertex &v=MeshLoader::refVertex( k );
		v.tex_coords[0][0]=v.tex_coords[1][0]=uv[0];
		v.tex_coords[0][1]=v.tex_coords[1][1]=1-uv[1];
//		v->tex_coords[0]=v->tex_coords[1]=Vector( uv[0],1-uv[1],1 );
	}
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:13,代码来源:loader_3ds.cpp

示例12: parseColor

static Vector parseColor(){
	Vector v;
	unsigned char rgb[3];
	enterChunk();
	while( int id=nextChunk() ){
		switch( id ){
		case CHUNK_RGBF:
			in.sgetn( (char*)&v,12 );
			break;
		case CHUNK_RGBB:
			in.sgetn( (char*)rgb,3 );
			v=Vector( rgb[0]/255.0f,rgb[1]/255.0f,rgb[2]/255.0f );
		}
	}
	leaveChunk();
	return v;
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:17,代码来源:loader_3ds.cpp

示例13: parseTriMesh

static void parseTriMesh( MeshModel *mesh ){
	_log( "TriMesh" );
	enterChunk();
	Transform tform;

	faces.clear();

	MeshLoader::beginMesh();

	while( int id=nextChunk() ){
		switch( id ){
		case CHUNK_VERTLIST:
			if( !animonly ) parseVertList();
			break;
		case CHUNK_MAPLIST:
			if( !animonly ) parseMapList();
			break;
		case CHUNK_FACELIST:
			if( !animonly ) parseFaceList();
			break;
		case CHUNK_TRMATRIX:
			in.sgetn( (char*)&tform,48 );
			if( conv ) tform=conv_tform * tform * -conv_tform;
			break;
		}
	}
	leaveChunk();

	//should really do something here...
//	bool neg_x=tform.m.j.cross(tform.m.k).dot(tform.m.i)<0;

	int k;

	mesh->setWorldTform( tform );

	if( animonly ){
		MeshLoader::endMesh( 0 );
		return;
	}

	Transform inv_tform=-tform;
	for( k=0;k<MeshLoader::numVertices();++k ){
		Surface::Vertex &v=MeshLoader::refVertex( k );
		v.coords=inv_tform * v.coords;
	}

	for( k=0;k<faces.size();++k ){
		const Face3DS &f=faces[k];
		MeshLoader::addTriangle( f.verts,f.brush );
	}

	MeshLoader::endMesh( mesh );
	mesh->updateNormals();

	faces.clear();
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:56,代码来源:loader_3ds.cpp

示例14: MeshModel

static MeshModel *parseFile(){
	unsigned short id;int len;
	in.sgetn( (char*)&id,2 );
	in.sgetn( (char*)&len,4 );
	if( id!=CHUNK_MAIN ) return 0;
	chunk_end=(int)in.pubseekoff( 0,ios_base::cur )+len-6;

	enterChunk();
	MeshModel *root=d_new MeshModel();
	while( int id=nextChunk() ){
		switch( id ){
		case CHUNK_SCENE:
			parseScene( root );
			break;
		case CHUNK_KEYFRAMER:
			parseKeyFramer( root );
			break;
		}
	}
	leaveChunk();
	return root;
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:22,代码来源:loader_3ds.cpp

示例15: parseFaceList

static void parseFaceList(){
	unsigned short cnt;
	in.sgetn( (char*)&cnt,2 );
	_log( "FaceList cnt="+itoa(cnt) );
	while( cnt-- ){
		unsigned short v[4];
		in.sgetn( (char*)v,8 );
		Face3DS face;
		face.verts[0]=v[0];
		face.verts[1]=v[1];
		face.verts[2]=v[2];
		if( flip_tris ) std::swap( face.verts[1],face.verts[2] );
		faces.push_back( face );
	}
	enterChunk();
	while( int id=nextChunk() ){
		switch( id ){
		case CHUNK_FACEMAT:
			parseFaceMat();
			break;
		}
	}
	leaveChunk();
}
开发者ID:littlewater,项目名称:blitz3d,代码行数:24,代码来源:loader_3ds.cpp


注:本文中的filebuf类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。