#ifndef MSP_GLTK_LIST_H_
#define MSP_GLTK_LIST_H_
+#include <memory>
#include <stdexcept>
#include <typeinfo>
#include <sigc++/signal.h>
{
public:
Loader(List &);
+
private:
void item(const std::string &);
};
virtual ~ItemFactory() = default;
virtual void set_data(const ListData &) = 0;
- virtual Item *create_item(std::size_t) const = 0;
+ virtual std::unique_ptr<Item> create_item(std::size_t) const = 0;
};
template<typename I>
const ListDataStore<ValueType> *data;
public:
- TypedItemFactory(const ListData &d)
- { set_data(d); }
+ TypedItemFactory(const ListData &d) { set_data(d); }
void set_data(const ListData &d) override
{
throw incompatible_data(typeid(ValueType));
}
- Item *create_item(std::size_t i) const override
+ std::unique_ptr<Item> create_item(std::size_t i) const override
{
- return new I(data->get(i));
+ return std::make_unique<I>(data->get(i));
}
};
sigc::signal<void> signal_selection_cleared;
private:
+ std::unique_ptr<ListData> own_data;
ListData *data = nullptr;
- bool own_data = false;
- DataObserver *observer = nullptr;
- ItemFactory *item_factory = nullptr;
+ std::unique_ptr<DataObserver> observer = nullptr;
+ std::unique_ptr<ItemFactory> item_factory = nullptr;
ViewMode view_mode = LIST;
std::size_t sel_index = INVALID_INDEX;
std::size_t focus_index = INVALID_INDEX;
int drag_start_y = 0;
VSlider slider;
- std::vector<Item *> items;
+ std::vector<std::unique_ptr<Item>> items;
std::vector<Row> rows;
+ List(std::unique_ptr<ListData>);
public:
List();
List(ListData &);
- virtual ~List();
const char *get_class() const override { return "list"; }
public:
template<typename I>
- void set_item_type()
- {
- ItemFactory *f = new TypedItemFactory<I>(*data);
- delete item_factory;
- item_factory = f;
- }
+ void set_item_type() { item_factory = std::make_unique<TypedItemFactory<I>>(*data); }
private:
- Item *create_item(std::size_t);
+ std::unique_ptr<Item> create_item(std::size_t);
public:
void set_view_mode(ViewMode);