HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_DataBlock.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: OP_DataBlock.h (OP Library, C++)
7  *
8  * COMMENTS: Simple class for holding a chunk of arbitrary binary data
9  * owned by a node.
10  */
11 
12 #ifndef __OP_DATABLOCK_H_INCLUDED__
13 #define __OP_DATABLOCK_H_INCLUDED__
14 
15 #include "OP_API.h"
16 #include <UT/UT_IntrusivePtr.h>
17 #include <UT/UT_StringHolder.h>
18 #include <iosfwd>
19 
20 class UT_IStream;
21 
23 {
24 public:
26  virtual ~OP_DataBlockInterpreter();
27 
28  virtual const void *createNativeData(const char *data,
29  exint length) const = 0;
30  virtual exint memoryUsedByNativeData(
31  const void *nativedata) const = 0;
32  virtual void deleteNativeData(const void *nativedata) const = 0;
33  virtual void saveNativeData(const void *nativedata,
34  std::ostream &os) const = 0;
35 
36 private:
37  UT_StringHolder myType;
38 };
39 
40 class OP_API OP_DataBlock : public UT_IntrusiveRefCounter<OP_DataBlock>
41 {
42 public:
44  ~OP_DataBlock();
45 
46  static const OP_DataBlockInterpreter *
47  getInterpreter(const UT_StringRef &blocktype);
48 
49  const UT_StringHolder &type() const
50  { return myType; }
51  const char *data() const
52  { return myData; }
53  exint length() const
54  { return myLength; }
55  exint getMemoryUsage() const;
56 
57  const void *nativeData();
58  void adoptData(const char *data, exint length);
59  void adoptNativeData(const void *nativedata);
60  bool saveData(std::ostream &os) const;
61  bool loadData(UT_IStream &is);
62 
63 private:
64  void deleteData();
65  void deleteNativeData();
66 
67  const UT_StringHolder myType;
68  const char *myData;
69  exint myLength;
70  const void *myNativeData;
71  bool myNativeDataIsValid;
72 };
73 
74 #endif // __OP_DATABLOCK_H_INCLUDED__
int64 exint
Definition: SYS_Types.h:125
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
A reference counter base class for use with UT_IntrusivePtr.
exint length() const
Definition: OP_DataBlock.h:53
const char * data() const
Definition: OP_DataBlock.h:51
const UT_StringHolder & type() const
Definition: OP_DataBlock.h:49
#define OP_API
Definition: OP_API.h:10
type
Definition: core.h:1059
Definition: format.h:895