+ class ItemFactory
+ {
+ protected:
+ ItemFactory() { }
+ public:
+ virtual ~ItemFactory() { }
+
+ virtual void set_data(const ListData &) = 0;
+ virtual Item *create_item(unsigned) const = 0;
+ };
+
+ template<typename I>
+ class TypedItemFactory: public ItemFactory
+ {
+ private:
+ typedef typename I::ValueType ValueType;
+
+ const ListDataStore<ValueType> *data;
+
+ public:
+ TypedItemFactory(const ListData &d)
+ { set_data(d); }
+
+ virtual void set_data(const ListData &d)
+ {
+ if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
+ data = ds;
+ else
+ throw incompatible_data(typeid(ValueType));
+ }
+
+ virtual Item *create_item(unsigned i) const
+ {
+ return new I(data->get(i));
+ }
+ };
+