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();
237 return getAnyFirstNode(tag.c_str());
242 template<
class Object>
245 return getAnyFirstNode( internal::gsXml<Object>::tag(),
246 internal::gsXml<Object>::type() ) != 0 ;
250 template<
class Object>
254 for (gsXmlNode * child = getFirstNode( internal::gsXml<Object>::tag(),
255 internal::gsXml<Object>::type() ) ;
256 child; child = getNextSibling(child, internal::gsXml<Object>::tag(),
257 internal::gsXml<Object>::type() ))
264 template<
class Object>
267 this->add<Object>(obj);
271 template<
class Object>
272 void add (
const Object & obj,
int id = -1)
275 internal::gsXml<Object>::put(obj, *
data);
278 gsInfo<<
"gsFileData: Trouble inserting "<<internal::gsXml<Object>::tag()
279 <<
" to the XML tree. is \"put\" implemented ??\n";
283 data->appendToRoot(node,
id);
288 template<
class Object>
292 internal::gsXml<Object>::put(obj, *
data);
295 gsInfo<<
"gsFileData: Trouble inserting "<<internal::gsXml<Object>::tag()
296 <<
" to the XML tree. is \"put\" implemented ??\n";
300 data->appendToRoot(node,-1,label);
308 data->appendToRoot(node);
312 void addString (
const std::string & s,
const std::string & label)
316 data->appendToRoot(node);
324 void addInclude(
const std::string & filename,
const real_t & time=-1.,
325 const index_t &
id=-1,
const std::string & label=
"");
336 return getInclude(res,
id, -1.,
"");
344 return getInclude(res, -1,time,
"");
352 return getInclude(res, -1,-1.,label);
355 std::string getString ()
const
358 gsXmlNode * node = getFirstNode(
"string");
360 std::string res( node->value() );
364 std::string getString(
index_t id)
const
368 gsXmlNode * root = getXmlRoot();
372 std::string res(nd->value());
375 GISMO_ERROR(
"String with id " <<
id <<
" does not exist!");
378 std::string getStringByLabel (
const std::string & label)
const
382 gsXmlNode * root = getXmlRoot();
386 std::string res(nd->value());
389 GISMO_ERROR(
"String with label " << label <<
" does not exist!");
393 size_t bufferSize()
const {
return m_buffer.front().size(); };
396 std::ostream &
print(std::ostream &os)
const;
437 template<
class Object>
440 gsXmlNode* node = getFirstNode(internal::gsXml<Object>::tag(),
441 internal::gsXml<Object>::type() );
444 gsWarn<<
"gsFileData: getFirst: Didn't find any "<<
445 internal::gsXml<Object>::type()<<
" "<<
446 internal::gsXml<Object>::tag() <<
". Error.\n";
447 return memory::unique_ptr<Object>();
465 template<
class Object>
468 gsXmlNode* node = getFirstNode(internal::gsXml<Object>::tag(),
469 internal::gsXml<Object>::type() );
472 gsWarn<<
"gsFileData: getFirst: Didn't find any "<<
473 internal::gsXml<Object>::type()<<
" "<<
474 internal::gsXml<Object>::tag() <<
". Error.\n";
477 internal::gsXml<Object>::get_into(node, result);
482 template<
class Object>
483 inline std::vector< memory::unique_ptr<Object> >
getAll()
const
485 std::vector< memory::unique_ptr<Object> > result;
487 for (gsXmlNode * child = getFirstNode( internal::gsXml<Object>::tag(),
488 internal::gsXml<Object>::type() ) ;
489 child; child = getNextSibling(child, internal::gsXml<Object>::tag(),
490 internal::gsXml<Object>::type() ))
509 template<
class Object>
512 gsXmlNode* node = getAnyFirstNode(internal::gsXml<Object>::tag(),
513 internal::gsXml<Object>::type() );
516 gsWarn <<
"gsFileData: getAnyFirst: Didn't find any "<<
517 internal::gsXml<Object>::type()<<
" "<<
518 internal::gsXml<Object>::tag() <<
". Error.\n";
519 return memory::unique_ptr<Object>();
537 template<
class Object>
540 gsXmlNode* node = getAnyFirstNode(internal::gsXml<Object>::tag(),
541 internal::gsXml<Object>::type() );
544 gsWarn <<
"gsFileData: getAnyFirst: Didn't find any "<<
545 internal::gsXml<Object>::type()<<
" "<<
546 internal::gsXml<Object>::tag() <<
". Error.\n";
549 internal::gsXml<Object>::get_into(node, result);
561 gsXmlNode * getXmlRoot()
const;
562 static void deleteXmlSubtree (gsXmlNode* node);
565 gsXmlNode * getFirstNode (
const String & name =
"",
566 const String &
type =
"" )
const;
569 gsXmlNode * getAnyFirstNode(
const String & name =
"",
570 const String &
type =
"" )
const;
573 static gsXmlNode * getNextSibling( gsXmlNode*
const & node,
574 const String & name =
"",
575 const String &
type =
"" );
578 void addX3dShape(gsXmlNode * shape);
579 void addX3dTransform(gsXmlNode * shape);
585 std::ostream &operator<<(std::ostream &os, const gsFileData<T> & fd)
586 {
return fd.print(os); }
588 #ifdef GISMO_WITH_PYBIND11
593 void pybind11_init_gsFileData(pybind11::module &m);
595 #endif // GISMO_WITH_PYBIND11
599 #ifndef GISMO_BUILD_LIB
601 #include GISMO_HPP_HEADER(gsFileData.hpp)
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:289
unique_ptr< T > make_unique(T *x)
Definition: gsMemory.h:198
void addString(const std::string &s, const std::string &label)
Add a string to the Xml tree.
Definition: gsFileData.h:312
A fixed-size, statically allocated 3D vector.
Definition: gsVector.h:218
unsigned getFloatPrecision() const
Definition: gsFileData.h:101
bool readStlFile(String const &fn)
Reads STL mesh file.
Definition: gsFileData.hpp:1327
String tag() const
Prints the XML tag of a Gismo object.
Definition: gsFileData.h:210
bool readParasolidFile(String const &fn)
Reads parasolid files.
Definition: gsFileData.hpp:2539
void addString(const std::string &s)
Add a string to the Xml tree.
Definition: gsFileData.h:305
bool has() const
Returns true if an Object exists in the filedata.
Definition: gsFileData.h:220
bool getFirst(Object &result) const
Definition: gsFileData.h:466
memory::unique_ptr< Object > getId(const int &id) const
Searches and fetches the Gismo object with a given id.
Definition: gsFileData.h:180
bool hasTag(std::string tag) const
Returns true if an entry of tag exists in the xml file.
Definition: gsFileData.h:235
void saveCompressed(String const &fname="dump") const
Save file contents to compressed xml file.
Definition: gsFileData.hpp:131
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
size_t bufferSize() const
Returns the size of the data.
Definition: gsFileData.h:393
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:272
gsXmlNode * searchId(const int id, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition: gsXml.h:254
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:334
int numTags() const
Counts the number of Objects/tags in the filedata.
Definition: gsFileData.hpp:2602
bool readXmlGzFile(String const &fn, bool recursive=false)
Reads a file with xml.gz extension.
Definition: gsFileData.hpp:240
bool getAnyFirst(Object &result) const
Definition: gsFileData.h:538
gsXmlNode * searchNode(gsXmlNode *root, const std::string &attr_name, const std::string &value, const char *tag_name=NULL)
Definition: gsXml.h:231
void operator<<(const Object &obj)
Inserts an object to the XML tree.
Definition: gsFileData.h:265
bool readOffFile(String const &fn)
Reads Off mesh file.
Definition: gsFileData.hpp:1259
bool readGismoXmlStream(std::istream &is, bool recursive=false)
Reads Gismo's native XML file.
Definition: gsFileData.hpp:252
#define gsWarn
Definition: gsDebug.h:50
String contents() const
Lists the contents of the filedata.
Definition: gsFileData.hpp:2583
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:342
bool hasAny() const
Definition: gsFileData.h:243
bool readObjFile(String const &fn)
Reads Wavefront OBJ file.
Definition: gsFileData.hpp:1410
bool read(String const &fn, bool recursive=false)
Definition: gsFileData.hpp:162
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
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
#define gsInfo
Definition: gsDebug.h:43
memory::unique_ptr< Object > getAnyFirst() const
Definition: gsFileData.h:510
bool readIgesFile(String const &fn)
Reads Iges file.
Definition: gsFileData.hpp:2149
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 readAxelFile(String const &fn)
Reads Axel file.
Definition: gsFileData.hpp:349
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
int numData() const
Reports the number of objects which are held in the file data.
Definition: gsFileData.h:71
void dump(String const &fname="dump") const
Dump file contents to an xml file.
Definition: gsFileData.hpp:86
bool hasId(int id) const
Returns true if an Object exists in the filedata.
Definition: gsFileData.h:227
std::vector< memory::unique_ptr< Object > > getAll() const
Returns a vector with all Objects found in the XML data.
Definition: gsFileData.h:483
String type() const
Prints the XML tag type of a Gismo object.
Definition: gsFileData.h:215
bool readGeompFile(String const &fn)
Reads GeoPDEs txt file.
Definition: gsFileData.hpp:882
memory::unique_ptr< Object > getFirst() const
Definition: gsFileData.h:438
FileData * data
File data as an xml tree.
Definition: gsFileData.h:105
int count() const
Counts the number of Objects in the filedata.
Definition: gsFileData.h:251
void getLabel(const std::string &name, Object &result) const
Searches and fetches the Gismo object with a given label.
Definition: gsFileData.h:202
void clear()
Clear all data.
Definition: gsFileData.hpp:69
bool read3dmFile(String const &fn)
Reads 3DM file.
Definition: gsFileData.hpp:2527
bool readX3dFile(String const &fn)
Reads X3D file.
Definition: gsFileData.hpp:2460
Utility class for finding files and handling paths.
EIGEN_STRONG_INLINE idMat_expr id(const index_t dim)
The identity matrix of dimension dim.
Definition: gsExpressions.h:4472
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
bool readGoToolsFile(String const &fn)
Reads GoTools file.
Definition: gsFileData.hpp:511
This class represents an XML data tree which can be read from or written to a (file) stream...
Definition: gsFileData.h:33
void save(String const &fname="dump", bool compress=false) const
Save file contents to an xml file.
Definition: gsFileData.hpp:98
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:350
bool readBrepFile(String const &fn)
Reads OpenCascade brep file.
Definition: gsFileData.hpp:1694
Provides declaration of input/output XML utilities struct.
bool readXmlFile(String const &fn, bool recursive=false)
Reads a file with xml extension.
Definition: gsFileData.hpp:229
std::ostream & print(std::ostream &os) const
Prints the XML data as a string.
Definition: gsFileData.hpp:77
void setFloatPrecision(const unsigned k)
Definition: gsFileData.h:96
void getId(const int &id, Object &result) const
Searches and fetches the Gismo object with a given id.
Definition: gsFileData.h:187