42 lines
970 B
C++
42 lines
970 B
C++
#ifndef INVENTORY_DBCONTAINER_HH_
|
|
#define INVENTORY_DBCONTAINER_HH_
|
|
#include "dbobjectvec.hh"
|
|
#include "dbobjectmap.hh"
|
|
#include "dbobjectptr.hh"
|
|
#include <memory>
|
|
#include <algorithm>
|
|
|
|
namespace inventory {
|
|
namespace datamodel {
|
|
|
|
template<class T, template<class> class Container>
|
|
using DBObjectInserter =
|
|
std::function<void(datamodel::DBObjectPtr<T>, Container<T> &)>;
|
|
|
|
template<class T, template<class> class Container>
|
|
class DBObjectInserterImpl {};
|
|
|
|
template<class T>
|
|
class DBObjectInserterImpl<T, DBObjectVector> {
|
|
public:
|
|
static void inserter(DBObjectPtr<T> el, DBObjectVector<T> &c) {
|
|
c.push_back(el);
|
|
}
|
|
};
|
|
|
|
template<class T>
|
|
class DBObjectInserterImpl<T, DBObjectMap> {
|
|
public:
|
|
static void inserter(DBObjectPtr<T> el, DBObjectMap<T> &c) {
|
|
c.insert(std::make_pair((int)(el->id), el));
|
|
}
|
|
};
|
|
|
|
template<class T, template<class> class Container = DBObjectVector>
|
|
using DBContainerPtr = std::shared_ptr<Container<T>>;
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|