HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_IOTranslator.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Geometry Conversion Utility Library (C++)
7  *
8  * COMMENTS:
9  * This is the base class for all conversion types.
10  *
11  */
12 
13 #ifndef __GEO_IOTranslator_h__
14 #define __GEO_IOTranslator_h__
15 
16 #include "GEO_API.h"
17 #include <iosfwd>
18 #include <GA/GA_Detail.h>
19 #include <UT/UT_StringMap.h>
20 
21 class GEO_Detail;
22 class UT_IStream;
23 
25 {
26 public:
27  /// Define a map where the key is the IOTranslator format name and the
28  /// value is the DSO file defining the translator. Built-in translators
29  /// don't appear in this list.
31 
33  virtual ~GEO_IOTranslator();
34 
35  /// This method is used to create a copy of the sub-class
36  virtual GEO_IOTranslator * duplicate() const = 0;
37 
38  /// Returns the label for the geometry format that this
39  /// translator supports.
40  virtual const char * formatName() const = 0;
41 
42  /// Method to check the extension of the name to see if it matches one that
43  /// we can handle. Returns true if there's a match
44  virtual int checkExtension(const char *name) = 0;
45 
46  /// Method to return a list of the file extensions matched by this
47  /// translator. The strings should contain the extensions (with dots).
48  /// For exmple [".eps", ".ai"]. The default method returns nothing.
49  virtual void getFileExtensions(UT_StringArray &extensions) const;
50 
51  /// Method to check if the given magic number matches the magic number.
52  /// Return true on a match.
53  virtual int checkMagicNumber(unsigned magic) = 0;
54 
55  /// Method to "stat" a file. If possible, stat shouldn't have to load the
56  /// entire geometry.
57  virtual bool fileStat(const char *filename,
58  GA_Stat &stat,
59  uint level);
60 
61  /// Method to load from a stream. If the ate_magic flag is on, then the
62  /// library has already read the magic number and the loader should
63  /// not expect it.
64  /// If the file format doesn't support reading from streams, it
65  /// can use UT_IStream::isRandomAccessFile to get the raw name
66  /// to read from.
67  /// Return false if this translator doesn't support loading.
68  virtual GA_Detail::IOStatus fileLoad(GEO_Detail *gdp,
69  UT_IStream &is,
70  bool ate_magic) = 0;
71 
72  /// Method to save a gdp to another format. Return false if this translator
73  /// does not support saving.
74  virtual GA_Detail::IOStatus fileSave(const GEO_Detail *gdp,
75  std::ostream &os) = 0;
76 
77  /// Method to save a gdp to another format via a filename. Return false if
78  /// this translator does not support saving.
79  ///
80  /// This is an optional method. By default, it will create a stream and
81  /// call the streaming version of fileSave().
82  virtual GA_Detail::IOStatus fileSaveToFile(const GEO_Detail *gdp,
83  const char *filename);
84 
85  /// @private
86  /// Due to the library hierarchy, it isn't possible to implement a default
87  /// stat method (i.e. load the file and stat) at the GEO level (since
88  /// GEO_Detail is pure virtual). A higher library is responsible for
89  /// setting the default stat method.
90  class GEO_API DefaultStatFunction
91  {
92  public:
93  DefaultStatFunction();
94  virtual ~DefaultStatFunction();
95  virtual bool stat(GEO_IOTranslator &io,
96  const char *filename,
97  GA_Stat &stat,
98  uint level) const = 0;
99  virtual bool statJSON(UT_IStream &is,
100  GA_Stat &stat,
101  uint level) const = 0;
102  };
103  /// @private
104  /// The stat functor must stay as a persistent object (ownership is not
105  /// maintained by this class).
106  static void setDefaultStat(DefaultStatFunction *func)
107  { theDefaultStat = func; }
108 
109  /// Return the list of DSO based translators
110  static const geo_DSODefinitions &dsoDefinitions();
111 
112  /// @{
113  /// @private
114  void addDSODefinition();
115  void eraseDSODefinition();
116  /// @}
117 
118 protected:
119  /// Stat a .bgeo JSON stream
120  bool statJSONStream(UT_IStream &is, GA_Stat &stat, uint level) const;
121 
122 private:
123  static DefaultStatFunction *theDefaultStat;
124 };
125 
126 #endif
GT_API const UT_StringHolder filename
GLuint const GLchar * name
Definition: glew.h:1814
#define GEO_API
Definition: GEO_API.h:14
Class to return information about a GA_Detail.
Definition: GA_Stat.h:50
GLenum func
Definition: glcorearb.h:782
UT_StringMap< UT_StringHolder > geo_DSODefinitions
unsigned int uint
Definition: SYS_Types.h:45
GLint level
Definition: glew.h:1252