Develop and Download Open Source Software

Browse CVS Repository

Contents of /jyugem/jyusecs/bee/b_object.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Sun Jun 20 15:23:39 2004 UTC (19 years, 9 months ago) by fukasawa
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
File MIME type: text/x-c++src
配列データのサポート。
BIG−ENDIAN形式のCPUへの対応。

1 // $Id: b_object.cpp,v 1.5 2003/03/02 04:12:45 fukasawa Exp $
2
3 //=============================================================================
4 /**
5 * @file b_object.cpp
6 *
7 * @author Fukasawa Mitsuo
8 *
9 *
10 * Copyright (C) 2001-2004 BEE Co.,Ltd. All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 //=============================================================================
27
28 #define BEE_BUILD_DLL
29
30 #include "b_objtype.h"
31 #include "b_object.h"
32 #include "b_attrdata.h"
33 #include "b_specification.h"
34
35 //-----------------------------------------------------------------------------
36 // Constructor/Destructor
37 //-----------------------------------------------------------------------------
38 b_object::b_object(b_objtype * cls, const BCHAR * name)
39 {
40 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::b_object");
41
42 m_objtype = cls;
43 if (name == NULL)
44 { // type + id
45 cls->makeObjID(m_name);
46 }
47 else
48 { // type + name
49 m_name = name;
50 }
51 m_spec = cls->typeName();
52 m_spec += _TX(":");
53 m_spec += m_name;
54
55 b_attributes::iterator iter = cls->m_attrs.begin();
56 for ( ; iter != cls->m_attrs.end(); iter++)
57 {
58 b_attribute * mbrattr = *iter;
59 b_attrdata * adata = mbrattr->instance(this);
60 m_values.push_back(adata);
61 if (mbrattr->name() == _TX("ObjType"))
62 {
63 b_value objtype(m_objtype->typeName());
64 adata->set(objtype);
65 }
66 else if (mbrattr->name() == _TX("ObjID"))
67 {
68 b_value objid(m_name.c_str());
69 adata->set(objid);
70 }
71 }
72
73 return ;
74 }
75
76 //-----------------------------------------------------------------------------
77 b_object::b_object(const b_object& rhs)
78 {
79 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::b_object");
80
81 this->copy(rhs);
82 return ;
83 }
84
85 //-----------------------------------------------------------------------------
86 b_object::~b_object()
87 {
88 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::~b_object");
89 AttrDataVect::iterator iter;
90 for (iter = m_values.begin(); iter != m_values.end(); iter++)
91 {
92 b_attrdata * data = *iter;
93 delete data;
94 }
95 m_objtype->remove(this);
96 }
97
98 //-----------------------------------------------------------------------------
99 // Copy
100 //-----------------------------------------------------------------------------
101 b_object& b_object::operator=(const b_object& rhs)
102 {
103 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::operator=");
104 if (this == &rhs)
105 return *this;
106 this->copy(rhs);
107 return *this;
108 }
109
110 //-----------------------------------------------------------------------------
111 void b_object::copy(const b_object& rhs)
112 {
113 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::copy");
114
115 m_objtype = rhs.m_objtype;
116 m_objtype->makeObjID(m_name);
117 m_spec = m_objtype->typeName();
118 m_spec += ":";
119 m_spec += m_name;
120
121 m_values.clear();
122 AttrDataVect::const_iterator iter;
123 for (iter = rhs.m_values.begin(); iter != rhs.m_values.end(); iter++)
124 {
125 b_attrdata * data = *iter;
126 b_attrdata * dest = new b_attrdata(*data);
127 m_values.push_back(dest);
128 }
129 }
130
131 //-----------------------------------------------------------------------------
132 // Set value at attribute
133 //-----------------------------------------------------------------------------
134 const b_attribute * b_object::findAttr(const string& name) const
135 {
136 TRACE_FUNCTION(TRL_LOW, "b_object::findAttr");
137 const b_attribute * result = m_objtype->find(name.c_str());
138 return result;
139 }
140
141 //-----------------------------------------------------------------------------
142 b_attrdata * b_object::findData(const string& name) const
143 {
144 TRACE_FUNCTION(TRL_LOW, "b_object::findData");
145
146 const b_attribute * attr = m_objtype->find(name.c_str());
147 if (attr == NULL)
148 {
149 return NULL;
150 }
151
152 return m_values[attr->position()];
153 }
154
155 //-----------------------------------------------------------------------------
156 b_attrdata * b_object::findDataByUser(const string& name) const
157 {
158 TRACE_FUNCTION(TRL_LOW, "b_object::findData");
159
160 const b_attribute * attr = m_objtype->findByUser(name);
161 if (attr == NULL)
162 {
163 return NULL;
164 }
165
166 return m_values[attr->position()];
167 }
168
169 //-----------------------------------------------------------------------------
170 // Set attribute data
171 //-----------------------------------------------------------------------------
172 int b_object::set(const b_object& rhs)
173 {
174 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::set");
175 BEEAssert(m_objtype == rhs.m_objtype);
176
177 for (size_t i = 0; i < rhs.m_values.size(); i++)
178 {
179 b_attrdata * srcdata = rhs.m_values[i];
180 b_attrdata * destdata = m_values[i];
181 destdata->set(srcdata->get());
182 //
183 // Don't check atribute name
184 //
185 }
186 return 0;
187 }
188
189 //-----------------------------------------------------------------------------
190 // Compare attribute data
191 //-----------------------------------------------------------------------------
192 bool b_object::isEqual(const b_object& rhs)
193 {
194 TRACE_FUNCTION(TRL_CONSTRUCT, "b_object::set");
195 BEEAssert(m_objtype == rhs.m_objtype);
196
197 bool result = true;
198 for (size_t i = 0; i < rhs.m_values.size(); i++)
199 {
200 b_attrdata * srcdata = rhs.m_values[i];
201 b_attrdata * destdata = m_values[i];
202 if (! (*srcdata == *destdata))
203 {
204 result = false;
205 }
206 }
207 return result;
208 }
209
210
211
212 //-----------------------------------------------------------------------------
213 // Dump
214 //-----------------------------------------------------------------------------
215 void b_object::dump() const
216 {
217 ACE_DEBUG((LM_DEBUG, ACE_TEXT("<object name=\"%s\" class=\"%s\">\n"),
218 m_name.c_str(), m_objtype->typeName()));
219 ACE_DEBUG((LM_DEBUG, ACE_TEXT(" <attrdata>\n")));
220 AttrDataVect::const_iterator iter;
221 for (iter = m_values.begin(); iter != m_values.end(); iter++)
222 {
223 const b_attrdata * data = *iter;
224 data->dump();
225 }
226 ACE_DEBUG((LM_DEBUG, ACE_TEXT(" </attrdata>\n</object>\n")));
227 }
228
229

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26