Record "object" representation now finished and passes Test

This commit is contained in:
Fischlurch 2015-08-17 22:13:36 +02:00
parent 0bff4f21d5
commit a56226f297
3 changed files with 66 additions and 27 deletions

View file

@ -47,11 +47,13 @@
** - the parts or \em realms within this symbolic representation are distinguished
** by convention solely
**
** * metadata is very limited and boils down to magic attributes known by name
** * metadata is very limited and boils down to a type attribute known by name
** * children (scope contents) can be recognised by \em not bearing a name
**
** Record entities are meant to be immutable. The proper way to alter a Record is
** to apply a \link tree-diff.hpp diff \endlink
** to apply a \link tree-diff.hpp diff \endlink. Yet for the \em implementation
** of this diff handling, a Record::Mutator is provided, to allow controlled
** partial re-building of a given data element.
**
** \par rationale
** The underlying theme of this design is negative, dialectical: we do not want to
@ -62,7 +64,7 @@
** which is to exchange diff messages drawn against a symbolic representation
** of a typed object tree. Especially, we assume that there is only a small
** number of attributes (so linear search for access by key is adequate).
** - moreover, we assume that the value type allows to somehow to embed
** - moreover, we assume that the value type allows for somehow embedding
** the key of each attribute; the implementation needs an explicit
** specialisation of the binding functions for each value type.
** - this header defines a specialisation for VAL = std::string --
@ -483,7 +485,7 @@ namespace diff{
/**
* wrapped record reference.
* A helper for lib::GenNode and the diff representation.
* RecordRef is copyable and assignable, but like a reference
* RecordRef is copyable and movable, but like a reference
* can not be rebound. It can be used to refer to a subtree
* within the diff representation, without the need to copy.
* @remarks this is almost identical to std::ref, with the
@ -497,7 +499,7 @@ namespace diff{
using Target = Record<VAL>;
Target* record_;
public:
/** by default create an
* invalid ("bottom") reference */
@ -640,7 +642,7 @@ namespace diff{
{
return string(key + " = " + extractVal(payload));
}

View file

@ -26,10 +26,8 @@
#include "lib/format-util.hpp"
#include "lib/diff/record.hpp"
#include "lib/itertools.hpp"
#include "lib/util.hpp" //////TODO necessary?
#include <iostream>
//#include <utility>
#include <string>
#include <vector>
@ -38,7 +36,7 @@ using util::isSameObject;
using util::isnil;
using util::join;
using std::vector;
//using std::swap;
using std::swap;
using std::cout;
using std::endl;
@ -47,7 +45,6 @@ namespace lib {
namespace diff{
namespace test{
// using lumiera::error::LUMIERA_ERROR_LOGIC;
using lumiera::error::LUMIERA_ERROR_INVALID;
using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE;
@ -92,10 +89,37 @@ namespace test{
/*************************************************************************************//**
* @test Verify properties of a special collection type meant for external representation
* of object-like data.
* of object-like data, especially for symbolic representation in diff messages.
* - there is a type meta attribute
* - a Record can have attributes (by key) and contents (ordered list of values)
* - various kinds of iterators are provided
* - besides the regular constructor, which explicitly takes a type, a collection
* of attributes, and a collection of contents, there is a convenience constructor
* especially for literal notation and data definition. This one figures out the
* break between attributes and contents automatically; a type meta attribute
* is recognised and the first element without a given key or ID ends the
* attributes and starts the content scope
* - Record elements are conceived as values and equality is defined in terms
* of their contents, including the order (no normalisation, no sorting)
* - they are \em immutable after construction. But we provide a Mutator
* for remoulding a given element, enabling object builder notation.
* - a reference wrapper for handling of large structures is provided.
* @remarks this test uses the specialisation \c Record<string> solely, to cover the
* basic properties and behaviour, while leaving out the complexities of specific
* payload data types. For the actual use case, the symbolic description of
* data structure differences, we use a specific "value" within Record,
* the diff::GenNode, which is a limited typesafe Variant element, and in
* turn allows Record<GenNode> as embedded payload. Effectively this creates
* a "recursive data type", which is key to typesafe functional processing of
* unlimited data structures. The design of diff::Record only makes sense with
* this use case in mind; most notably, we have the keys (attribute names)
* embedded within the value payload, which turns attributes into just another
* content scope with special access operations. This also explains, why we
* do not normalise the content in any way; content is meant to reflect
* other data structures, which are normalised and maintained by their owner.
*
* @see IndexTable
* @see DiffListApplication_test
* @see GenNodeBasic_test
* @see tree-diff.cpp
*/
class GenericRecordRepresentation_test : public Test
{
@ -131,10 +155,10 @@ namespace test{
CHECK (enterprise.hasAttribute("Owner"));
CHECK (!enterprise.hasAttribute("owner"));
CHECK (!enterprise.hasAttribute("Owner "));
CHECK (!enterprise.hasAttribute("Owner ")); // no normalisation
CHECK (enterprise.contains("Data"));
CHECK (!enterprise.contains("Woof"));
CHECK (!enterprise.contains("Woof")); // it is /Worf/, madam
CHECK (util::contains (enterprise, "Worf"));
VERIFY_ERROR (INVALID, enterprise.get("warp10"));
@ -231,6 +255,7 @@ namespace test{
RecS aaa({"a","a"});
RecS ax({"type=a","a"});
RecS ay({"a=a","a"});
RecS az({"a =a","a"});
CHECK (a != aa); CHECK (aa != a);
CHECK (aa != aaa); CHECK (aaa != aa);
@ -239,7 +264,9 @@ namespace test{
CHECK (a != ay); CHECK (ay != a);
CHECK (ax != ay); CHECK (ay != ax);
CHECK (aaa != ay); CHECK (ay != aaa);
CHECK (ay != az); CHECK (az != ay); // NOTE: attributes are *not* normalised,
// rather, they are used as-is,
// thus "a=a" != "a =a"
RecS a2({"a","aa"});
CHECK (aa == a2); CHECK (a2 == aa);

View file

@ -32,7 +32,8 @@
<node CREATED="1434128170381" ID="ID_976705384" MODIFIED="1435943245803" TEXT="GenNode">
<linktarget COLOR="#ff0033" DESTINATION="ID_976705384" ENDARROW="Default" ENDINCLINATION="10;45;" ID="Arrow_ID_1285375088" SOURCE="ID_553361956" STARTARROW="Default" STARTINCLINATION="-13;-67;"/>
<node CREATED="1435421658394" ID="ID_1938259420" MODIFIED="1435421666963" TEXT="ID">
<node CREATED="1435421670349" ID="ID_1358247529" MODIFIED="1435421676200" TEXT="verwende EntryID">
<node CREATED="1435421670349" FOLDED="true" ID="ID_1358247529" MODIFIED="1439842301216" TEXT="verwende EntryID">
<icon BUILTIN="button_ok"/>
<node CREATED="1435421678004" ID="ID_691179282" MODIFIED="1435421687224" TEXT="Abh&#xe4;ngigkeitsprobleme">
<node CREATED="1435421693260" ID="ID_1314021887" MODIFIED="1435942753226" TEXT="generische ID-Funktionen">
<icon BUILTIN="button_ok"/>
@ -50,6 +51,7 @@
</node>
</node>
</node>
<node CREATED="1439842285584" ID="ID_334339765" MODIFIED="1439842291292" TEXT="spezielle Ref-IDs"/>
</node>
<node CREATED="1434128174030" ID="ID_1395250463" MODIFIED="1434128176521" TEXT="Variant">
<node CREATED="1435943070542" FOLDED="true" ID="ID_949070153" MODIFIED="1436042653604" TEXT="Wert-Semantik">
@ -185,8 +187,10 @@
<icon BUILTIN="help"/>
</node>
</node>
<node CREATED="1434128176918" ID="ID_863330674" MODIFIED="1434128195333" TEXT="Record">
<node CREATED="1434128198957" FOLDED="true" ID="ID_1224215957" MODIFIED="1436042755923" TEXT="Konstuktor">
<node CREATED="1434128176918" FOLDED="true" ID="ID_863330674" MODIFIED="1439842253318" TEXT="Record">
<icon BUILTIN="button_ok"/>
<node CREATED="1434128198957" FOLDED="true" ID="ID_1224215957" MODIFIED="1439842227325" TEXT="Konstuktor">
<icon BUILTIN="button_ok"/>
<node CREATED="1434421381345" ID="ID_752165044" MODIFIED="1436042396321" TEXT="DSL zur Daten-Definition">
<icon BUILTIN="button_ok"/>
</node>
@ -315,12 +319,12 @@
</node>
</node>
</node>
<node CREATED="1436042774669" ID="ID_714336641" MODIFIED="1436924649059" TEXT="Implementierung">
<icon BUILTIN="pencil"/>
<node CREATED="1436042774669" ID="ID_714336641" MODIFIED="1439842202322" TEXT="Implementierung">
<icon BUILTIN="button_ok"/>
<node CREATED="1436042783700" ID="ID_381817780" MODIFIED="1436042788584" TEXT="zwei Collections"/>
<node CREATED="1436042814044" ID="ID_1455779230" MODIFIED="1436042818312" TEXT="aber semantisch eine Liste"/>
<node CREATED="1436924462201" ID="ID_1369837914" MODIFIED="1436924596628" TEXT="Probleme">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1436924462201" FOLDED="true" ID="ID_1369837914" MODIFIED="1439842208565" TEXT="Probleme">
<icon BUILTIN="button_ok"/>
<node CREATED="1436924502056" ID="ID_1085481788" MODIFIED="1439826939611" TEXT="R&#xfc;ckgabetyp von Attribut-Gettern">
<richcontent TYPE="NOTE"><html>
<head>
@ -466,7 +470,8 @@
</node>
</node>
</node>
<node CREATED="1434128179406" HGAP="25" ID="ID_1833179523" MODIFIED="1436042759827" TEXT="Referez" VSHIFT="13">
<node CREATED="1434128179406" FOLDED="true" HGAP="25" ID="ID_1833179523" MODIFIED="1439842219059" TEXT="Referez" VSHIFT="13">
<icon BUILTIN="button_ok"/>
<node CREATED="1434129158157" FOLDED="true" ID="ID_1777328498" MODIFIED="1439827103583" TEXT="sicher dereferenzierbar">
<node CREATED="1434205928410" ID="ID_733269570" MODIFIED="1434205947253" TEXT="entweder zwangsweise gebunden"/>
<node CREATED="1434205947841" ID="ID_871233558" MODIFIED="1434205955964" TEXT="oder NULL-Zustand mit Exception"/>
@ -518,7 +523,7 @@
</node>
</node>
<node CREATED="1434128128869" ID="ID_244966341" MODIFIED="1434128131785" TEXT="Verben">
<node CREATED="1434128134508" ID="ID_553361956" MODIFIED="1435943245803" TEXT="ID-Repr&#xe4;s">
<node CREATED="1434128134508" FOLDED="true" ID="ID_553361956" MODIFIED="1439842248575" TEXT="ID-Repr&#xe4;s">
<arrowlink COLOR="#ff0033" DESTINATION="ID_976705384" ENDARROW="Default" ENDINCLINATION="10;45;" ID="Arrow_ID_1285375088" STARTARROW="Default" STARTINCLINATION="-13;-67;"/>
<node CREATED="1434128393429" ID="ID_1275202366" MODIFIED="1434128584214" TEXT="mu&#xdf; GenNode sein">
<icon BUILTIN="idea"/>
@ -752,7 +757,7 @@
</node>
</node>
</node>
<node CREATED="1437693678626" ID="ID_1536988357" MODIFIED="1437693685381" POSITION="left" TEXT="Doku">
<node CREATED="1437693678626" FOLDED="true" ID="ID_1536988357" MODIFIED="1439842398635" POSITION="left" TEXT="Doku">
<node CREATED="1437693687650" ID="ID_1484874437" MODIFIED="1437693692821" TEXT="Sound-Systeme">
<node CREATED="1437693693617" ID="ID_955932218" LINK="https://wiki.debian.org/Sound" MODIFIED="1437693739404" TEXT="siehe die Debian-&#xdc;bersichtsseite">
<richcontent TYPE="NOTE"><html>
@ -768,7 +773,8 @@
</node>
</node>
</node>
<node CREATED="1439176872457" HGAP="15" ID="ID_355008543" MODIFIED="1439176884431" POSITION="left" TEXT="Plattform" VSHIFT="41">
<node CREATED="1439176872457" FOLDED="true" HGAP="15" ID="ID_355008543" MODIFIED="1439842393308" POSITION="left" TEXT="Plattform" VSHIFT="41">
<icon BUILTIN="go"/>
<node CREATED="1439176875682" HGAP="36" ID="ID_1487331591" MODIFIED="1439176889180" TEXT="Debian/Jessie" VSHIFT="42">
<node CREATED="1439176890840" FOLDED="true" ID="ID_170863947" MODIFIED="1439644328498" TEXT="Probleme">
<icon BUILTIN="button_ok"/>
@ -1178,6 +1184,10 @@
<icon BUILTIN="bell"/>
</node>
</node>
<node CREATED="1439842359711" FOLDED="true" ID="ID_1982964862" MODIFIED="1439842388500" TEXT="Paket">
<icon BUILTIN="messagebox_warning"/>
<node CREATED="1439842379420" ID="ID_1336697213" MODIFIED="1439842385655" TEXT="gtk-Abh&#xe4;ngigkeiten"/>
</node>
</node>
</node>
</map>