Generic Record: finish basic implementation

This commit is contained in:
Fischlurch 2015-08-17 03:59:53 +02:00
parent 657f0031f4
commit 0cde55a67f
4 changed files with 37 additions and 23 deletions

View file

@ -382,13 +382,6 @@ namespace diff{
return "todo"; ////TODO
}
template<>
inline GenNode
Rec::buildTypeAttribute (string const& typeID)
{
return GenNode("type", typeID);
}
template<>
inline string
Rec::extractKey (GenNode const& v)

View file

@ -167,10 +167,11 @@ namespace diff{
{
auto p = std::begin(con);
auto e = std::end(con);
if (p!=e && isTypeID (*p))
type_ = extractTypeID(*(p++));
for ( ; p!=e && isAttribute(*p); ++p)
attribs_.push_back (*p);
if (isTypeID (*p))
type_ = extractTypeID(*p);
else
attribs_.push_back (*p);
for ( ; p!=e; ++p)
children_.push_back (*p);
}
@ -307,7 +308,6 @@ namespace diff{
static bool isAttribute (VAL const& v);
static bool isTypeID (VAL const& v);
static string extractTypeID (VAL const& v);
static VAL buildTypeAttribute (string const& typeID);
static string renderAttribute (VAL const& a);
static string extractKey (VAL const& v);
static Access extractVal (VAL const& v);
@ -388,7 +388,6 @@ namespace diff{
void
setType (string const& newTypeID)
{
set ("type", Rec::buildTypeAttribute (newTypeID));
record_.type_ = newTypeID;
}
@ -595,14 +594,7 @@ namespace diff{
inline string
Record<string>::extractTypeID (string const& v)
{
return "todo"; //////////////////////////////////////////TODO do we really need this function?
}
template<>
inline string
Record<string>::buildTypeAttribute (string const& typeID)
{
return "type = "+typeID;
return extractVal(v);
}
template<>
@ -629,7 +621,7 @@ namespace diff{
return "Rec("
+ join (transformIterator (this->attribs(), renderAttribute))
+ "|{"
+ " |{"
+ join (this->scope())
+ "})"
;

View file

@ -214,7 +214,31 @@ return: 0
END
PLANNED "GenericRecordRepresentation_test" GenericRecordRepresentation_test <<END
TEST "Generic Object Record" GenericRecordRepresentation_test <<END
out-lit: enterprise = Rec(Name = USS Enterprise, Registry = NCC-1701-D, Class = Galaxy, Owner = United Federation of Planets, Operator = Starfleet, built = 2363 |{Picard, Riker, Data, Troi, Worf, Crusher, La Forge})
out-lit: Name = USS Enterprise
out-lit: Registry = NCC-1701-D
out-lit: Class = Galaxy
out-lit: Owner = United Federation of Planets
out-lit: Operator= Starfleet
out-lit: built=2363
out-lit: Picard
out-lit: Riker
out-lit: Data
out-lit: Troi
out-lit: Worf
out-lit: Crusher
out-lit: La Forge
out-lit: --Attributes--
out-lit: Name = USS Enterprise
out-lit: Registry = NCC-1701-D
out-lit: Class = Galaxy
out-lit: Owner = United Federation of Planets
out-lit: Operator= Starfleet
out-lit: built=2363
out-lit: --Keys--->Name<->Registry<->Class<->Owner<->Operator<->built
out-lit: --Vals--->USS Enterprise<->NCC-1701-D<->Galaxy<->United Federation of Planets<->Starfleet<->2363
out-lit: --Crew--->Picard | Riker | Data | Troi | Worf | Crusher | La Forge
return: 0
END

View file

@ -36,6 +36,7 @@
using std::string;
using util::isSameObject;
using util::isnil;
using util::join;
using std::vector;
//using std::swap;
using std::cout;
@ -119,6 +120,7 @@ namespace test{
,"Registry = NCC-1701-D"
,"Class = Galaxy"
,"Owner = United Federation of Planets"
,"Operator= Starfleet"
,"built=2363"
})
, strings ({"Picard", "Riker", "Data", "Troi", "Worf", "Crusher", "La Forge"})
@ -139,8 +141,11 @@ namespace test{
cout << "enterprise = " << string(enterprise)<<endl;
for (string elm : enterprise) cout << elm<<endl;
for (string mbr : enterprise.scope()) cout << mbr<<endl;
cout << "--Attributes--"<<endl;
for (string att : enterprise.attribs()) cout << att<<endl;
cout << "--Keys--->" << join (enterprise.keys(), "<->")<<endl;
cout << "--Vals--->" << join (enterprise.vals(), "<->")<<endl;
cout << "--Crew--->" << join (enterprise.scope()," | ")<<endl;
}