Choreonoid  1.1
LinkGroup.h
説明を見る。
1 /*
2  @author Shin'ichiro Nakaoka
3 */
4 
5 #ifndef CNOID_BODY_LINK_GROUP_H_INCLUDED
6 #define CNOID_BODY_LINK_GROUP_H_INCLUDED
7 
8 #include <boost/variant.hpp>
9 #include <cnoid/Referenced>
10 #include <vector>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15  class YamlSequence;
16 
17  class Body;
18  typedef boost::intrusive_ptr<Body> BodyPtr;
19 
20  class LinkGroup;
21  typedef boost::intrusive_ptr<LinkGroup> LinkGroupPtr;
22 
24  {
25  typedef boost::variant<LinkGroupPtr, int> Element;
26 
27  public:
28 
29  static LinkGroupPtr create(BodyPtr body, const YamlSequence& linkGroupSeq);
30 
31  LinkGroup();
32  virtual ~LinkGroup();
33 
34  inline void setName(const std::string& name) { name_ = name; }
35  inline const std::string& name() { return name_; }
36 
37  inline int numElements() { return elements.size(); }
38  inline bool isSubGroup(int index) { return elements[index].which() == 0; }
39  inline bool isLinkIndex(int index) { return elements[index].which() == 1; }
40  inline LinkGroupPtr subGroup(int index) { return boost::get<LinkGroupPtr>(elements[index]); }
41  inline int linkIndex(int index) { return boost::get<int>(elements[index]); }
42 
43  std::vector<int> collectLinkIndices() const;
44  std::vector<LinkGroupPtr> collectGroups() const;
45 
46  private:
47 
48  std::string name_;
49  std::vector<Element> elements;
50 
51  bool load(BodyPtr& body, const YamlSequence& linkGroupseq);
52  void setFlatLinkList(BodyPtr& body);
53  };
54 }
55 
56 
57 #endif