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  int size() const {
24  return static_cast<int>(symbols_.size());
25  }
26 
27  explicit operator bool() const {
28  return selectedIndex_ >= 0;
29  }
30 
31  operator int() const {
32  return selectedIndex_;
33  }
34 
35  void resize(int s);
36 
37  void clear();
38 
39  void setSymbol(int index, const std::string& symbol);
40 
41  Selection& operator<<(const std::string& symbol);
42 
43  std::string& symbol(int index) {
44  return symbols_[index];
45  }
46 
47  const std::string& symbol(int index) const {
48  return symbols_[index];
49  }
50 
51  int index(const std::string& symbol) const;
52 
53  const char* label(int index) const;
54 
55  bool select(int index);
56  bool selectIndex(int index);
57  bool select(const std::string& symbol);
58 
59  int selectedIndex() const {
60  return selectedIndex_;
61  }
62 
63  int which() const {
64  return selectedIndex_;
65  }
66 
67  bool is(int index) const {
68  return (index == selectedIndex_);
69  }
70 
71  const char* selectedSymbol() const;
72  const char* selectedLabel() const;
73 
74 private:
75  std::vector<std::string> symbols_;
76  int selectedIndex_;
77  const char* domainname_;
78 };
79 
80 }
81 
82 #endif
cnoid::Selection
Definition: Selection.h:15
cnoid::Selection::is
bool is(int index) const
Definition: Selection.h:67
cnoid::Selection::symbol
const std::string & symbol(int index) const
Definition: Selection.h:47
cnoid::Selection::selectedIndex
int selectedIndex() const
Definition: Selection.h:59
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:43
cnoid::Selection::size
int size() const
Definition: Selection.h:23
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Selection::which
int which() const
Definition: Selection.h:63