46 #define snprintf _snprintf 57 Object* obj = getImportedStructure(st);
62 std::map< std::string, ref<ClassWrapper> >::iterator it = registry()->importRegistry().find(st->
tag());
63 if (it != registry()->importRegistry().end())
71 setError(ImportError);
79 setError(ImportError);
80 Log::error(
Say(
"No importing serializer found for structure '%s'.") << st->
tag() );
99 std::map< TypeInfo, ref<ClassWrapper> >::iterator it = registry()->exportRegistry().find(obj->classType());
100 if (it != registry()->exportRegistry().end())
108 setError(ExportError);
109 Log::error(
Say(
"Error exporting '%s'.") << obj->classType().name() );
116 setError(ExportError);
117 Log::error(
Say(
"No exporting serializer found for '%s'.") << obj->classType().name() );
129 return registry()->exportRegistry().find(obj->classType()) != registry()->exportRegistry().end();
137 return registry()->importRegistry().find(st->
tag()) != registry()->importRegistry().end();
142 VL_CHECK( mImportedStructures.find(st) == mImportedStructures.end() )
143 mImportedStructures[st] = obj;
148 VL_CHECK(mExportedObjects.find(obj) == mExportedObjects.end())
149 mExportedObjects[obj] = st;
154 std::map< ref<VLXStructure>,
ref<Object> >::iterator it = mImportedStructures.find(st);
155 if (it == mImportedStructures.end())
160 return it->second.get_writable();
166 std::map< ref<Object>,
ref<VLXStructure> >::iterator it = mExportedObjects.find(obj);
167 if (it == mExportedObjects.end())
172 return it->second.get_writable();
176 void VLXSerializer::signalImportError(
const String& str)
182 setError( VLXSerializer::ImportError );
186 void VLXSerializer::signalExportError(
const String& str)
192 setError( VLXSerializer::ExportError );
196 std::string VLXSerializer::generateID(
const char* prefix)
198 char number[
sizeof(int)*8+1];
199 snprintf(number,
sizeof(number),
"%d", ++mIDCounter);
200 return std::string(
"#") + prefix +
"id" + number;
220 std::map< std::string, VLXValue >::iterator it = metadata().begin();
221 for( ; it != metadata().end(); ++it )
223 if (it->first ==
"VL_Serializer_Version")
225 if (it->first ==
"Authoring_Tool")
227 if (it->first ==
"Creation_Date")
234 String auth =
Say(
"Visualization Library %n.%n.%s") << VL_Major << VL_Minor << VL_Patch;
239 std::string str = ctime(&rawtime);
240 str.resize(str.size()-1);
241 *meta <<
"Creation_Date" <<
VLXValue( str.c_str(), VLXValue::String );
248 std::map< std::string, int > uid_set;
255 text_export_visitor.
setIDSet(&uid_set);
261 if ( file->
write( text_export_visitor.
text().c_str(), text_export_visitor.
text().size() ) != (
int)text_export_visitor.
text().size() )
263 Log::error(
Say(
"VLXSerializer::saveVLT() write error : %s\n") << file->
path() );
268 return mError == NoError;
291 std::map< std::string, VLXValue >::iterator it = metadata().begin();
292 for( ; it != metadata().end(); ++it )
294 if (it->first ==
"VL_Serializer_Version")
296 if (it->first ==
"Authoring_Tool")
298 if (it->first ==
"Creation_Date")
305 String auth =
Say(
"Visualization Library %n.%n.%s") << VL_Major << VL_Minor << VL_Patch;
310 std::string str = ctime(&rawtime);
311 str.resize(str.size()-1);
312 *meta <<
"Creation_Date" <<
VLXValue( str.c_str(), VLXValue::String );
319 std::map< std::string, int > uid_set;
326 bin_export_visitor.
setIDSet(&uid_set);
332 return mError == NoError;
353 setDocumentURL( file->
path() );
358 bool ok = parser.parse();
363 setError(ImportError);
368 metadata() = parser.metadata();
372 setError(ImportError);
376 if (parser.structures().empty())
379 return importVLX( parser.structures()[0].get() );
397 setDocumentURL( file->
path() );
402 bool ok = parser.parse();
407 setError(ImportError);
412 metadata() = parser.metadata();
416 setError(ImportError);
420 if (parser.structures().empty())
423 return importVLX( parser.structures()[0].get() );
426 const char* VLXSerializer::errorString()
const 430 case NoError:
return "NoError";
431 case ImportError:
return "ImportError";
432 case ExportError:
return "ExportError";
433 case ReadError:
return "ReadError";
435 case WriteError:
return "WriteError";
439 void VLXSerializer::resolvePath(std::string& path)
VLX_EXPORT bool saveVLT(vl::VirtualFile *file, const vl::ResourceDatabase *)
Wrapper for all VLX value types.
void setInputFile(vl::VirtualFile *file)
An abstract class representing a file.
A simple String formatting class.
Counts the number of occurrencies of each ID.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Key/value pair used by VLXStructure.
Parses a VLT file translating it into a VLX hierarchy.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
String extractPath() const
If the String contains a file path the function returns the path with trailing slash, without the file name.
Base cass for all class wrappers implementing the translation to/from its VLX representation.
void setIDSet(std::map< std::string, int > *uids)
const std::string & text() const
String & normalizeSlashes()
Transform \ slashes in / slashes and removes duplicates.
void setInputFile(VirtualFile *file)
virtual void close()=0
Closes the file.
const String & path() const
Returns the path of the file.
Visualization Library main namespace.
static String fromStdString(const std::string &str, bool utf8=true)
Initializes the string from a std::string using fromUTF() if utf8 == true (default) otherwise uses fr...
void setIDSet(std::map< std::string, int > *uids)
A list of key/VLXValue pairs, can also have a tag.
The base class for all the reference counted objects.
#define VL_SERIALIZER_VERSION
const std::string & tag() const
Translates a VLX hierarchy into VLB format writing to the provided VirtualFile.
long long write(const void *buffer, long long byte_count)
Writes byte_count bytes to a file. Returns the number of bytes actually written.
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
virtual vl::ref< VLXStructure > exportVLX(VLXSerializer &s, const vl::Object *obj)=0
bool startsWith(const String &str) const
Returns true if a String starts with the specified String str.
virtual void acceptVisitor(Visitor *v)
std::vector< KeyValue > & value()
void setIDSet(std::map< std::string, int > *uids)
VLX_EXPORT vl::ref< vl::ResourceDatabase > loadVLT(vl::VirtualFile *file)
VLTTokenizer * tokenizer()
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
Parses a VLT file translating it into a VLX hierarchy.
A VirtualFile that operates on regular disk files.
VLX_EXPORT bool saveVLB(vl::VirtualFile *file, const vl::ResourceDatabase *)
The ref<> class is used to reference-count an Object.
String right(int count) const
Returns the count rightmost caracters of a String. If count is negative the function returns all but ...
std::string toStdString() const
Returns a UTF8 encoded std::string.
Translates a VLX hierarchy into VLT notation.
VLX_EXPORT vl::ref< vl::ResourceDatabase > loadVLB(vl::VirtualFile *file)
virtual vl::ref< vl::Object > importVLX(VLXSerializer &s, const VLXStructure *st)=0