Choreonoid  1.8
Selection.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_SELECTION_H
6 #define CNOID_UTIL_SELECTION_H
7 
8 #include <vector>
9 #include <string>
10 #include <initializer_list>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class CNOID_EXPORT Selection
16 {
17 public:
18  explicit Selection(const char* domainname = nullptr);
19  explicit Selection(size_t size, const char* domainname = nullptr);
20  Selection(std::initializer_list<std::string> symbols, const char* domainname = nullptr);
21  Selection(const Selection& org);
22 
23  Selection& operator=(const Selection& rhs);
24 
25  int size() const {
26  return static_cast<int>(symbols_.size());
27  }
28 
29  explicit operator bool() const {
30  return selectedIndex_ >= 0;
31  }
32 
33  operator int() const {
34  return selectedIndex_;
35  }
36 
37  void resize(int s);
38 
39  void clear();
40 
41  void setSymbol(int index, const std::string& symbol);
42 
43  Selection& operator<<(const std::string& symbol);
44 
45  std::string& symbol(int index) {
46  return symbols_[index];
47  }
48 
49  const std::string& symbol(int index) const {
50  return symbols_[index];
51  }
52 
53  int index(const std::string& symbol) const;
54 
55  const char* label(int index) const;
56 
57  bool select(int index);
58  bool selectIndex(int index);
59  bool select(const std::string& symbol);
60 
61  int selectedIndex() const {
62  return selectedIndex_;
63  }
64 
65  int which() const {
66  return selectedIndex_;
67  }
68 
69  bool is(int index) const {
70  return (index == selectedIndex_);
71  }
72 
73  const char* selectedSymbol() const;
74  const char* selectedLabel() const;
75 
76 private:
77  std::vector<std::string> symbols_;
78  int selectedIndex_;
79  const char* domainname_;
80 };
81 
82 }
83 
84 #endif
cnoid::Selection
Definition: Selection.h:15
cnoid::Selection::is
bool is(int index) const
Definition: Selection.h:69
cnoid::Selection::symbol
const std::string & symbol(int index) const
Definition: Selection.h:49
cnoid::Selection::selectedIndex
int selectedIndex() const
Definition: Selection.h:61
cnoid::operator<<
CNOID_EXPORT std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Definition: BoundingBox.cpp:160
cnoid::Selection::symbol
std::string & symbol(int index)
Definition: Selection.h:45
cnoid::Selection::size
int size() const
Definition: Selection.h:25
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Selection::which
int which() const
Definition: Selection.h:65