Choreonoid  1.8
SceneUpdate.h
Go to the documentation of this file.
1 #ifndef CNOID_UTIL_SCENE_UPDATE_H
2 #define CNOID_UTIL_SCENE_UPDATE_H
3 
4 #include <vector>
5 
6 namespace cnoid {
7 
8 class SgObject;
9 
10 class SgUpdate
11 {
12 public:
13  enum Action {
14  None = 0,
15  Added = 1 << 0,
16  Removed = 1 << 1,
17  GeometryModified = 1 << 2,
20 
21  // deprecated
27  };
28 
29  typedef std::vector<SgObject*> Path;
30 
31  SgUpdate() : action_(MODIFIED), initialPathCapacity_(0) { }
32  SgUpdate(int action) : action_(action), initialPathCapacity_(0) { }
33  SgUpdate(const SgUpdate& org)
34  : path_(org.path_), action_(org.action_), initialPathCapacity_(0) { }
35  ~SgUpdate() { }
36  void setInitialPathCapacity(unsigned char n) { initialPathCapacity_ = n; }
37  void reservePathCapacity(int n) { path_.reserve(n); }
38  int action() const { return action_; }
39  bool hasAction(int act) const { return action_ & act; }
40  SgUpdate& withAction(int act) { action_ = act; return *this; }
41  void setAction(int act) { action_ = act; }
42  void addAction(int act) { action_ |= act; }
43  const Path& path() const { return path_; }
44  void pushNode(SgObject* node) { path_.push_back(node); }
45  void popNode() { path_.pop_back(); }
46  void clearPath() {
47  if(path_.empty()){
48  path_.reserve(initialPathCapacity_);
49  } else {
50  path_.clear();
51  }
52  }
53 
54  [[deprecated("Use setAction.")]]
55  void resetAction(int act = None) { setAction(act); }
56  [[deprecated("Use clearPath()")]]
57  void clear() { clearPath(); }
58 
59 private:
60  Path path_;
61  char action_;
62  unsigned char initialPathCapacity_;
63 };
64 
65 
66 class SgTmpUpdate : public SgUpdate
67 {
68 public:
70 };
71 
72 
74 {
75  SgUpdate* pUpdate;
76  bool isTmpUpdate;
77 
78 public:
79  SgUpdateRef() : pUpdate(nullptr), isTmpUpdate(false) { }
80  SgUpdateRef(SgUpdate& update) : pUpdate(&update), isTmpUpdate(false) { }
81  SgUpdateRef(SgUpdate* pUpdate) : pUpdate(pUpdate), isTmpUpdate(false) { }
82  SgUpdateRef(const SgUpdateRef& org) : pUpdate(org.pUpdate), isTmpUpdate(false) { }
83  SgUpdateRef(bool doCreateTmpUpdate) : isTmpUpdate(doCreateTmpUpdate) {
84  if(doCreateTmpUpdate){
85  pUpdate = new SgTmpUpdate;
86  } else {
87  pUpdate = nullptr;
88  }
89  }
90  ~SgUpdateRef() { if(isTmpUpdate) delete pUpdate; }
91  operator bool() const { return pUpdate != nullptr; }
92  operator SgUpdate*() { return pUpdate; }
93  SgUpdate& operator*() { return *pUpdate; }
94  SgUpdate* operator->() { return pUpdate; }
95 };
96 
97 }
98 
99 #endif
cnoid::SgUpdate::Added
@ Added
Definition: SceneUpdate.h:15
cnoid::SgTmpUpdate
Definition: SceneUpdate.h:66
cnoid::SgUpdate::Removed
@ Removed
Definition: SceneUpdate.h:16
cnoid::SgUpdate::addAction
void addAction(int act)
Definition: SceneUpdate.h:42
cnoid::SgUpdateRef::SgUpdateRef
SgUpdateRef(SgUpdate *pUpdate)
Definition: SceneUpdate.h:81
cnoid::SgUpdate::hasAction
bool hasAction(int act) const
Definition: SceneUpdate.h:39
cnoid::SgUpdate::REMOVED
@ REMOVED
Definition: SceneUpdate.h:24
cnoid::SgUpdate::SgUpdate
SgUpdate()
Definition: SceneUpdate.h:31
cnoid::SgUpdate::reservePathCapacity
void reservePathCapacity(int n)
Definition: SceneUpdate.h:37
cnoid::SgUpdateRef::SgUpdateRef
SgUpdateRef(SgUpdate &update)
Definition: SceneUpdate.h:80
cnoid::SgUpdate::ADDED
@ ADDED
Definition: SceneUpdate.h:23
cnoid::SgUpdate::~SgUpdate
~SgUpdate()
Definition: SceneUpdate.h:35
cnoid::SgUpdate::clear
void clear()
Definition: SceneUpdate.h:57
cnoid::SgUpdate::path
const Path & path() const
Definition: SceneUpdate.h:43
cnoid::SgUpdate
Definition: SceneUpdate.h:10
cnoid::SgUpdate::action
int action() const
Definition: SceneUpdate.h:38
cnoid::SgUpdate::SgUpdate
SgUpdate(int action)
Definition: SceneUpdate.h:32
cnoid::SgUpdate::pushNode
void pushNode(SgObject *node)
Definition: SceneUpdate.h:44
cnoid::SgUpdateRef::operator*
SgUpdate & operator*()
Definition: SceneUpdate.h:93
cnoid::SgUpdateRef
Definition: SceneUpdate.h:73
cnoid::SgUpdate::popNode
void popNode()
Definition: SceneUpdate.h:45
cnoid::SgUpdate::setInitialPathCapacity
void setInitialPathCapacity(unsigned char n)
Definition: SceneUpdate.h:36
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::SgUpdate::setAction
void setAction(int act)
Definition: SceneUpdate.h:41
cnoid::SgUpdateRef::operator->
SgUpdate * operator->()
Definition: SceneUpdate.h:94
cnoid::SgUpdate::Action
Action
Definition: SceneUpdate.h:13
cnoid::SgUpdate::clearPath
void clearPath()
Definition: SceneUpdate.h:46
cnoid::SgUpdate::resetAction
void resetAction(int act=None)
Definition: SceneUpdate.h:55
cnoid::SgUpdate::BBOX_UPDATED
@ BBOX_UPDATED
Definition: SceneUpdate.h:26
cnoid::SgUpdateRef::SgUpdateRef
SgUpdateRef(const SgUpdateRef &org)
Definition: SceneUpdate.h:82
cnoid::SgUpdate::Modified
@ Modified
Definition: SceneUpdate.h:19
cnoid::SgUpdate::withAction
SgUpdate & withAction(int act)
Definition: SceneUpdate.h:40
cnoid::SgUpdate::GeometryModified
@ GeometryModified
Definition: SceneUpdate.h:17
cnoid::SgUpdateRef::~SgUpdateRef
~SgUpdateRef()
Definition: SceneUpdate.h:90
cnoid::SgUpdate::SgUpdate
SgUpdate(const SgUpdate &org)
Definition: SceneUpdate.h:33
cnoid::SgUpdate::MODIFIED
@ MODIFIED
Definition: SceneUpdate.h:25
cnoid::SgUpdateRef::SgUpdateRef
SgUpdateRef()
Definition: SceneUpdate.h:79
cnoid::SgObject
Definition: SceneGraph.h:28
cnoid::SgUpdate::NONE
@ NONE
Definition: SceneUpdate.h:22
cnoid::SgUpdate::AppearanceModified
@ AppearanceModified
Definition: SceneUpdate.h:18
cnoid::SgUpdateRef::SgUpdateRef
SgUpdateRef(bool doCreateTmpUpdate)
Definition: SceneUpdate.h:83
cnoid::SgUpdate::Path
std::vector< SgObject * > Path
Definition: SceneUpdate.h:29
cnoid::SgTmpUpdate::SgTmpUpdate
SgTmpUpdate()
Definition: SceneUpdate.h:69
cnoid::SgUpdate::None
@ None
Definition: SceneUpdate.h:14