1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
//
// Copyright 2001-2008 Randal M. Henne, Greg Landrum and
// Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
//
#include "types.h"
#include <RDGeneral/Invariant.h>
using namespace RDKit;
using namespace std;
class DictCon{
public:
DictCon() { d.reset(); };
DictCon(const DictCon &other) {d = other.d;};
DictCon &operator=(const DictCon &other) { d= other.d; return *this;};
Dict *getDict() { return &d;};
private:
Dict d;
};
int main(){
RDLog::InitLogs();
Dict d;
INT_VECT fooV;
fooV.resize(3);
BOOST_LOG(rdInfoLog) << "dict test" << std::endl;
CHECK_INVARIANT(!d.hasVal("foo"),"bad init");
int x = 1;
d.setVal("foo", x);
CHECK_INVARIANT(d.hasVal("foo"),"should be there");
CHECK_INVARIANT(!d.hasVal("bar"),"bad other key");
int v,v2;
d.getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
v2=d.getVal<int>("foo");
CHECK_INVARIANT(v2==v,"bad val");
d.setVal("bar",fooV);
d.getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
v2=d.getVal<int>("foo");
CHECK_INVARIANT(v2==v,"bad val");
INT_VECT fooV2,fooV3;
d.getVal("bar",fooV2);
fooV3=d.getVal<INT_VECT>("bar");
CHECK_INVARIANT(fooV==fooV2,"bad getVal");
CHECK_INVARIANT(fooV2==fooV3,"bad getVal");
VECT_INT_VECT fooV4;
fooV4.resize(3);
CHECK_INVARIANT(!d.hasVal("baz"),"bad get");
d.setVal("baz",fooV4);
CHECK_INVARIANT(d.hasVal("baz"),"bad get");
DictCon dc1;
CHECK_INVARIANT(!dc1.getDict()->hasVal("foo"),"bad init");
int y = 1;
dc1.getDict()->setVal("foo",y);
CHECK_INVARIANT(dc1.getDict()->hasVal("foo"),"should be there");
CHECK_INVARIANT(!dc1.getDict()->hasVal("bar"),"bad other key");
dc1.getDict()->setVal("bar",fooV);
dc1.getDict()->getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
dc1.getDict()->getVal("bar",fooV2);
CHECK_INVARIANT(fooV==fooV2,"bad getVal");
fooV4.resize(3);
CHECK_INVARIANT(!dc1.getDict()->hasVal("baz"),"bad get");
dc1.getDict()->setVal("baz",fooV4);
CHECK_INVARIANT(dc1.getDict()->hasVal("baz"),"bad get");
dc1.getDict()->reset();
DictCon dc2=dc1;
CHECK_INVARIANT(!dc2.getDict()->hasVal("foo"),"bad init");
int z = 1;
dc2.getDict()->setVal("foo",z);
CHECK_INVARIANT(dc2.getDict()->hasVal("foo"),"should be there");
CHECK_INVARIANT(!dc2.getDict()->hasVal("bar"),"bad other key");
dc2.getDict()->setVal("bar",fooV);
dc2.getDict()->getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
dc2.getDict()->getVal("bar",fooV2);
CHECK_INVARIANT(fooV==fooV2,"bad getVal");
fooV4.resize(3);
CHECK_INVARIANT(!dc2.getDict()->hasVal("baz"),"bad get");
dc2.getDict()->setVal("baz",fooV4);
CHECK_INVARIANT(dc2.getDict()->hasVal("baz"),"bad get");
DictCon dc3(dc2);
CHECK_INVARIANT(dc3.getDict()->hasVal("foo"),"should be there");
dc3.getDict()->getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
dc3.getDict()->getVal("bar",fooV2);
CHECK_INVARIANT(fooV==fooV2,"bad getVal");
fooV4.resize(3);
CHECK_INVARIANT(dc3.getDict()->hasVal("baz"),"bad get");
CHECK_INVARIANT(dc3.getDict()->hasVal("foo"),"should be there");
dc3.getDict()->getVal("foo",v);
CHECK_INVARIANT(v==1,"bad val");
dc3.getDict()->getVal("bar",fooV2);
CHECK_INVARIANT(fooV==fooV2,"bad getVal");
fooV4.resize(3);
CHECK_INVARIANT(dc3.getDict()->hasVal("baz"),"bad get");
return 0;
}
|