Original Post
So I've taken a look at the Boost.Flyweight library and it seems quite nifty. I'm curious if it would be good for resource management though. For example, would a setup like the following be reasonable? (I did not try to compile this code; there are probably mistakes.) This would index resources by a unique ID. Coupled with a package system that assigns a unique ID to resources stored on disk, it looks like Boost.Flyweight would provide all the plumping for quick and easy lookup and management of those resources. What do you think? I'm interested in what people think about the library in general as well. Thanks.
class resource {
public:
typedef boost::uint_fast32_t id_type;
virtual ~resource();
id_type get_id() const;
private:
id_type id_;
};
struct resource_id_extractor {
resource::id_type operator()(const resource &r) const {
return r.get_id();
}
};
std::size_t hash_value(const resource &r) {
boost::hash<typename resource::id_type> hasher;
return hasher(r.get_id());
}
bool operator==(const resource &lhs, const resource &rhs) {
return lhs.get_id() == rhs.get_id();
}
typedef boost::flyweight<boost::key_value<typename resource::id_type, resource, resource_id_extractor> > resource_handle;
class texture : public resource {
};