45 #define snprintf _snprintf 79 Log::error(
Say(
"No importing serializer found for structure '%s'.") << st->
tag() );
98 std::map< TypeInfo, ref<VLXClassWrapper> >::iterator it =
registry()->
exportRegistry().find(obj->classType());
108 Log::error(
Say(
"Error exporting '%s'.") << obj->classType().name() );
116 Log::error(
Say(
"No exporting serializer found for '%s'.") << obj->classType().name() );
141 VL_CHECK( mImportedStructures.find(st) == mImportedStructures.end() )
142 mImportedStructures[st] = obj;
147 VL_CHECK(mExportedObjects.find(obj) == mExportedObjects.end())
148 mExportedObjects[obj] = st;
153 std::map< ref<VLXStructure>,
ref<Object> >::iterator it = mImportedStructures.find(st);
154 if (it == mImportedStructures.end())
159 return it->second.get_writable();
165 std::map< ref<Object>,
ref<VLXStructure> >::iterator it = mExportedObjects.find(obj);
166 if (it == mExportedObjects.end())
171 return it->second.get_writable();
197 char number[
sizeof(int)*8+1];
198 snprintf(number,
sizeof(number),
"%d", ++mIDCounter);
199 return std::string(
"#") + prefix +
"id" + number;
219 std::map< std::string, VLXValue >::iterator it =
metadata().begin();
220 for( ; it !=
metadata().end(); ++it )
222 if (it->first ==
"VL_Serializer_Version")
224 if (it->first ==
"Authoring_Tool")
226 if (it->first ==
"Creation_Date")
233 String auth =
Say(
"Visualization Library %n.%n.%s") << VL_Major << VL_Minor << VL_Patch;
238 std::string str = ctime(&rawtime);
239 str.resize(str.size()-1);
242 *meta <<
"VL_Serializer_Version" <<
VLXValue( (
long long) 100 );
247 std::map< std::string, int > uid_set;
254 text_export_visitor.
setIDSet(&uid_set);
260 if ( file->
write( text_export_visitor.
text().c_str(), text_export_visitor.
text().size() ) != (
int)text_export_visitor.
text().size() )
262 Log::error(
Say(
"VLXSerializer::saveVLT() write error : %s\n") << file->
path() );
290 std::map< std::string, VLXValue >::iterator it =
metadata().begin();
291 for( ; it !=
metadata().end(); ++it )
293 if (it->first ==
"VL_Serializer_Version")
295 if (it->first ==
"Authoring_Tool")
297 if (it->first ==
"Creation_Date")
304 String auth =
Say(
"Visualization Library %n.%n.%s") << VL_Major << VL_Minor << VL_Patch;
309 std::string str = ctime(&rawtime);
310 str.resize(str.size()-1);
313 *meta <<
"VL_Serializer_Version" <<
VLXValue( (
long long) 100 );
318 std::map< std::string, int > uid_set;
325 bin_export_visitor.
setIDSet(&uid_set);
357 bool ok = parser.parse();
375 if (parser.structures().empty())
378 return importVLX( parser.structures()[0].get() );
401 bool ok = parser.parse();
419 if (parser.structures().empty())
422 return importVLX( parser.structures()[0].get() );
429 case NoError:
return "NoError";
ref< Object > loadVLB(const String &path, bool start_fresh=true)
void registerImportedStructure(const VLXStructure *st, Object *obj)
const std::string & text() const
Counts the number of occurrencies of each ID.
void setError(EError err)
Sets a serialization error.
void setIDSet(std::map< std::string, int > *uids)
bool canExport(const Object *obj) const
VLXRegistry * registry()
The VLXRegistry used by the serializer, by default set to vl::defVLXRegistry().
An abstract class representing a file.
std::map< std::string, VLXValue > & metadata()
The metadata to be imported or exported.
A simple String formatting class.
Parses a VLT file translating it into a VLX hierarchy.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
bool canImport(const VLXStructure *st) const
virtual ref< VLXStructure > exportVLX(VLXSerializer &s, const Object *obj)=0
void setDocumentURL(const String &location)
The URL of the document used to resolve document-relative file paths.
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...
VLXStructure * exportVLX(const Object *obj)
void registerExportedObject(const Object *obj, VLXStructure *st)
String extractPath() const
If the String contains a file path the function returns the path with trailing slash, without the file name.
void signalExportError(const String &str)
std::string generateID(const char *prefix)
virtual ref< Object > importVLX(VLXSerializer &s, const VLXStructure *st)=0
void setIDSet(std::map< std::string, int > *uids)
std::map< std::string, ref< VLXClassWrapper > > & importRegistry()
ref< Object > loadVLT(const String &path, bool start_fresh=true)
String & normalizeSlashes()
Transform \ slashes in / slashes and removes duplicates.
void setInputFile(VirtualFile *file)
virtual void close()=0
Closes the file.
void setIDSet(std::map< std::string, int > *uids)
const String & path() const
Returns the path of the file.
EError error() const
The last signaled error.
const String & documentURL() const
The URL of the document used to resolve document-relative file paths.
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...
Key/value pair used by VLXStructure.
Object * getImportedStructure(const VLXStructure *st)
void setInputFile(VirtualFile *file)
const std::string & tag() const
const char * errorString() const
std::vector< Value > & value()
The base class for all the reference counted objects.
std::map< TypeInfo, ref< VLXClassWrapper > > & exportRegistry()
Translates a VLX hierarchy into VLB format writing to the provided VirtualFile.
Object * importVLX(const VLXStructure *st)
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.
Wrapper for all VLX value types.
bool startsWith(const String &str) const
Returns true if a String starts with the specified String str.
VLXStructure * getExportedObject(const Object *obj)
virtual void acceptVisitor(VLXVisitor *v)
void signalImportError(const String &str)
bool saveVLT(const String &path, const Object *obj, bool start_fresh=true)
Base cass for all class wrappers implementing the translation to/from its VLX representation.
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
Translates a VLX hierarchy into VLT notation.
A VirtualFile that operates on regular disk files.
bool saveVLB(const String &path, const Object *obj, bool start_fresh=true)
void resolvePath(std::string &path)
If the given path starts with "this:" then the "this:" prefix is replaced with the documentURL()...
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.
A list of key/VLXValue pairs, can also have a tag.
VLTTokenizer * tokenizer()