]> git.tdb.fi Git - r2c2.git/blob - source/designer/selection.h
Remove a queued block reservation if the block is released
[r2c2.git] / source / designer / selection.h
1 #ifndef SELECTION_H_
2 #define SELECTION_H_
3
4 #include <set>
5 #include <sigc++/sigc++.h>
6 #include "libr2c2/object.h"
7
8 class Selection
9 {
10 public:
11         sigc::signal<void> signal_changed;
12
13 private:
14         std::set<R2C2::Object *> objects;
15
16 public:
17         const std::set<R2C2::Object *> &get_objects() const { return objects; }
18         R2C2::Object *get_object() const;
19
20         template<typename T>
21         std::set<T *> get_objects() const
22         {
23                 std::set<T *> result;
24                 for(std::set<R2C2::Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
25                         if(T *to = dynamic_cast<T *>(*i))
26                                 result.insert(to);
27                 return result;
28         }
29
30         template<typename T>
31         T *get_object() const
32         {
33                 for(std::set<R2C2::Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
34                         if(T *to = dynamic_cast<T *>(*i))
35                                 return to;
36                 return 0;
37         }
38
39         unsigned size() const { return objects.size(); }
40         bool empty() const { return objects.empty(); }
41
42         void clear();
43
44         template<typename Iter>
45         void replace(Iter begin, Iter end)
46         {
47                 objects.clear();
48                 objects.insert(begin, end);
49                 signal_changed.emit();
50         }
51
52         void add_object(R2C2::Object *);
53         void remove_object(R2C2::Object *);
54         void toggle_object(R2C2::Object *);
55
56         void select_more();
57         void select_linked();
58         void select_blocks();
59 };
60
61 #endif