G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFileData< T > Class Template Reference

Detailed Description

template<class T>
class gismo::gsFileData< T >

This class represents an XML data tree which can be read from or written to a (file) stream.

Public Member Functions

template<class Object >
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.
 
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. More...
 
void addString (const std::string &s)
 Add a string to the Xml tree.
 
void addString (const std::string &s, const std::string &label)
 Add a string to the Xml tree.
 
template<class Object >
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.
 
size_t bufferSize () const
 Returns the size of the data.
 
void clear ()
 Clear all data.
 
String contents () const
 Lists the contents of the filedata.
 
template<class Object >
int count () const
 Counts the number of Objects in the filedata.
 
void dump (String const &fname="dump") const
 Dump file contents to an xml file.
 
template<class Object >
std::vector
< memory::unique_ptr< Object > > 
getAll () const
 Returns a vector with all Objects found in the XML data.
 
template<class Object >
memory::unique_ptr< Object > getAnyFirst () const
 
template<class Object >
bool getAnyFirst (Object &result) const
 
template<class Object >
memory::unique_ptr< Object > getFirst () const
 
template<class Object >
bool getFirst (Object &result) const
 
unsigned getFloatPrecision () const
 
template<class Object >
memory::unique_ptr< Object > getId (const int &id) const
 Searches and fetches the Gismo object with a given id.
 
template<class Object >
void getId (const int &id, Object &result) const
 Searches and fetches the Gismo object with a given id.
 
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 gsFileData res object. More...
 
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 gsFileData res object. More...
 
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 gsFileData res object. More...
 
template<class Object >
memory::unique_ptr< Object > getLabel (const std::string &name) const
 Searches and fetches a poitner to a Gismo object with a given label.
 
template<class Object >
void getLabel (const std::string &name, Object &result) const
 Searches and fetches the Gismo object with a given label.
 
 gsFileData (String const &fn, bool recursive=false)
 
template<class Object >
bool has () const
 Returns true if an Object exists in the filedata.
 
template<class Object >
bool hasAny () const
 
bool hasId (int id) const
 Returns true if an Object exists in the filedata.
 
bool hasTag (std::string tag) const
 Returns true if an entry of tag exists in the xml file.
 
int numData () const
 Reports the number of objects which are held in the file data.
 
int numTags () const
 Counts the number of Objects/tags in the filedata.
 
template<class Object >
void operator<< (const Object &obj)
 Inserts an object to the XML tree.
 
std::ostream & print (std::ostream &os) const
 Prints the XML data as a string.
 
bool read (String const &fn, bool recursive=false)
 
void save (String const &fname="dump", bool compress=false) const
 Save file contents to an xml file.
 
void saveCompressed (String const &fname="dump") const
 Save file contents to compressed xml file.
 
void setFloatPrecision (const unsigned k)
 
template<class Object >
String tag () const
 Prints the XML tag of a Gismo object.
 
template<class Object >
String type () const
 Prints the XML tag type of a Gismo object.
 
void writeIges (String const &fname)
 Save multipatch contents to an IGES file.
 

Protected Member Functions

bool read3dmFile (String const &fn)
 Reads 3DM file.
 
bool readAxelFile (String const &fn)
 Reads Axel file.
 
bool readBrepFile (String const &fn)
 Reads OpenCascade brep file.
 
bool readGeompFile (String const &fn)
 Reads GeoPDEs txt file.
 
bool readGismoXmlStream (std::istream &is, bool recursive=false)
 Reads Gismo's native XML file.
 
bool readGoToolsFile (String const &fn)
 Reads GoTools file.
 
bool readIgesFile (String const &fn)
 Reads Iges file.
 
bool readObjFile (String const &fn)
 Reads Wavefront OBJ file.
 
bool readOffFile (String const &fn)
 Reads Off mesh file.
 
bool readParasolidFile (String const &fn)
 Reads parasolid files.
 
bool readStlFile (String const &fn)
 Reads STL mesh file.
 
bool readX3dFile (String const &fn)
 Reads X3D file.
 
bool readXmlFile (String const &fn, bool recursive=false)
 Reads a file with xml extension.
 
bool readXmlGzFile (String const &fn, bool recursive=false)
 Reads a file with xml.gz extension.
 

Private Attributes

FileData * data
 File data as an xml tree.
 

Constructor & Destructor Documentation

gsFileData ( String const &  fn,
bool  recursive = false 
)
explicit

Initializes a gsFileData object with the contents of a file

Parameters
fnfilename string
recursiveif true, then all referenced xml files will be read as one gsFileData object recursively

Member Function Documentation

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.

Parameters
filenameThe path of the referenced file, relative to the path of the current file
timefor time series data, optional
idInteger for identification purposes, optional
labelString for identification purposes, optional
memory::unique_ptr<Object> getAnyFirst ( ) const
inline

Returns the first Object found in the XML data as uPtr. Look also for nested objects. Value of uPtr is null if nothing was found.

gsFunctionExpr<>::uPtr expr;
if (expr = getFirst< gsFunctionExpr<> >())
gsInfo << expr;
Template Parameters
ObjectType of object.
Returns
An uPtr with the object inside, or null inside if no object was found.
bool getAnyFirst ( Object &  result) const
inline

Returns the first object of this type found in the XML data. Look also for nested objects. Writes it into the parameter.

gsMultiPatch<> mp;
if(getFirst(mp))
gsInfo << mp;
Template Parameters
ObjectType of object.
Parameters
resultObject read into.
Returns
True if result has been found, false if result was not found.
memory::unique_ptr<Object> getFirst ( ) const
inline

Returns the first Object found in the XML data as uPtr. Doesn't look for nested objects. Value of uPtr is null if nothing was found.

gsFunctionExpr<>::uPtr expr;
if (expr = getFirst< gsFunctionExpr<> >())
gsInfo << expr;
Template Parameters
ObjectType of object.
Returns
An uPtr with the object inside, or null inside if no object was found.
bool getFirst ( Object &  result) const
inline

Returns the first object of this type found in the XML data. Doesn't look for nested objects. Writes it into the parameter.

gsMultiPatch<> mp;
if(getFirst(mp))
gsInfo << mp;
Template Parameters
ObjectType of object.
Parameters
resultObject read into.
Returns
True if result has been found, false if result was not found.
unsigned getFloatPrecision ( ) const
inline

Returns the precision (number of decimals) used for writing floats to output files. 8 digits reflects to a 32-bit float, while 16 reflects to a 64-bit double.

void getIncludeById ( gsFileData< T > &  res,
index_t  id 
)
inline

Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gsFileData res object.

Parameters
resThe gsFileData object where the referenced file will be loaded into
idIndex of the <xmlfile> node
void getIncludeByLabel ( gsFileData< T > &  res,
std::string  label 
)
inline

Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gsFileData res object.

Parameters
resThe gsFileData object where the referenced file will be loaded into
labelLabel of the <xmlfile> node
void getIncludeByTime ( gsFileData< T > &  res,
real_t  time 
)
inline

Looks for a referenced Gismo .xml file ( <xmlfile> tag ) in the current xml tree, parses it in the gsFileData res object.

Parameters
resThe gsFileData object where the referenced file will be loaded into
timeTime attribute of the <xmlfile> node
bool hasAny ( ) const
inline

Returns true if an Object exists in the filedata, even nested inside other objects

bool read ( String const &  fn,
bool  recursive = false 
)

Loads the contents of a file into a gsFileData object

Parameters
fnfilename string
recursiveif true, then all referenced xml files will be read as one gsFileData object recursively

Returns true on success, false on failure.

void setFloatPrecision ( const unsigned  k)
inline

Set the precision (number of decimals) used for writing floats to output files. A 32-bit float has a precision of about 8 digits. A 64-bit double has a precision of about 16.