Choreonoid  1.8
ArchiveSession.h
Go to the documentation of this file.
1 #ifndef CNOID_UTIL_ARCHIVE_SESSION_H
2 #define CNOID_UTIL_ARCHIVE_SESSION_H
3 
4 #include "Referenced.h"
5 #include "Signal.h"
6 #include <string>
7 #include "exportdecl.h"
8 
9 namespace cnoid {
10 
11 class Uuid;
12 
16 class CNOID_EXPORT ArchiveSession
17 {
18 public:
20  virtual ~ArchiveSession();
21 
22  void initialize();
23 
24  bool addReference(const Uuid& uuid, Referenced* object, bool doUnreferenceImmediately = false);
25 
26  template<class ObjectType>
28  const Uuid& uuid,
29  std::function<bool(ObjectType* object, bool isImmediate)> onResolved,
30  std::function<bool()> onNotResolved = nullptr)
31  {
32  resolveReference_(
33  uuid,
34  [onResolved](Referenced* object, bool isImmediate){
35  if(auto derived = dynamic_cast<ObjectType*>(object)){
36  return onResolved(derived, isImmediate);
37  }
38  return false;
39  },
40  onNotResolved,
41  false);
42  }
43 
44  template<class ObjectType>
46  const Uuid& uuid,
47  std::function<bool(ObjectType* object)> onResolved,
48  std::function<bool()> onNotResolved = nullptr)
49  {
50  resolveReference_(
51  uuid,
52  [onResolved](Referenced* object, bool isImmediate){
53  if(auto derived = dynamic_cast<ObjectType*>(object)){
54  return onResolved(derived);
55  }
56  return false;
57  },
58  onNotResolved,
59  false);
60  }
61 
62  virtual void putWarning(const std::string& message);
63  virtual void putError(const std::string& message);
64 
65  void resolvePendingReferences();
66  bool finalize();
67  SignalProxy<void()> sigSessionFinalized();
68 
69 private:
70  void resolveReference_(
71  const Uuid& uuid,
72  std::function<bool(Referenced* object, bool isImmediate)> onResolved,
73  std::function<bool()> onNotResolved,
74  bool doResolveLater
75  );
76 
77  class Impl;
78  Impl* impl;
79 };
80 
81 }
82 
83 #endif
Referenced.h
cnoid::ArchiveSession::resolveReferenceLater
void resolveReferenceLater(const Uuid &uuid, std::function< bool(ObjectType *object)> onResolved, std::function< bool()> onNotResolved=nullptr)
Definition: ArchiveSession.h:45
cnoid::ArchiveSession::resolveReference
void resolveReference(const Uuid &uuid, std::function< bool(ObjectType *object, bool isImmediate)> onResolved, std::function< bool()> onNotResolved=nullptr)
Definition: ArchiveSession.h:27
cnoid::Uuid
Definition: Uuid.h:11
cnoid::ArchiveSession
Definition: ArchiveSession.h:16
cnoid
Definition: AbstractSceneLoader.h:11
Signal.h
cnoid::Referenced
Definition: Referenced.h:54
cnoid::SignalProxy
Definition: Signal.h:470