Generic Record: reorganise type configuration
this solves the problem how to deal with value access - for the simple default (string) implementation, we use a 'key = val' syntax and thus have to split strings, which means we need to return contents by value - for the actual relevant use case we have GenNode entries, which may recursively hold further Records. For dealing with diff messages over this data struture, its a good idea to allow for const& value access (otherwise we'd end up copying large subtrees for trivial operaions)
This commit is contained in:
parent
61b6868bff
commit
657f0031f4
3 changed files with 49 additions and 14 deletions
|
|
@ -122,6 +122,21 @@ namespace diff{
|
|||
|
||||
struct GenNode;
|
||||
|
||||
/** Define actual data storage and access types used */
|
||||
template<>
|
||||
struct RecordSetup<GenNode>
|
||||
{
|
||||
using Storage = std::vector<GenNode>;
|
||||
using ElmIter = typename Storage::const_iterator;
|
||||
|
||||
/** using const reference data access
|
||||
* relevant for handling large subtrees */
|
||||
using Access = GenNode const&;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
using Rec = Record<GenNode>;
|
||||
using RecRef = RecordRef<GenNode>;
|
||||
using MakeRec = Rec::Mutator;
|
||||
|
|
@ -382,7 +397,7 @@ namespace diff{
|
|||
}
|
||||
|
||||
template<>
|
||||
inline GenNode
|
||||
inline GenNode const&
|
||||
Rec::extractVal (GenNode const& v)
|
||||
{
|
||||
return GenNode(v); ///TODO
|
||||
|
|
|
|||
|
|
@ -106,6 +106,8 @@ namespace diff{
|
|||
|
||||
using std::string;
|
||||
|
||||
template<typename VAL>
|
||||
struct RecordSetup;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -129,14 +131,14 @@ namespace diff{
|
|||
template<typename VAL>
|
||||
class Record
|
||||
{
|
||||
using _Vec = std::vector<VAL>;
|
||||
using Attribs = _Vec;
|
||||
using Children = _Vec;
|
||||
using ElmIter = typename _Vec::const_iterator;
|
||||
using Storage = typename RecordSetup<VAL>::Storage;
|
||||
using ElmIter = typename RecordSetup<VAL>::ElmIter;
|
||||
using Access = typename RecordSetup<VAL>::Access;
|
||||
|
||||
|
||||
string type_;
|
||||
Attribs attribs_;
|
||||
Children children_;
|
||||
Storage attribs_;
|
||||
Storage children_;
|
||||
|
||||
public:
|
||||
Record()
|
||||
|
|
@ -209,7 +211,7 @@ namespace diff{
|
|||
return util::contains (children_, val);
|
||||
}
|
||||
|
||||
VAL const&
|
||||
Access
|
||||
get (string key) const
|
||||
{
|
||||
ElmIter found = findKey (key);
|
||||
|
|
@ -250,10 +252,10 @@ namespace diff{
|
|||
|
||||
/* ==== Exposing scope and contents for iteration ====== */
|
||||
|
||||
using iterator = IterAdapter<typename _Vec::const_iterator, const Record*>;
|
||||
using scopeIter = typename iter_stl::_SeqT<const _Vec>::Range;
|
||||
using iterator = IterAdapter<ElmIter, const Record*>;
|
||||
using scopeIter = typename iter_stl::_SeqT<const Storage>::Range;
|
||||
using keyIter = TransformIter<scopeIter, string>;
|
||||
using valIter = TransformIter<scopeIter, VAL>;
|
||||
using valIter = TransformIter<scopeIter, Access>;
|
||||
|
||||
/** default iteration exposes all data within this "object", starting with the attributes */
|
||||
iterator begin () const { return iterator(this, attribs_.begin()); }
|
||||
|
|
@ -308,7 +310,7 @@ namespace diff{
|
|||
static VAL buildTypeAttribute (string const& typeID);
|
||||
static string renderAttribute (VAL const& a);
|
||||
static string extractKey (VAL const& v);
|
||||
static VAL extractVal (VAL const& v);
|
||||
static Access extractVal (VAL const& v);
|
||||
|
||||
|
||||
ElmIter
|
||||
|
|
@ -421,7 +423,7 @@ namespace diff{
|
|||
|
||||
/* === extension point for building specific value types === */
|
||||
/*
|
||||
* the following builder functions are to be specialised
|
||||
* the following builder functions need to be specialised
|
||||
* to create a Record holding specific value types,
|
||||
* especially for building a tree like structure
|
||||
* with GenNode holding a Record<GenNode>
|
||||
|
|
@ -533,8 +535,24 @@ namespace diff{
|
|||
|
||||
|
||||
|
||||
/* === Extension point: Specialisations for attribute handling === */
|
||||
|
||||
/* === Specialisations to define the handling of attributes === */
|
||||
/**
|
||||
* Type configuration (extension point).
|
||||
* Data storage and access types.
|
||||
*/
|
||||
template<>
|
||||
struct RecordSetup<string>
|
||||
{
|
||||
using Storage = std::vector<string>;
|
||||
using ElmIter = typename Storage::const_iterator;
|
||||
using Access = string; ///< data access by value copy
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/* default handling defined for Record<string> */
|
||||
|
||||
template<>
|
||||
inline string
|
||||
|
|
|
|||
|
|
@ -457,6 +457,8 @@ namespace lib {
|
|||
|
||||
/**
|
||||
* Iterator tool treating pulled data by a custom transformation (function)
|
||||
* @param IT source iterator
|
||||
* @param VAL result (output) type
|
||||
*/
|
||||
template<class IT, class VAL>
|
||||
class TransformIter
|
||||
|
|
|
|||
Loading…
Reference in a new issue