Optimized instances size on disk.
[tpot/pegasus/.git] / src / Pegasus / Common / CIMObjectRep.cpp
1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "CIMObjectRep.h"
30
31 PEGASUS_USING_STD;
32
33 PEGASUS_NAMESPACE_BEGIN
34
35 CIMObjectRep::CIMObjectRep(const CIMReference& reference)
36     : _reference(reference), _resolved(false)
37 {
38 }
39
40 CIMObjectRep::~CIMObjectRep()
41 {
42
43 }
44
45 void CIMObjectRep::addProperty(const CIMProperty& x)
46 {
47     if (!x)
48         throw UnitializedHandle();
49
50     // Reject duplicate property names:
51
52     if (findProperty(x.getName()) != PEG_NOT_FOUND)
53         throw AlreadyExists();
54
55     // Append property:
56
57     _properties.append(x);
58 }
59
60 Uint32 CIMObjectRep::findProperty(const String& name)
61 {
62     for (Uint32 i = 0, n = _properties.size(); i < n; i++)
63     {
64         if (CIMName::equal(_properties[i].getName(), name))
65             return i;
66     }
67
68     return PEG_NOT_FOUND;
69 }
70
71 Boolean CIMObjectRep::existsProperty(const String& name)
72 {
73     return (findProperty(name) == PEG_NOT_FOUND) ? false : true;
74 }
75
76 CIMProperty CIMObjectRep::getProperty(Uint32 pos)
77 {
78     if (pos >= _properties.size())
79         throw OutOfBounds();
80
81     return _properties[pos];
82 }
83
84 void CIMObjectRep::removeProperty(Uint32 pos)
85     {
86         if (pos >= _properties.size())
87             throw OutOfBounds();
88
89         _properties.remove(pos);
90     }
91
92
93 Uint32 CIMObjectRep::getPropertyCount() const
94 {
95     return _properties.size();
96 }
97
98
99 CIMObjectRep::CIMObjectRep()
100 {
101
102 }
103
104 CIMObjectRep::CIMObjectRep(const CIMObjectRep& x) : 
105     Sharable(),
106     _reference(x._reference),
107     _resolved(x._resolved)
108 {
109     x._qualifiers.cloneTo(_qualifiers);
110
111     _properties.reserve(x._properties.size());
112
113     for (Uint32 i = 0, n = x._properties.size(); i < n; i++)
114         _properties.append(x._properties[i].clone(true));
115 }
116
117 Boolean CIMObjectRep::identical(const CIMObjectRep* x) const
118 {
119     if (!_reference.identical(x->_reference))
120         return false;
121
122     if (!_qualifiers.identical(x->_qualifiers))
123         return false;
124
125     // Compare properties:
126
127     {
128         const Array<CIMProperty>& tmp1 = _properties;
129         const Array<CIMProperty>& tmp2 = x->_properties;
130
131         if (tmp1.size() != tmp2.size())
132             return false;
133
134         for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
135         {
136             if (!tmp1[i].identical(tmp2[i]))
137                 return false;
138         }
139     }
140
141     if (_resolved != x->_resolved)
142         return false;
143
144     return true;
145 }
146
147 PEGASUS_NAMESPACE_END