Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXObjPack.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cXObjPack_H
7 #define _INC_cXObjPack_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../XObject/cXObjMgr.h" // cXObjTypeDef
13 #include "../XObject/cXObjDef.h"
14 #include "GrayCore/include/cFileDir.h" // cFileStatus
15 
16 namespace GrayLib
17 {
18  class cXObjEventSink;
19  class cXObjPackChild;
20  class cXObjPackFactory;
21 
23  {
27  };
28 
30  {
41 
42  typedef cXObjDef SUPER_t;
44 
45  public:
46  static const ATOMCHAR_t k_szSymNamePrefix[];
47  static const XOBJTID_t k_XObjTypeId = MAKEFOURCC('P', 'a', 'k', 'g'); // cXObjTypeDef for all file packages.
48  static cXObjTypeDef sm_XObjTypeDef; // for k_XObjTypeId
49 
50  // Last time it was closed. What did the file params look like ?
53  bool m_bDisabled;
55 
56  protected:
57  // List of all my cXObjDef children ? if any.
58  // These must be reloaded or deleted if the file changes.
60 
61  private:
62  void Init();
63 
64  protected:
65  cXObjPack(cStringF sFilePath, cXObjPackFactory* pFactory);
66 
67  public:
68  virtual ~cXObjPack();
69 
70  virtual cStringF get_FilePath() const
71  {
73  return m_sFilePath;
74  }
75  virtual cString get_Description() const override
76  {
77  return m_sFilePath;
78  }
79  STDMETHOD_(XOBJTID_t, get_XObjTypeId)() const override
80  {
81  return k_XObjTypeId;
82  }
83 
84  static cStringA GRAYCALL MakeSymNameFromPath(const FILECHAR_t* pszFilePath);
85 
86  HRESULT CheckForChange();
87 
88  virtual HRESULT DisposeThis() override;
89  virtual void UnloadXObject() override;
90 
92  virtual HRESULT LoadXObjPack(IXObject* pRoot = nullptr)
93  {
96  return S_FALSE;
97  }
98 
99  // used inside LoadXObjPack() to register each child object.
100  HRESULT RegisterChildDef(cXObjDef* pChildDef);
101  bool UnregisterChildDef(cXObjDef* pChildDef);
102 
103  // call a method by name in the file. File type dictates the exact format of the call.
104  virtual HRESULT InvokeMethodInt(cXObjPackChild* pEventSink, const ATOMCHAR_t* pszMethod, const cVariant& vArgs, cVariant& vValRet);
105  };
106 
108 
110  {
115  public:
117  public:
118  // overload this for the file types we might see.
120  : m_pszFileExt(pszExt)
121  {
122  ASSERT(pszExt != nullptr);
123  }
125  {
126  }
127 
128  bool IsFileExt(const FILECHAR_t* pszExt) const
129  {
131  ASSERT(m_pszFileExt != nullptr);
132  ASSERT(pszExt != nullptr);
133  // pszExt = cFilePath::GetFileNameExt(pszExt);
134  return(!StrT::CmpI(m_pszFileExt, pszExt));
135  }
136 
137  // First pass is just to enumerate the file. Create a tracking object for it.
138  // The cXObjPack parent class handles more specific loading.
139  virtual cXObjPackPtr CreateXObjFile(const FILECHAR_t* pszFilePath) = 0;
140  };
141 }
142 
143 #ifdef GRAY_DLL // force implementation/instantiate for DLL/SO.
144 namespace Gray
145 {
146  template class GRAYLIB_LINK cArrayRef<GrayLib::cXObjDef>;
147  template class GRAYLIB_LINK cRefPtr<GrayLib::cXObjPack>;
148  template class GRAYLIB_LINK cArrayPtr<GrayLib::cXObjPackFactory>;
149 }
150 #endif
151 
152 #endif // cXObjPack
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define MAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: cFourCC.h:24
#define CHEAPOBJECT_IMPL
Definition: cHeapObject.h:32
Definition: cVariant.h:26
Definition: cXObjDef.h:17
Definition: cXObjPackChild.h:18
Definition: cXObjPack.h:110
const FILECHAR_t * m_pszFileExt
What file extension are we supporting? i.e. MIME_EXT_scp, etc (includes dot).
Definition: cXObjPack.h:116
cXObjPackFactory(const FILECHAR_t *pszExt)
Definition: cXObjPack.h:119
virtual cXObjPackPtr CreateXObjFile(const FILECHAR_t *pszFilePath)=0
bool IsFileExt(const FILECHAR_t *pszExt) const
Definition: cXObjPack.h:128
virtual ~cXObjPackFactory()
Definition: cXObjPack.h:124
Definition: cXObjPack.h:30
virtual cString get_Description() const override
Definition: cXObjPack.h:75
bool m_bDisabled
disable all stuff from this file. for debug.
Definition: cXObjPack.h:53
cFileStatus m_Attr
Compare to see if this has changed.
Definition: cXObjPack.h:51
STDMETHOD_(XOBJTID_t, get_XObjTypeId)() const override
Definition: cXObjPack.h:79
cStringF m_sFilePath
full file path.
Definition: cXObjPack.h:52
static cXObjTypeDef sm_XObjTypeDef
Definition: cXObjPack.h:48
cArrayRef< cXObjDef > m_aLinkedChildren
usually cXObjDef is cXObjPackChild.
Definition: cXObjPack.h:59
virtual HRESULT LoadXObjPack(IXObject *pRoot=nullptr)
Check cached open of this file. check if it should be closed?
Definition: cXObjPack.h:92
cXObjPackFactory * m_pFactory
factory for this type of file.
Definition: cXObjPack.h:54
virtual cStringF get_FilePath() const
Definition: cXObjPack.h:70
Definition: cXObjMgr.h:92
Definition: cXObject.h:78
Definition: cArrayRef.h:21
Definition: cFileStatus.h:58
Definition: IXObject.h:46
Definition: cMesh.h:22
FOURCC XOBJTID_t
a unique FOURCC id for a type of XObject, 0=k_XOBJTID_NULL, MAKEFOURCC(a,b,c,d). Equiv to GUID for IU...
Definition: IXObject.h:42
cRefPtr< cXObjPack > cXObjPackPtr
Definition: cXObjPack.h:107
CXOBJFILE_CHANGE_TYPE
Definition: cXObjPack.h:23
@ CXOBJFILE_CHANGE_Changed
Definition: cXObjPack.h:26
@ CXOBJFILE_CHANGE_First
first time loading this.
Definition: cXObjPack.h:25
@ CXOBJFILE_CHANGE_Same
Definition: cXObjPack.h:24
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
static __DECL_IMPORT COMPARE_t __stdcall CmpI(const TYPE *pszStr1, const TYPE *pszStr2)