Raw
1 #ifndef ODB_SOURCE_INMEMORY_H
2 #define ODB_SOURCE_INMEMORY_H
3
4 #include "odb/source.h"
5
6 struct oidtree;
7
8 /*
9 * An in-memory source that you can write objects to that shall be made
10 * available for reading, but that shouldn't ever be persisted to disk. Note
11 * that any objects written to this source will be stored in memory, so the
12 * number of objects you can store is limited by available system memory.
13 */
14 struct odb_source_inmemory {
15 struct odb_source base;
16 struct oidtree *objects;
17 };
18
19 /* Create a new in-memory object database source. */
20 struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb);
21
22 /*
23 * Cast the given object database source to the in-memory backend. This will
24 * cause a BUG in case the source doesn't use this backend.
25 */
26 static inline struct odb_source_inmemory *odb_source_inmemory_downcast(struct odb_source *source)
27 {
28 if (source->type != ODB_SOURCE_INMEMORY)
29 BUG("trying to downcast source of type '%s' to '%s'",
30 odb_source_type_to_name(source->type),
31 odb_source_type_to_name(ODB_SOURCE_INMEMORY));
32 return container_of(source, struct odb_source_inmemory, base);
33 }
34
35 #endif