mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-03 06:12:43 -06:00
reorganizing repo
git-svn-id: svn://ultimatepp.org/upp/trunk@9206 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7d17505cfe
commit
e3e8d627f5
3840 changed files with 0 additions and 1161578 deletions
|
|
@ -1,97 +0,0 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
class Path {
|
||||
bool index;
|
||||
Value key;
|
||||
Value value;
|
||||
Path *parent;
|
||||
Value *target;
|
||||
|
||||
Path() { target = NULL; }
|
||||
|
||||
public:
|
||||
Path operator()(const Value& key);
|
||||
Path operator[](int i);
|
||||
void Set(const Value& key, const Value& v, bool ndx);
|
||||
void operator=(const Value& v) { value = v; parent->Set(key, v, index); }
|
||||
|
||||
Path(Value& v) { target = &v; value = v; parent = NULL; index = false; }
|
||||
};
|
||||
|
||||
Path Path::operator()(const Value& k)
|
||||
{
|
||||
Path p;
|
||||
ValueMap m;
|
||||
if(IsValueMap(value))
|
||||
m = value;
|
||||
p.parent = this;
|
||||
p.key = k;
|
||||
// DLOG("operator()(" << key << ": " << m[key]);
|
||||
p.value = m.GetAndClear(k); // Optimize!
|
||||
p.index = false;
|
||||
return p;
|
||||
}
|
||||
|
||||
Path Path::operator[](int i)
|
||||
{
|
||||
ASSERT(i >= 0);
|
||||
Path p;
|
||||
ValueArray va;
|
||||
if(IsValueArray(value))
|
||||
va = value;
|
||||
p.parent = this;
|
||||
p.key = i;
|
||||
p.index = true;
|
||||
if(i < va.GetCount())
|
||||
p.value = va.GetAndClear(i);
|
||||
p.index = true;
|
||||
return p;
|
||||
}
|
||||
|
||||
void Path::Set(const Value& k, const Value& v, bool ndx)
|
||||
{
|
||||
// DLOG("Set(" << k << ": " << v << "), current key: " << key << ", value: " << value);
|
||||
if(ndx) {
|
||||
ValueArray va;
|
||||
if(IsValueArray(value))
|
||||
va = value;
|
||||
va.Set((int)k, v);
|
||||
value = va;
|
||||
}
|
||||
else {
|
||||
ValueMap m;
|
||||
if(IsValueMap(value))
|
||||
m = value;
|
||||
m.Set(k, v);
|
||||
value = m;
|
||||
}
|
||||
if(parent)
|
||||
parent->Set(key, value, index);
|
||||
if(target)
|
||||
*target = value;
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
Value x;
|
||||
|
||||
Path(x)("hello")("world") = 555;
|
||||
DUMP(x);
|
||||
LOG("-------------------");
|
||||
Path(x)("hello")("you") = "this";
|
||||
DUMP(x);
|
||||
LOG("-------------------");
|
||||
Path(x)("hello")("x") = "y";
|
||||
DUMP(x);
|
||||
LOG("-------------------");
|
||||
for(int i = 0; i < 20; i++)
|
||||
Path(x)("hello")("array")[i] = i;
|
||||
DUMP(x);
|
||||
// Path p = Path(x)("hello")("array");
|
||||
// for(int i = 0; i < 20; i++)
|
||||
// p[i] = "*" + AsString(i);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue