1 #ifndef MSP_GLTK_LISTDATA_H_
2 #define MSP_GLTK_LISTDATA_H_
6 #include <sigc++/signal.h>
7 #include <msp/strings/lexicalcast.h>
15 sigc::signal<void, unsigned> signal_item_added;
16 sigc::signal<void, unsigned> signal_item_removed;
17 sigc::signal<void> signal_cleared;
18 sigc::signal<void> signal_refresh_strings;
23 virtual ~ListData() { }
25 virtual unsigned size() const = 0;
26 virtual std::string get_string(unsigned) const = 0;
27 void refresh_strings() const { signal_refresh_strings.emit(); }
31 class ListDataStore: public ListData
39 void append(const T &v) { insert(items.size(), v); }
41 void insert(unsigned i, const T & v)
44 throw std::out_of_range("ListDataStore::insert");
46 items.insert(items.begin()+i, v);
47 signal_item_added.emit(i);
50 const T &get(unsigned i) const
53 throw std::out_of_range("ListDataStore::get");
58 void remove(unsigned i)
61 throw std::out_of_range("ListDataStore::remove");
63 items.erase(items.begin()+i);
64 signal_item_removed.emit(i);
70 signal_cleared.emit();
73 virtual unsigned size() const { return items.size(); }
77 class BasicListData: public ListDataStore<T>
80 virtual std::string get_string(unsigned i) const
81 { return lexical_cast<std::string>(this->get(i)); }
85 class FunctionListData: public ListDataStore<T>
88 typedef std::string Func(const T &);
94 FunctionListData(Func f): func(f) { }
96 virtual std::string get_string(unsigned i) const
97 { return func(this->get(i)); }