summaryrefslogtreecommitdiffstats
path: root/odb/source-inmemory.h
blob: a88fc2e320ed5cd907b9307ff176040b7ace8e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef ODB_SOURCE_INMEMORY_H
#define ODB_SOURCE_INMEMORY_H

#include "odb/source.h"

struct oidtree;

/*
 * An in-memory source that you can write objects to that shall be made
 * available for reading, but that shouldn't ever be persisted to disk. Note
 * that any objects written to this source will be stored in memory, so the
 * number of objects you can store is limited by available system memory.
 */
struct odb_source_inmemory {
	struct odb_source base;
	struct oidtree *objects;
};

/* Create a new in-memory object database source. */
struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb);

/*
 * Cast the given object database source to the in-memory backend. This will
 * cause a BUG in case the source doesn't use this backend.
 */
static inline struct odb_source_inmemory *odb_source_inmemory_downcast(struct odb_source *source)
{
	if (source->type != ODB_SOURCE_INMEMORY)
		BUG("trying to downcast source of type '%d' to in-memory", source->type);
	return container_of(source, struct odb_source_inmemory, base);
}

#endif