My Project
IRefObject.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "util/unordered_array.hpp"
4 
5 namespace ParaEngine
6 {
7  using namespace std;
8  class IRefObject;
9 
10  typedef DWORD RefMessage;
12  {
18  };
19 
20  /* Some return codes for references...
21  * There would probably be a bunch of these.
22  */
23  enum RefResult {
24  REF_FAIL,
25  REF_SUCCEED,
26  REF_DONTCARE,
27  REF_STOP,
28  REF_INVALID,
29  // Return this from NotifRefChanged() when a REFMGS_TAGET_DELETED message is sent
30  // if a ReferenceMaker should be removed from the scene when all its references are removed.
31  REF_AUTO_DELETE
32  };
33 
38  {
39  public:
40  IRefObject* m_object;
41  int m_tag;
42  RefListItem( IRefObject* ref, int nTag):m_object(ref),m_tag(nTag) {}
43  RefListItem( IRefObject* ref):m_object(ref), m_tag(0) {};
44  RefListItem():m_object(NULL), m_tag(0) {};
45 
46  inline bool operator == (const RefListItem& r){
47  return this->m_object == r.m_object;
48  }
49 
50  inline bool operator == (const IRefObject* r){
51  return this->m_object == r;
52  }
53 
54  bool operator == (const char* r);
55  };
58 
66  {
67  protected:
69  RefList m_references;
70 
72  std::string m_sIdentifer;
73  public:
74  IRefObject() {}
75  virtual ~IRefObject();
76 
78  virtual const std::string& GetIdentifier();
79  virtual void SetIdentifier(const std::string& sID);
80 
82  int GetNameW(std::u16string& out);
84  const std::string& GetName();
85 
90  IRefObject* GetRefObjectByName(const char* sName);
91 
95  RefListItem* GetRefObjectByTag(int nTag);
96 
100  inline bool HasReferences(){ return !(m_references.empty());};
101 
107  RefResult AddReference(IRefObject* maker, int nTag = 0);
108 
114  RefResult DeleteReference(IRefObject* ref);
115 
117  RefResult DeleteAllRefs();
118 
122  int DeleteAllRefsByTag(int nTag = 0);
123 
125  inline RefList& GetRefList() { return m_references; }
126 
128  int GetRefObjNum();
129 
135  RefListItem* GetRefObject(int nIndex);
136 
144  virtual void OnRefAdded(IRefObject* rm, int nTag=0);
145 
152  virtual void OnRefDeleted(IRefObject* rm);
153 
155  //virtual RefResult AutoDelete(){ return REF_SUCCEED;};
156 
157  // Notify all dependent RefMakers concerned with the message
158  // virtual RefResult NotifyReferences(RefMessage message, bool propagate=true, IRefObject* pCaller=NULL);
159  };
160 }
when a reference object(caller) is deleted, it will send this message to all its references.
Definition: IRefObject.h:15
a referenced object
Definition: IRefObject.h:37
different physics engine has different winding order.
Definition: EventBinding.h:32
when a reference object add, it will send this message to all its references.
Definition: IRefObject.h:17
std::string m_sIdentifer
unit name used in the scripting language
Definition: IRefObject.h:72
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
REF_MESSAGE
Definition: IRefObject.h:11
RefList m_references
This is the list of active references that refer to us.
Definition: IRefObject.h:69
RefList & GetRefList()
get the ref list
Definition: IRefObject.h:125
unordered_array< RefListItem > RefList
reference list
Definition: IRefObject.h:57
bool HasReferences()
Definition: IRefObject.h:100
anything that makes references to other objects.
Definition: IRefObject.h:65