3D Repo Bouncer  1.4
repo_node.h
1 
21 #pragma once
22 
23 #include "repo_bson.h"
24 
25 namespace repo{
26  namespace core{
27  namespace model{
28  enum class NodeType{
29  CAMERA, MAP, MATERIAL, MESH, METADATA, REFERENCE,
30  REVISION, TEXTURE, TRANSFORMATION, UNKNOWN
31  };
32 
33  class REPO_API_EXPORT RepoNode : public RepoBSON
34  {
35  public:
36 
42  RepoNode(RepoBSON bson,
43  const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping =
44  std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>>());
45 
49  RepoNode() : RepoBSON() {};
50 
54  virtual ~RepoNode();
55 
65  virtual bool positionDependant() { return false; }
66 
67  /*
68  * ------------- Delusional modifiers --------------
69  * These are like "setters" but not. We are actually
70  * creating a new bson object with the changed field
71  */
72 
83  RepoNode cloneAndAddParent(
84  const repoUUID &parent,
85  const bool &newUniqueID = false,
86  const bool &newSharedID = false,
87  const bool &overwrite = false) const;
88 
96  RepoNode cloneAndAddParent(
97  const std::vector<repoUUID> &parents) const;
98 
107  const std::vector<float> &matrix) const
108  {
109  return RepoNode(copy(), bigFiles);
110  }
111 
119  const std::string &newName,
120  const bool &newUniqueID = true
121  ) const
122  {
123  return cloneAndAddFields(new RepoBSON(BSON(REPO_NODE_LABEL_NAME << newName)), newUniqueID);
124  }
125 
134  RepoNode cloneAndRemoveParent(
135  const repoUUID &parent,
136  const bool &newUniqueID = true) const;
137 
146  virtual RepoNode cloneAndAddFields(
147  const RepoBSON *changes,
148  const bool &newUniqueID = true) const;
149 
150  /*
151  * ------------- Convenience getters --------------
152  */
153 
158  std::string getName() const
159  {
160  return std::string(getStringField(REPO_NODE_LABEL_NAME));
161  }
162 
167  repoUUID getSharedID() const { return getUUIDField(REPO_NODE_LABEL_SHARED_ID); }
168 
173  virtual std::string getType() const
174  {
175  return getStringField(REPO_NODE_LABEL_TYPE);
176  }
177 
182  virtual NodeType getTypeAsEnum() const;
183 
188  repoUUID getUniqueID() const{ return getUUIDField(REPO_NODE_LABEL_ID); }
189 
194  std::vector<repoUUID> getParentIDs() const;
195 
196  /*
197  * ------------- Compare operations --------------
198  */
200  bool operator==(const RepoNode& other) const
201  {
202  return getUniqueID() == other.getUniqueID() && getSharedID() == other.getSharedID();
203  }
204 
206  bool operator<(const RepoNode& other) const
207  {
208  repoUUID sharedID = getSharedID();
209 
210  if (sharedID == other.getSharedID()){
211  return getUniqueID() < other.getUniqueID();
212  }
213  else{
214  return sharedID < other.getSharedID();
215  }
216  }
217 
225  virtual bool sEqual(const RepoNode &other) const
226  {
227  //On a node level, it is impossible to tell if
228  //one node is semantically the same as other.
229  //One does not expect this to be ever called
230  repoWarning << "sEqual() is called for RepoNode* this is not expected!";
231  return false; //returns false just incase.
232  }
233 
235  bool operator>(const RepoNode& other) const
236  {
237  repoUUID sharedID = getSharedID();
238 
239  if (sharedID == other.getSharedID()){
240  return getUniqueID() > other.getUniqueID();
241  }
242  else{
243  return sharedID > other.getSharedID();
244  }
245  }
246 
247  protected:
248 
249  /*
250  * ------------- node fields --------------
251  */
252 
253  //FIXME: Convenience fields, should these really exist?
254 
255  std::string type;
256  };
267  {
268  bool operator()(const RepoNode* a, const RepoNode* b) const
269  {
270  return *a < *b;
271  }
272  };
273 
275  typedef std::set<RepoNode *, RepoNodeComparator> RepoNodeSet;
276  } //namespace model
277  } //namespace core
278 } //namespace repo
virtual bool sEqual(const RepoNode &other) const
Definition: repo_node.h:225
Definition: repo_connection_pool_mongo.h:32
repoUUID getSharedID() const
Definition: repo_node.h:167
bool operator<(const RepoNode &other) const
Returns true if the other node is greater than this one, false otherwise.
Definition: repo_node.h:206
virtual std::string getType() const
Definition: repo_node.h:173
repoUUID getUniqueID() const
Definition: repo_node.h:188
virtual RepoNode cloneAndApplyTransformation(const std::vector< float > &matrix) const
Definition: repo_node.h:106
std::string getName() const
Definition: repo_node.h:158
RepoNode()
Definition: repo_node.h:49
Definition: repo_node.h:266
bool operator>(const RepoNode &other) const
Returns true if the other node is greater than this one, false otherwise.
Definition: repo_node.h:235
Definition: repo_node.h:33
Definition: repo_bson.h:53
virtual bool positionDependant()
Definition: repo_node.h:65
std::string type
Compulsory type of this document.
Definition: repo_node.h:255
bool operator==(const RepoNode &other) const
Returns true if the node is the same, false otherwise.
Definition: repo_node.h:200
RepoNode cloneAndChangeName(const std::string &newName, const bool &newUniqueID=true) const
Definition: repo_node.h:118