Choreonoid  1.8
LinkGroup.h
Go to the documentation of this file.
1 /*
2  @author Shin'ichiro Nakaoka
3 */
4 
5 #ifndef CNOID_BODY_LINK_GROUP_H
6 #define CNOID_BODY_LINK_GROUP_H
7 
8 #include <cnoid/stdx/variant>
9 #include <vector>
10 #include <string>
11 #include <memory>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class Listing;
17 class Body;
18 class LinkGroup;
19 typedef std::shared_ptr<LinkGroup> LinkGroupPtr;
20 
21 class CNOID_EXPORT LinkGroup
22 {
23  typedef stdx::variant<LinkGroupPtr, int> Element;
24 
25  LinkGroup(const LinkGroup& org);
26 
27  struct private_tag { };
28 
29 public:
30  static LinkGroupPtr create(const Body& body);
31 
32  LinkGroup(private_tag tag);
33  virtual ~LinkGroup();
34 
35  void setName(const std::string& name) { name_ = name; }
36  const std::string& name() { return name_; }
37 
38  int numElements() const { return elements.size(); }
39  bool isSubGroup(int index) const { return stdx::get_variant_index(elements[index]) == 0; }
40  bool isLinkIndex(int index) const { return stdx::get_variant_index(elements[index]) == 1; }
41  const LinkGroupPtr& subGroup(int index) const { return stdx::get<LinkGroupPtr>(elements[index]); }
42  int linkIndex(int index) const { return stdx::get<int>(elements[index]); }
43 
44  std::vector<int> collectLinkIndices() const;
45  std::vector<LinkGroupPtr> collectGroups() const;
46 
47 private:
48  std::string name_;
49  std::vector<Element> elements;
50 
51  bool load(const Body& body, const Listing& linkGroupList);
52  void setFlatLinkList(const Body& body);
53 };
54 
55 }
56 
57 #endif
cnoid::LinkGroup::linkIndex
int linkIndex(int index) const
Definition: LinkGroup.h:42
cnoid::LinkGroup::setName
void setName(const std::string &name)
Definition: LinkGroup.h:35
cnoid::LinkGroup
Definition: LinkGroup.h:21
cnoid::LinkGroup::numElements
int numElements() const
Definition: LinkGroup.h:38
cnoid::LinkGroupPtr
std::shared_ptr< LinkGroup > LinkGroupPtr
Definition: LinkGroup.h:18
cnoid::Listing
Definition: ValueTree.h:486
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::LinkGroup::name
const std::string & name()
Definition: LinkGroup.h:36
cnoid::LinkGroup::subGroup
const LinkGroupPtr & subGroup(int index) const
Definition: LinkGroup.h:41
cnoid::LinkGroup::isSubGroup
bool isSubGroup(int index) const
Definition: LinkGroup.h:39
cnoid::LinkGroup::isLinkIndex
bool isLinkIndex(int index) const
Definition: LinkGroup.h:40
cnoid::Body
Definition: Body.h:28