Choreonoid  1.8
MprProgram.h
Go to the documentation of this file.
1 #ifndef CNOID_MANIPULATOR_PLUGIN_MPR_PROGRAM_H
2 #define CNOID_MANIPULATOR_PLUGIN_MPR_PROGRAM_H
3 
4 #include <cnoid/ClonableReferenced>
5 #include <cnoid/Signal>
6 #include <string>
7 #include <deque>
8 #include <iosfwd>
9 #include "exportdecl.h"
10 
11 namespace cnoid {
12 
13 class Mapping;
14 class MprPosition;
15 class MprPositionList;
16 class MprStatement;
17 class MprStructuredStatement;
18 class PositionTagGroup;
19 
20 
21 class CNOID_EXPORT MprProgram : public ClonableReferenced
22 {
23 public:
24  typedef std::deque<ref_ptr<MprStatement>> StatementContainer;
25  typedef StatementContainer::iterator iterator;
26  typedef StatementContainer::const_iterator const_iterator;
27 
28  MprProgram();
29  ~MprProgram();
30 
31  MprProgram* clone() const {
32  return static_cast<MprProgram*>(doClone(nullptr));
33  }
34  MprProgram* clone(CloneMap& cloneMap) const {
35  return static_cast<MprProgram*>(doClone(&cloneMap));
36  }
37 
38  const std::string& name() const;
39  void setName(const std::string& name);
40 
41  bool empty() const { return statements_.empty(); }
42  int numStatements() const { return statements_.size(); }
43 
44  iterator insert(iterator pos, MprStatement* statement, bool doNotify = true);
45  iterator append(MprStatement* statement, bool doNotify = true);
46  iterator remove(iterator pos, bool doNotify = true);
47  bool remove(MprStatement* statement, bool doNotify = true);
48  iterator find(MprStatement* statement);
49  const_iterator find(MprStatement* statement) const;
50  void clearStatements();
51 
52  iterator begin(){ return statements_.begin(); }
53  const_iterator begin() const { return statements_.begin(); }
54  iterator end(){ return statements_.end(); }
55  const_iterator end() const { return statements_.end(); }
56 
57  void setLocalPositionListEnabled(bool on);
58  bool hasLocalPositionList() const { return hasLocalPositionList_; }
59  MprPositionList* positionList();
60  const MprPositionList* positionList() const;
61  void removeUnreferencedPositions();
62 
63  SignalProxy<void(MprProgram::iterator iter)> sigStatementInserted();
64  SignalProxy<void(MprStatement* statement, MprProgram* program)> sigStatementRemoved();
65  SignalProxy<void(MprStatement* statement)> sigStatementUpdated();
66 
67  void notifyStatementUpdate(MprStatement* statement) const;
68 
69  MprStructuredStatement* holderStatement() const;
70  bool isTopLevelProgram() const;
71  bool isSubProgram() const;
72  MprProgram* topLevelProgram() const;
73 
74  void traverseStatements(std::function<void(MprStatement* statement)> callback);
75 
80  bool traverseStatements(std::function<bool(MprStatement* statement)> callback);
81 
82  void renumberPositionIds();
83 
84  bool isEditingEnabled() const { return isEditingEnabled_; }
85  void setEditingEnabled(bool on) { isEditingEnabled_ = on; }
86 
87  bool load(const std::string& filename, std::ostream& os);
88  bool save(const std::string& filename);
89 
90  bool read(const Mapping& archive);
91  bool write(Mapping& archive) const;
92 
93 protected:
94  MprProgram(const MprProgram& org, CloneMap* cloneMap = nullptr);
95  virtual Referenced* doClone(CloneMap* cloneMap) const override;
96 
97 private:
98  StatementContainer statements_;
99  bool hasLocalPositionList_;
100  bool isEditingEnabled_;
101 
102  class Impl;
103  Impl* impl;
104 
106 
107  void setHolderStatement(MprStructuredStatement* holder);
108 };
109 
111 
112 }
113 
114 #endif
cnoid::MprProgram::hasLocalPositionList
bool hasLocalPositionList() const
Definition: MprProgram.h:58
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::MprStructuredStatement
Definition: MprStructuredStatement.h:10
cnoid::MprProgram::end
const_iterator end() const
Definition: MprProgram.h:55
cnoid::write
Listing * write(Mapping *mapping, const std::string &key, const Eigen::MatrixBase< Derived > &x)
Definition: EigenArchive.h:145
cnoid::MprProgram::numStatements
int numStatements() const
Definition: MprProgram.h:42
cnoid::MprProgram::clone
MprProgram * clone() const
Definition: MprProgram.h:31
cnoid::read
bool read(const Mapping *mapping, const std::string &key, Eigen::MatrixBase< Derived > &x)
Definition: EigenArchive.h:43
cnoid::MprProgram::setEditingEnabled
void setEditingEnabled(bool on)
Definition: MprProgram.h:85
cnoid::MprProgram::begin
const_iterator begin() const
Definition: MprProgram.h:53
cnoid::MprProgramPtr
ref_ptr< MprProgram > MprProgramPtr
Definition: MprProgram.h:110
cnoid::ref_ptr< MprProgram >
cnoid::MprProgram::end
iterator end()
Definition: MprProgram.h:54
cnoid::MprProgram::clone
MprProgram * clone(CloneMap &cloneMap) const
Definition: MprProgram.h:34
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::ClonableReferenced
Definition: ClonableReferenced.h:10
cnoid::CloneMap
Definition: CloneMap.h:13
cnoid::MprStatement
Definition: MprStatement.h:16
cnoid::Referenced
Definition: Referenced.h:54
cnoid::MprProgram::StatementContainer
std::deque< ref_ptr< MprStatement > > StatementContainer
Definition: MprProgram.h:24
cnoid::MprProgram
Definition: MprProgram.h:21
cnoid::MprProgram::const_iterator
StatementContainer::const_iterator const_iterator
Definition: MprProgram.h:26
cnoid::SignalProxy
Definition: Signal.h:470
cnoid::MprPositionList
Definition: MprPositionList.h:14
cnoid::MprProgram::begin
iterator begin()
Definition: MprProgram.h:52
cnoid::MprProgram::empty
bool empty() const
Definition: MprProgram.h:41
cnoid::MprProgram::iterator
StatementContainer::iterator iterator
Definition: MprProgram.h:25
cnoid::MprProgram::isEditingEnabled
bool isEditingEnabled() const
Definition: MprProgram.h:84