-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdobject.cpp
More file actions
99 lines (79 loc) · 2.62 KB
/
dobject.cpp
File metadata and controls
99 lines (79 loc) · 2.62 KB
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
#include "dobject.hpp"
#include "dstruct.hpp"
#include "dvalue.hpp"
#include "dnullobject.hpp"
#include "dexception.hpp"
#include "drealvalue.hpp"
namespace Destruct
{
DObject::DObject(DStruct* dstruct, DValue const& args) : RefcountPolicy(), __dstruct(dstruct), __baseObject(NULL)
{
if (dstruct && dstruct->base())
this->__baseObject = ((DStruct*)dstruct->base())->newObject(RealValue<DObject*>(this));
}
DObject::DObject(const DObject& copy) : __dstruct(copy.__dstruct), __baseObject(copy.__baseObject)
{
}
DStruct* DObject::instanceOf(void) const
{
return (this->__dstruct);
}
DStruct const * const DObject::base(void) const
{
return (this->__dstruct->base());
}
DObject::~DObject()
{
if (this->__baseObject)
this->__baseObject->destroy();
}
DObject* DObject::baseObject(void) const
{
return (this->__baseObject);
}
DValue DObject::getValue(DUnicodeString const& name) const
{
int32_t index = this->instanceOf()->findAttribute(name); //check not found
if (index != -1)
return (this->getValue(index));
throw DException(this->instanceOf()->name() + "::getValue instance has no attribute " + name);
}
void DObject::setValue(DUnicodeString const& name, DValue const& v)
{
int32_t index = this->instanceOf()->findAttribute(name); //check not found
if (index != -1)
return (this->setValue(index, v));
throw DException(this->instanceOf()->name() + "::setValue instance has no attribute " + name);
}
//template <typename RealType>
//DValue DObject::call(DUnicodeString const& name, RealType v)
//{
//int32_t index = this->instanceOf()->findAttribute(name);
//DValue value = RealValue<RealType>(v);
//if (index != -1)
//return (this->call((size_t)index, value));
//throw DException(this->instanceOf()->name() + "::call instance has no attribute " + name);
//}
DValue DObject::call(DUnicodeString const& name, DValue const& v) //const ? XXX : throw
{
int32_t index = this->instanceOf()->findAttribute(name);
if (index != -1)
return (this->call((size_t)index, v));
throw DException(this->instanceOf()->name() + "::call instance has no attribute " + name);
}
DValue DObject::call(DUnicodeString const& name) //const ? XXX : throw
{
int32_t index = this->instanceOf()->findAttribute(name);
if (index != -1)
return (this->call((size_t)index, RealValue<DObject*>(DNone)));
throw DException(this->instanceOf()->name() + "::call instance has no attribute " + name);
}
BaseValue* DObject::getBaseValue(DObject* dobject, size_t index)
{
return (dobject->getBaseValue(index));
}
BaseValue const* DObject::getBaseValue(DObject const* dobject, size_t index)
{
return (dobject->getBaseValue(index));
}
}