Choreonoid  1.8
MprVariableList.h
Go to the documentation of this file.
1 #ifndef CNOID_MANIPULATOR_PLUGIN_MPR_VARIABLE_LIST_H
2 #define CNOID_MANIPULATOR_PLUGIN_MPR_VARIABLE_LIST_H
3 
4 #include "MprVariable.h"
5 #include <cnoid/ClonableReferenced>
6 #include <cnoid/Signal>
7 #include <string>
8 #include "exportdecl.h"
9 
10 namespace cnoid {
11 
12 class CNOID_EXPORT MprVariableList : public ClonableReferenced
13 {
14 public:
15  enum VariableType {
16  GeneralVariable, IntVariable, DoubleVariable, BoolVariable, StringVariable };
17 
19  MprVariableList(VariableType variableType);
20  MprVariableList(const MprVariableList& org);
21  ~MprVariableList();
22 
24  return static_cast<MprVariableList*>(doClone(nullptr));
25  }
26  MprVariableList* clone(CloneMap& cloneMap) const {
27  return static_cast<MprVariableList*>(doClone(&cloneMap));
28  }
29 
30  MprVariableList& operator=(const MprVariableList& rhs) = delete;
31 
32  void setVariableType(VariableType type);
33  void setGeneralVariableValueTypeUnchangeable(bool on);
34  void setNumberIdEnabled(bool on);
35  void setStringIdEnabled(bool on);
36 
37  VariableType variableType() const { return variableType_; }
39  return isGeneralVariableValueTypeUnchangeable_;
40  }
41  bool isNumberIdEnabled() const { return isNumberIdEnabled_; }
42  bool isStringIdEnabled() const { return isStringIdEnabled_; }
43 
44  void clear();
45  int numVariables() const;
46  MprVariable* variableAt(int index) const;
47  int indexOf(MprVariable* variable) const;
48  MprVariable* findVariable(const GeneralId& id) const;
49  MprVariable::Value defaultValue() const;
50 
51  bool insert(int index, MprVariable* variable);
52  bool append(MprVariable* variable);
53  bool removeAt(int index);
54 
55  SignalProxy<void(int index)> sigVariableAdded();
56  SignalProxy<void(int index, MprVariable* variable)> sigVariableRemoved();
57  SignalProxy<void(int index, int flags)> sigVariableUpdated();
58 
63  bool resetId(MprVariable* variable, const GeneralId& newId);
64 
65  void resetIdCounter();
66  GeneralId createNextId(int prevId = -1);
67 
68  bool read(const Mapping& archive);
69  bool write(Mapping& archive) const;
70 
71 protected:
72  MprVariableList(const MprVariableList& org, CloneMap* cloneMap);
73  virtual Referenced* doClone(CloneMap* cloneMap) const override;
74 
75 private:
76  // Called from the MprVariable implementation
77  void notifyVariableUpdate(MprVariable* variable, int flags);
78 
79  class Impl;
80  Impl* impl;
81 
82  VariableType variableType_;
83  bool isGeneralVariableValueTypeUnchangeable_;
84  bool isNumberIdEnabled_;
85  bool isStringIdEnabled_;
86 
87  friend class MprVariable;
88 };
89 
91 
92 }
93 
94 #endif
cnoid::MprVariableList::clone
MprVariableList * clone(CloneMap &cloneMap) const
Definition: MprVariableList.h:26
cnoid::MprVariable
Definition: MprVariable.h:15
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::GeneralId
Definition: GeneralId.h:11
cnoid::write
Listing * write(Mapping *mapping, const std::string &key, const Eigen::MatrixBase< Derived > &x)
Definition: EigenArchive.h:145
cnoid::MprVariableList::VariableType
VariableType
Definition: MprVariableList.h:15
cnoid::read
bool read(const Mapping *mapping, const std::string &key, Eigen::MatrixBase< Derived > &x)
Definition: EigenArchive.h:43
cnoid::MprVariableListPtr
ref_ptr< MprVariableList > MprVariableListPtr
Definition: MprVariableList.h:90
cnoid::ref_ptr< MprVariableList >
cnoid::MprVariable::Value
stdx::variant< int, double, bool, std::string > Value
Definition: MprVariable.h:18
cnoid::MprVariableList::clone
MprVariableList * clone() const
Definition: MprVariableList.h:23
MprVariable.h
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::ClonableReferenced
Definition: ClonableReferenced.h:10
cnoid::CloneMap
Definition: CloneMap.h:13
cnoid::MprVariableList::variableType
VariableType variableType() const
Definition: MprVariableList.h:37
cnoid::MprVariableList::isStringIdEnabled
bool isStringIdEnabled() const
Definition: MprVariableList.h:42
cnoid::MprVariableList
Definition: MprVariableList.h:12
cnoid::Referenced
Definition: Referenced.h:54
cnoid::MprVariableList::isNumberIdEnabled
bool isNumberIdEnabled() const
Definition: MprVariableList.h:41
cnoid::MprVariableList::isGeneralVariableValueTypeUnchangeable
bool isGeneralVariableValueTypeUnchangeable() const
Definition: MprVariableList.h:38
cnoid::SignalProxy
Definition: Signal.h:470