--- /dev/null
+#include <cstring>
+#include <msp/io/memory.h>
+#include "builtinsource.h"
+#include "collection.h"
+
+using namespace std;
+
+namespace Msp {
+namespace DataFile {
+
+void BuiltinSource::add_object(const string &name, const char *content, unsigned size)
+{
+ objects[name] = Object(content, size);
+}
+
+void BuiltinSource::add_object(const string &name, const char *content)
+{
+ add_object(name, content, strlen(content));
+}
+
+bool BuiltinSource::is_loadable(const CollectionItemTypeBase &, const string &name) const
+{
+ return objects.count(name);
+}
+
+CollectionSource::NameList BuiltinSource::get_names(const CollectionItemTypeBase &type) const
+{
+ NameList names;
+ for(ObjectMap::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+ if(type.match_name(i->first))
+ names.push_back(i->first);
+ return names;
+}
+
+void BuiltinSource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
+{
+ ObjectMap::const_iterator i = objects.find(name);
+ if(i!=objects.end())
+ {
+ IO::Memory in(i->second.data, i->second.size);
+ Parser parser(in, name);
+ type.load_item(coll, parser, name);
+ }
+}
+
+IO::Seekable *BuiltinSource::open(const string &name) const
+{
+ ObjectMap::const_iterator i = objects.find(name);
+ if(i!=objects.end())
+ return new IO::Memory(i->second.data, i->second.size);
+
+ return 0;
+}
+
+
+BuiltinSource::Object::Object():
+ data(0),
+ size(0)
+{ }
+
+BuiltinSource::Object::Object(const char *d, unsigned s):
+ data(d),
+ size(s)
+{ }
+
+} // namespace DataFile
+} // namespace Msp
--- /dev/null
+#ifndef MSP_DATAFILE_BUILTINSOURCE_H_
+#define MSP_DATAFILE_BUILTINSOURCE_H_
+
+#include "collectionsource.h"
+
+namespace Msp {
+namespace DataFile {
+
+class BuiltinSource: public CollectionSource
+{
+private:
+ struct Object
+ {
+ const char *data;
+ unsigned size;
+
+ Object();
+ Object(const char *, unsigned);
+ };
+
+ typedef std::map<std::string, Object> ObjectMap;
+
+ ObjectMap objects;
+
+public:
+ void add_object(const std::string &, const char *, unsigned);
+ void add_object(const std::string &, const char *);
+
+ virtual bool is_loadable(const CollectionItemTypeBase &, const std::string &) const;
+ virtual NameList get_names(const CollectionItemTypeBase &) const;
+ virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const;
+ virtual IO::Seekable *open(const std::string &) const;
+};
+
+} // namespace DataFile
+} // namespace Msp
+
+#endif