36 typedef internal::gsXmlTree FileData;
37 typedef internal::gsXmlNode gsXmlNode;
38 typedef internal::gsXmlAttribute gsXmlAttribute;
39 typedef std::string String;
53 explicit gsFileData(String
const & fn,
bool recursive=
false);
63 bool read(String
const & fn,
bool recursive=
false) ;
74 void save(String
const & fname =
"dump",
bool compress =
false)
const;
83 void dump(String
const & fname =
"dump")
const;
85 void addComment(String
const & message);
91 String lastPath()
const {
return m_lastPath; }
108 std::list<std::vector<char> > m_buffer;
111 mutable String m_lastPath;
120 bool readXmlFile( String
const & fn,
bool recursive=
false);
123 bool readXmlGzFile( String
const & fn,
bool recursive=
false);
130 bool readAxelSurface( gsXmlNode * node );
131 bool readAxelCurve ( gsXmlNode * node );
132 bool readAxelMesh ( gsXmlNode * node );
164 bool readCsvFile(String
const & fn);
167 void ioError(
int lineNumber,
const String& str);
179 template<
class Object>
180 inline memory::unique_ptr<Object>
getId(
const int &
id)
const
186 template<
class Object>
187 inline void getId(
const int &
id, Object& result)
const
189 memory::unique_ptr<Object> obj = getId<Object>(
id);
194 template<
class Object>
195 inline memory::unique_ptr<Object>
getLabel(
const std::string & name)
const
201 template<
class Object>
202 inline void getLabel(
const std::string & name, Object& result)
const
204 memory::unique_ptr<Object> obj = getLabel<Object>(name);
209 template<
class Object>
211 {
return internal::gsXml<Object>::tag(); }
214 template<
class Object>
216 {
return internal::gsXml<Object>::type(); }
219 template<
class Object>
222 return getFirstNode( internal::gsXml<Object>::tag(),
223 internal::gsXml<Object>::type() ) != 0 ;
228 gsXmlNode* root = getXmlRoot();
236 gsXmlNode* root = getXmlRoot();
245 return getAnyFirstNode(
tag.c_str());
250 template<
class Object>
253 return getAnyFirstNode( internal::gsXml<Object>::tag(),
254 internal::gsXml<Object>::type() ) != 0 ;
258 template<
class Object>
262 for (gsXmlNode * child = getFirstNode( internal::gsXml<Object>::tag(),
263 internal::gsXml<Object>::type() ) ;
264 child; child = getNextSibling(child, internal::gsXml<Object>::tag(),
265 internal::gsXml<Object>::type() ))
272 template<
class Object>
275 this->add<Object>(obj);
279 template<
class Object>
280 void add (
const Object & obj,
int id = -1)
283 internal::gsXml<Object>::put(obj, *
data);
286 gsInfo<<
"gsFileData: Trouble inserting "<<internal::gsXml<Object>::tag()
287 <<
" to the XML tree. is \"put\" implemented ??\n";
291 data->appendToRoot(node,
id);
296 template<
class Object>
300 internal::gsXml<Object>::put(obj, *
data);
303 gsInfo<<
"gsFileData: Trouble inserting "<<internal::gsXml<Object>::tag()
304 <<
" to the XML tree. is \"put\" implemented ??\n";
308 data->appendToRoot(node,-1,label);
316 data->appendToRoot(node);
320 void addString (
const std::string & s,
const std::string & label)
324 data->appendToRoot(node);
332 void addInclude(
const std::string & filename,
const real_t & time=-1.,
333 const index_t &
id=-1,
const std::string & label=
"");
344 return getInclude(res,
id, -1.,
"");
352 return getInclude(res, -1,time,
"");
360 return getInclude(res, -1,-1.,label);
363 std::string getString ()
const
366 gsXmlNode * node = getFirstNode(
"string");
368 std::string res( node->value() );
372 std::string getString(
index_t id)
const
376 gsXmlNode * root = getXmlRoot();
380 std::string res(nd->value());
383 GISMO_ERROR(
"String with id " <<
id <<
" does not exist!");
386 std::string getStringByLabel (
const std::string & label)
const
390 gsXmlNode * root = getXmlRoot();
394 std::string res(nd->value());
397 GISMO_ERROR(
"String with label " << label <<
" does not exist!");
401 size_t bufferSize()
const {
return m_buffer.front().size(); };
404 std::ostream &
print(std::ostream &os)
const;
413 template<class Object>
414 bool operator>>(Object * obj)
416 gsWarn<< "getting "<< typeid(Object).name() <<"\n";
417 gsXmlNode* node = getFirstNode(internal::gsXml<Object>::tag(),
418 internal::gsXml<Object>::type() );
421 gsWarn<<"gsFileData: false!\n";
426 obj = internal::gsXml<Object>::get(node);
427 this->deleteXmlSubtree( node );
445 template<
class Object>
448 gsXmlNode* node = getFirstNode(internal::gsXml<Object>::tag(),
449 internal::gsXml<Object>::type() );
452 gsWarn<<
"gsFileData: getFirst: Didn't find any "<<
453 internal::gsXml<Object>::type()<<
" "<<
454 internal::gsXml<Object>::tag() <<
". Error.\n";
455 return memory::unique_ptr<Object>();
473 template<
class Object>
476 gsXmlNode* node = getFirstNode(internal::gsXml<Object>::tag(),
477 internal::gsXml<Object>::type() );
480 gsWarn<<
"gsFileData: getFirst: Didn't find any "<<
481 internal::gsXml<Object>::type()<<
" "<<
482 internal::gsXml<Object>::tag() <<
". Error.\n";
485 internal::gsXml<Object>::get_into(node, result);
490 template<
class Object>
491 inline std::vector< memory::unique_ptr<Object> >
getAll()
const
493 std::vector< memory::unique_ptr<Object> > result;
495 for (gsXmlNode * child = getFirstNode( internal::gsXml<Object>::tag(),
496 internal::gsXml<Object>::type() ) ;
497 child; child = getNextSibling(child, internal::gsXml<Object>::tag(),
498 internal::gsXml<Object>::type() ))
517 template<
class Object>
520 gsXmlNode* node = getAnyFirstNode(internal::gsXml<Object>::tag(),
521 internal::gsXml<Object>::type() );
524 gsWarn <<
"gsFileData: getAnyFirst: Didn't find any "<<
525 internal::gsXml<Object>::type()<<
" "<<
526 internal::gsXml<Object>::tag() <<
". Error.\n";
527 return memory::unique_ptr<Object>();
545 template<
class Object>
548 gsXmlNode* node = getAnyFirstNode(internal::gsXml<Object>::tag(),
549 internal::gsXml<Object>::type() );
552 gsWarn <<
"gsFileData: getAnyFirst: Didn't find any "<<
553 internal::gsXml<Object>::type()<<
" "<<
554 internal::gsXml<Object>::tag() <<
". Error.\n";
557 internal::gsXml<Object>::get_into(node, result);
569 gsXmlNode * getXmlRoot()
const;
570 static void deleteXmlSubtree (gsXmlNode* node);
573 gsXmlNode * getFirstNode (
const String & name =
"",
574 const String &
type =
"" )
const;
577 gsXmlNode * getAnyFirstNode(
const String & name =
"",
578 const String &
type =
"" )
const;
581 static gsXmlNode * getNextSibling( gsXmlNode*
const & node,
582 const String & name =
"",
583 const String &
type =
"" );
586 void addX3dShape(gsXmlNode * shape);
587 void addX3dTransform(gsXmlNode * shape);
593std::ostream &operator<<(std::ostream &os,
const gsFileData<T> & fd)
594{
return fd.print(os); }
596#ifdef GISMO_WITH_PYBIND11
601 void pybind11_init_gsFileData(pybind11::module &m);
607#ifndef GISMO_BUILD_LIB
609#include GISMO_HPP_HEADER(gsFileData.hpp)
This class represents an XML data tree which can be read from or written to a (file) stream.
Definition gsFileData.h:34
void writeIges(String const &fname)
Save multipatch contents to an IGES file.
void addInclude(const std::string &filename, const real_t &time=-1., const index_t &id=-1, const std::string &label="")
Add a reference ( <xmlfile> tag ) to another Gismo .xml file to the xml tree.
Definition gsFileData.hpp:296
memory::unique_ptr< Object > getId(const int &id) const
Searches and fetches the Gismo object with a given id.
Definition gsFileData.h:180
memory::unique_ptr< Object > getAnyFirst() const
Definition gsFileData.h:518
bool readObjFile(String const &fn)
Reads Wavefront OBJ file.
Definition gsFileData.hpp:1410
unsigned getFloatPrecision() const
Definition gsFileData.h:101
bool readIgesFile(String const &fn)
Reads Iges file.
Definition gsFileData.hpp:2149
bool readBrepFile(String const &fn)
Reads OpenCascade brep file.
Definition gsFileData.hpp:1694
String tag() const
Prints the XML tag of a Gismo object.
Definition gsFileData.h:210
void addWithLabel(const Object &obj, std::string label)
Add the object to the Xml tree, same as <<, but also allows to set the XML label attribute.
Definition gsFileData.h:297
void saveCompressed(String const &fname="dump") const
Save file contents to compressed xml file.
Definition gsFileData.hpp:131
void getLabel(const std::string &name, Object &result) const
Searches and fetches the Gismo object with a given label.
Definition gsFileData.h:202
bool readGoToolsFile(String const &fn)
Reads GoTools file.
Definition gsFileData.hpp:511
int count() const
Counts the number of Objects in the filedata.
Definition gsFileData.h:259
void operator<<(const Object &obj)
Inserts an object to the XML tree.
Definition gsFileData.h:273
FileData * data
File data as an xml tree.
Definition gsFileData.h:105
bool readStlFile(String const &fn)
Reads STL mesh file.
Definition gsFileData.hpp:1327
bool readXmlFile(String const &fn, bool recursive=false)
Reads a file with xml extension.
Definition gsFileData.hpp:229
void getId(const int &id, Object &result) const
Searches and fetches the Gismo object with a given id.
Definition gsFileData.h:187
bool hasLabel(std::string label) const
Returns true if an Object with such label exists in the filedata.
Definition gsFileData.h:235
int numTags() const
Counts the number of Objects/tags in the filedata.
Definition gsFileData.hpp:2602
bool read3dmFile(String const &fn)
Reads 3DM file.
Definition gsFileData.hpp:2527
String contents() const
Lists the contents of the filedata.
Definition gsFileData.hpp:2583
size_t bufferSize() const
Returns the size of the data.
Definition gsFileData.h:401
void setFloatPrecision(const unsigned k)
Definition gsFileData.h:96
void getIncludeById(gsFileData &res, index_t id)
Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gs...
Definition gsFileData.h:342
bool hasTag(std::string tag) const
Returns true if an entry of tag exists in the xml file.
Definition gsFileData.h:243
std::vector< memory::unique_ptr< Object > > getAll() const
Returns a vector with all Objects found in the XML data.
Definition gsFileData.h:491
bool getFirst(Object &result) const
Definition gsFileData.h:474
bool readGeompFile(String const &fn)
Reads GeoPDEs txt file.
Definition gsFileData.hpp:882
void save(String const &fname="dump", bool compress=false) const
Save file contents to an xml file.
Definition gsFileData.hpp:98
void addString(const std::string &s, const std::string &label)
Add a string to the Xml tree.
Definition gsFileData.h:320
void addString(const std::string &s)
Add a string to the Xml tree.
Definition gsFileData.h:313
bool readGismoXmlStream(std::istream &is, bool recursive=false)
Reads Gismo's native XML file.
Definition gsFileData.hpp:252
bool getAnyFirst(Object &result) const
Definition gsFileData.h:546
memory::unique_ptr< Object > getLabel(const std::string &name) const
Searches and fetches a poitner to a Gismo object with a given label.
Definition gsFileData.h:195
bool readX3dFile(String const &fn)
Reads X3D file.
Definition gsFileData.hpp:2460
memory::unique_ptr< Object > getFirst() const
Definition gsFileData.h:446
bool hasId(int id) const
Returns true if an Object exists in the filedata.
Definition gsFileData.h:227
void clear()
Clear all data.
Definition gsFileData.hpp:69
bool readXmlGzFile(String const &fn, bool recursive=false)
Reads a file with xml.gz extension.
Definition gsFileData.hpp:240
bool read(String const &fn, bool recursive=false)
Definition gsFileData.hpp:162
bool readOffFile(String const &fn)
Reads Off mesh file.
Definition gsFileData.hpp:1259
std::ostream & print(std::ostream &os) const
Prints the XML data as a string.
Definition gsFileData.hpp:77
bool readAxelFile(String const &fn)
Reads Axel file.
Definition gsFileData.hpp:349
bool readParasolidFile(String const &fn)
Reads parasolid files.
Definition gsFileData.hpp:2539
String type() const
Prints the XML tag type of a Gismo object.
Definition gsFileData.h:215
void getIncludeByTime(gsFileData &res, real_t time)
Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gs...
Definition gsFileData.h:350
void dump(String const &fname="dump") const
Dump file contents to an xml file.
Definition gsFileData.hpp:86
bool has() const
Returns true if an Object exists in the filedata.
Definition gsFileData.h:220
void getIncludeByLabel(gsFileData &res, std::string label)
Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gs...
Definition gsFileData.h:358
bool hasAny() const
Definition gsFileData.h:251
void add(const Object &obj, int id=-1)
Add the object to the Xml tree, same as <<, but also allows to set the XML id and label attributes.
Definition gsFileData.h:280
int numData() const
Reports the number of objects which are held in the file data.
Definition gsFileData.h:71
A fixed-size, statically allocated 3D vector.
Definition gsVector.h:219
#define index_t
Definition gsConfig.h:32
#define GISMO_ERROR(message)
Definition gsDebug.h:118
#define gsWarn
Definition gsDebug.h:50
#define gsInfo
Definition gsDebug.h:43
Utility class for finding files and handling paths.
Provides declaration of input/output XML utilities struct.
gsXmlNode * searchLabel(const std::string label, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition gsXml.h:273
gsXmlNode * searchNode(gsXmlNode *root, const std::string &attr_name, const std::string &value, const char *tag_name=NULL)
Definition gsXml.h:231
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition gsXml.cpp:54
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition gsXml.cpp:37
gsXmlNode * searchId(const int id, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition gsXml.h:254
unique_ptr< T > make_unique(T *x)
Definition gsMemory.h:198
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266