示例#1
0
char* mml_serialize(MMLObject* mml) {
	DArray out;
	out = darray_create(sizeof(char), 0);

	_serialize(mml, &out, 0, 0);
	darray_append(&out, "\0");

	// This is a hack, but saves one alloc/free pair.
	// Freeing out.data is mostly the same as calling darray_free.
	return (char*)out.data;
}	
void CPersistentDataContainer::_writeToFile(std::vector<std::string>& dataNames,std::vector<std::string>& dataValues)
{
	std::string filenameAndPath(VVarious::splitPath_path(VVarious::getModulePathAndFile())+VREP_SLASH+V_REP_SYSTEM_DIRECTORY_NAME+VREP_SLASH+_filename.c_str());
	try
	{
		VFile myFile(filenameAndPath,VFile::CREATE|VFile::WRITE|VFile::SHARE_EXCLUSIVE);
		myFile.setLength(0);
		VArchive archive(&myFile,VArchive::STORE);
		_serialize(archive,dataNames,dataValues);
		archive.close();
		myFile.close();
	}
	catch(VFILE_EXCEPTION_TYPE e)
	{
		// silent error since 3/2/2012: when the system folder dowesn't exist, we don't want an error!!    VFile::reportAndHandleFileExceptionError(e);
	}
}
void CPersistentDataContainer::_readFromFile(std::vector<std::string>& dataNames,std::vector<std::string>& dataValues)
{
	dataNames.clear();
	dataValues.clear();
	std::string filenameAndPath(VVarious::splitPath_path(VVarious::getModulePathAndFile())+VREP_SLASH+V_REP_SYSTEM_DIRECTORY_NAME+VREP_SLASH+_filename.c_str());
	if (VFile::doesFileExist(filenameAndPath))
	{
		try
		{
			VFile file(filenameAndPath,VFile::READ|VFile::SHARE_DENY_NONE);
			VArchive archive(&file,VArchive::LOAD);
			_serialize(archive,dataNames,dataValues);
			archive.close();
			file.close();
		}
		catch(VFILE_EXCEPTION_TYPE e)
		{
			// silent error since 3/2/2012: when the system folder dowesn't exist, we don't want an error!!    VFile::reportAndHandleFileExceptionError(e);
		}
	}
}
示例#4
0
void _serialize(MMLObject* mml, DArray* out, NodeIdx node, uint padding) {
	assert(mml);
	assert(out);

	MMLNode* node_ptr = mml_get_nodeptr(mml, node);
	
	uint i = padding;
	while(i--) {
		darray_append(out, " ");
	}	

	const char* name = mml_get_str(mml, node_ptr->name_start);
	const char* value = mml_get_str(mml, node_ptr->value_start);

	darray_append_multi(out, "( ", 2);
	mml_insert_escapes(name, out);
	darray_append(out, " ");
	mml_insert_escapes(value, out);

	if(node_ptr->first_child_idx == 0) {
		// node has no children, print it on a single line
		darray_append_multi(out, " )\n", 3);
		return;
	}
	else {
		// node has children, recurse
		darray_append(out, "\n");
		NodeIdx child = node_ptr->first_child_idx;
		while(child) {
			_serialize(mml, out, child, padding + 4);
			child = mml_get_next(mml, child);
		}	
		i = padding;
		while(i--) {
			darray_append(out, " ");
		}	
		darray_append_multi(out, ")\n", 2);
	}	
}	
示例#5
0
 void DurOp::serialize(AlignedBuilder& ab) {
     ab.appendNum(_opcode);
     _serialize(ab);
 }
示例#6
0
 inline std::string value::_serialize(int indent) const {
   std::string s;
   _serialize(std::back_inserter(s), indent);
   return s;
 }
示例#7
0
 inline std::string value::serialize(bool prettify) const {
   return _serialize(prettify ? 0 : -1);
 }
示例#8
0
 template <typename Iter> void value::serialize(Iter oi, bool prettify) const {
   return _serialize(oi, prettify ? 0 : -1);
 }