WIP: attempt to define the object builder invocation chain

TODO still unresolved issues with the bootstrap.
Looks like we shall not initiate from the basic Rec(),
but reather require an explicit construction.
This commit is contained in:
Fischlurch 2015-07-04 03:39:53 +02:00
parent 8e990fc04d
commit d92878876a
3 changed files with 179 additions and 10 deletions

View file

@ -263,6 +263,39 @@ namespace diff{
/* === Specialisation to add fluent GenNode builder API to Record<GenNode> === */
template<>
inline GenNode&&
Rec::Mutator::genNode()
{
UNIMPLEMENTED("wrap newly built Record into a new GenNode instance");
}
template<>
inline GenNode&&
Rec::Mutator::genNode(string const& symbolicID)
{
UNIMPLEMENTED("wrap newly built Record into a new named GenNode instance");
}
template<>
template<typename...ARGS>
inline Rec::Mutator&
Rec::Mutator::attrib (ARGS&& ...args)
{
UNIMPLEMENTED("split sequence of arguments into key-value pairs and use these to populate the attributes collection");
}
template<>
template<typename...ARGS>
inline Rec::Mutator&
Rec::Mutator::scope (ARGS&& ...args)
{
UNIMPLEMENTED("split sequence of arguments and build GenNode instances from them, to populate scope collection");
}
/* === Specialisation for handling of attributes in Record<GenNode> === */ /* === Specialisation for handling of attributes in Record<GenNode> === */
template<> template<>

View file

@ -131,7 +131,6 @@ namespace diff{
class Record class Record
{ {
using _Vec = std::vector<VAL>; using _Vec = std::vector<VAL>;
using Attrib = std::pair<Symbol, VAL>;
using Attribs = _Vec; using Attribs = _Vec;
using Children = _Vec; using Children = _Vec;
@ -247,6 +246,44 @@ namespace diff{
/* ==== extension point for fluent builder API ====== */
// to initiate and open builder chain:
Mutator
type (string const& typeID)
{
return Mutator(*this).type(typeID);
}
template<typename...ARGS>
Mutator
attrib (ARGS&& ...args)
{
return Mutator(*this).attrib(std::forward<ARGS>(args)...);
}
template<typename...ARGS>
Mutator
scope (ARGS&& ...args)
{
return Mutator(*this).scope(std::forward<ARGS>(args)...);
}
// to close and finish builder chain (needs specialisation)
VAL&&
genNode()
{
return Mutator(*this).genNode();
}
VAL&&
genNode(string const& symbolicID)
{
return Mutator(*this).genNode(symbolicID);
}
/* ==== Exposing scope and contents for iteration ====== */ /* ==== Exposing scope and contents for iteration ====== */
using iterator = IterAdapter<typename _Vec::const_iterator, const Record*>; using iterator = IterAdapter<typename _Vec::const_iterator, const Record*>;
@ -354,6 +391,12 @@ namespace diff{
std::swap (existingInstance, record_); std::swap (existingInstance, record_);
} }
bool
empty() const
{
return record_.empty();
}
/* === functions to alter contents === */ /* === functions to alter contents === */
@ -364,29 +407,52 @@ namespace diff{
record_.type_ = newTypeID; record_.type_ = newTypeID;
} }
void Mutator&
type (string const& typeID)
{
setType (typeID);
return *this;
}
Mutator&
set (string const& key, VAL const& newValue) set (string const& key, VAL const& newValue)
{ {
///////////TODO; ///////////TODO;
return *this;
} }
void Mutator&
appendChild (VAL const& newChild) appendChild (VAL const& newChild)
{ {
record_.children_.push_back (newChild); record_.children_.push_back (newChild);
return *this;
} }
void Mutator&
prependChild (VAL const& newChild) prependChild (VAL const& newChild)
{ {
record_.children_.insert (record_.children_.begin(), newChild); record_.children_.insert (record_.children_.begin(), newChild);
return *this;
} }
bool
empty() const /* === extension point for building specific value types === */
{ /*
return record_.empty(); * the following builder functions are to be specialised
} * to create a Record holding specific value types,
* especially for building a tree like structure
* with GenNode holding a Record<GenNode>
*/
VAL&& genNode();
VAL&& genNode(string const& symbolicID);
template<typename...ARGS>
Mutator& attrib (ARGS&& ...);
template<typename...ARGS>
Mutator& scope (ARGS&& ...);
}; };

View file

@ -196,8 +196,78 @@
</body> </body>
</html></richcontent> </html></richcontent>
</node> </node>
<node CREATED="1435973418262" ID="ID_1847939996" MODIFIED="1435973701272">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
Object <b>builder</b>
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="pencil"/>
<node CREATED="1435973448902" ID="ID_1729239555" MODIFIED="1435973564507" TEXT="wie definieren">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
Problem ist, wir definieren den Typ Record generisch,
</p>
<p>
verwenden dann aber nur die spezialisierung Record&lt;GenNode&gt;
</p>
<p>
Und die Builder-Funktionen brauchen eigentlich spezielles Wissen &#252;ber den zu konstruierenden Zieltyp
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="help"/>
</node> </node>
<node CREATED="1434128179406" ID="ID_1833179523" MODIFIED="1434129153311" TEXT="Referez"> <node CREATED="1435973566277" ID="ID_1320441333" MODIFIED="1435973686783">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
Ergebnis move
</p>
<p>
<font size="1">pro / contra</font>
</p>
</body>
</html>
</richcontent>
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
Move ist <b>gef&#228;hrlich </b>
</p>
<p>
aber auch deutlich effizienter,
</p>
<p>
denn wir m&#252;ssen sonst das ganze erzeugte Ergebnis einmal kopieren.
</p>
<p>
Nicht sicher, ob der Optimiser das hinbekommt
</p>
</body>
</html>
</richcontent>
</node>
</node>
</node>
<node CREATED="1434128179406" HGAP="25" ID="ID_1833179523" MODIFIED="1435973696882" TEXT="Referez" VSHIFT="13">
<icon BUILTIN="pencil"/> <icon BUILTIN="pencil"/>
<node CREATED="1434129158157" ID="ID_1777328498" MODIFIED="1434129165457" TEXT="sicher dereferenzierbar"> <node CREATED="1434129158157" ID="ID_1777328498" MODIFIED="1434129165457" TEXT="sicher dereferenzierbar">
<node CREATED="1434205928410" ID="ID_733269570" MODIFIED="1434205947253" TEXT="entweder zwangsweise gebunden"/> <node CREATED="1434205928410" ID="ID_733269570" MODIFIED="1434205947253" TEXT="entweder zwangsweise gebunden"/>