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