Develop and Download Open Source Software

Browse CVS Repository

Contents of /jyugem/jyusecs/bee/b_attribute.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: +40 -22 lines
File MIME type: text/x-c++src
配列データのサポート。
BIG−ENDIAN形式のCPUへの対応。

1 // $Id: b_attribute.cpp,v 1.16 2003/03/15 04:35:30 fukasawa Exp $
2
3 //=============================================================================
4 /**
5 * @file b_attribute.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_attribute.h"
31 #include "b_objtype.h"
32 #include "b_object.h"
33 #include "b_specification.h"
34 #include "b_attrdata.h"
35
36 //-----------------------------------------------------------------------------
37 // Constructor/Destructor
38 //-----------------------------------------------------------------------------
39 b_attribute::b_attribute(const BCHAR * name, int type, size_t size, int mode,
40 bool nodel)
41 : m_name(name), m_userName(name), m_type(type), m_size(size),
42 m_position(0), m_mode(mode), m_nodel(nodel), m_enumerator(NULL)
43 {
44 TRACE_FUNCTION(TRL_CONSTRUCT, "b_attribute::b_attribute");
45
46 switch (type)
47 {
48 case ATOM_ASCII: m_init = ""; break;
49 case ATOM_BINARY: m_init.set((BYTE *)NULL, 0); break;
50 case ATOM_BOOLEAN: m_init = false; break;
51 case ATOM_INT1: m_init = (char)0; break;
52 case ATOM_INT2: m_init = (short)0; break;
53 case ATOM_INT4: m_init = (int)0; break;
54 case ATOM_INT8: m_init = (LONGLONG)0; break;
55 case ATOM_UINT1: m_init = (BYTE)0; break;
56 case ATOM_UINT2: m_init = (USHORT)0; break;
57 case ATOM_UINT4: m_init = (UINT)0; break;
58 case ATOM_UINT8: m_init = (ULONGLONG)0; break;
59 case ATOM_FLOAT4: m_init = (float)0.0; break;
60 case ATOM_FLOAT8: m_init = (double)0.0; break;
61 case ATOM_STRUCT:
62 {
63 b_valvect vv;
64 m_init = vv;
65 m_init.m_t = ATOM_STRUCT;
66 }
67 break;
68 case ATOM_VECTOR:
69 {
70 b_valvect vv;
71 m_init = vv;
72 m_init.m_t = ATOM_VECTOR;
73 }
74 break;
75 default:
76 break;
77 }
78 }
79
80 //-----------------------------------------------------------------------------
81 b_attribute::b_attribute(b_objtype& cls, const BCHAR * name, int type,
82 size_t size, int mode, bool nodel)
83 : m_name(name), m_userName(name), m_type(type), m_size(size),
84 m_position(0), m_mode(mode), m_nodel(nodel), m_enumerator(NULL)
85 {
86 TRACE_FUNCTION(TRL_CONSTRUCT, "b_attribute::b_attribute");
87
88 switch (type)
89 {
90 case ATOM_ASCII: m_init = ""; break;
91 case ATOM_BINARY: m_init.set((BYTE *)NULL, 0); break;
92 case ATOM_BOOLEAN: m_init = false; break;
93 case ATOM_INT1: m_init = (char)0; break;
94 case ATOM_INT2: m_init = (short)0; break;
95 case ATOM_INT4: m_init = (int)0; break;
96 case ATOM_INT8: m_init = (LONGLONG)0; break;
97 case ATOM_UINT1: m_init = (BYTE)0; break;
98 case ATOM_UINT2: m_init = (USHORT)0; break;
99 case ATOM_UINT4: m_init = (UINT)0; break;
100 case ATOM_UINT8: m_init = (ULONGLONG)0; break;
101 case ATOM_FLOAT4: m_init = (float)0.0; break;
102 case ATOM_FLOAT8: m_init = (double)0.0; break;
103 case ATOM_STRUCT:
104 {
105 b_valvect vv;
106 m_init = vv;
107 m_init.m_t = ATOM_STRUCT;
108 }
109 break;
110 case ATOM_VECTOR:
111 {
112 b_valvect vv;
113 m_init = vv;
114 m_init.m_t = ATOM_VECTOR;
115 }
116 break;
117 default:
118 break;
119 }
120
121 cls.add(this);
122 }
123
124 //-----------------------------------------------------------------------------
125 b_attribute::~b_attribute()
126 {
127 TRACE_FUNCTION(TRL_LOW, "b_attribute::b_attribute");
128
129 for (size_t i = 0; i < m_attrs.size(); i++)
130 {
131 b_attribute * mbr = m_attrs[i];
132 if (! mbr->nodel()) // can't delete static attribute
133 {
134 //@ delete mbr;
135 }
136 }
137 }
138
139 //-----------------------------------------------------------------------------
140 // Create instance data of attribute
141 //-----------------------------------------------------------------------------
142 b_attrdata * b_attribute::instance(const b_object * obj) const
143 {
144 TRACE_FUNCTION(TRL_LOW, "b_attribute::instance");
145
146 b_attrdata * val = new b_attrdata(obj, this);
147
148 return val;
149 }
150
151 //-----------------------------------------------------------------------------
152 // Dump
153 //-----------------------------------------------------------------------------
154 void b_attribute::dump() const
155 {
156 ACE_DEBUG((LM_DEBUG, ACE_TEXT(" name = %s(%s), "), m_name.c_str(),
157 m_userName.c_str()));
158 ACE_DEBUG((LM_DEBUG, ACE_TEXT("type = 0x%x, "), m_type));
159 ACE_DEBUG((LM_DEBUG, ACE_TEXT("size = %d, "), m_size));
160 ACE_DEBUG((LM_DEBUG, ACE_TEXT("position = %d, "), m_position));
161 string value;
162 m_init.get(value);
163 ACE_DEBUG((LM_DEBUG, ACE_TEXT("initval = %s\n"), value.c_str()));
164 }
165
166 //
167 // <<< Vector >>>
168 //
169 //-----------------------------------------------------------------------------
170 // Constructor/Destructor
171 //-----------------------------------------------------------------------------
172 b_vector::b_vector(const BCHAR * name, b_attribute * attr, size_t q, int mode,
173 bool nodel)
174 : b_attribute(name, ATOM_VECTOR, q, mode, nodel)
175 {
176 if (attr != NULL)
177 {
178 m_attrs.push_back(attr);
179 b_valvect vv;
180 vv.push_back(const_cast<b_value *>(&(attr->getInitVal())));
181 m_init = vv;
182 }
183 }
184
185 //-----------------------------------------------------------------------------
186 b_vector::b_vector(b_objtype& cls, const BCHAR * name, b_attribute * attr,
187 size_t q, int mode, bool nodel)
188 : b_attribute(name, ATOM_VECTOR, q, mode, nodel)
189 {
190 if (attr != NULL)
191 {
192 m_attrs.push_back(attr);
193 b_valvect vv;
194 vv.push_back(const_cast<b_value *>(&(attr->getInitVal())));
195 m_init = vv;
196 }
197 cls.add(this);
198 }
199
200 //-----------------------------------------------------------------------------
201 b_vector::b_vector(b_struct& stt, const BCHAR * name, b_attribute * attr,
202 size_t q, int mode, bool nodel)
203 : b_attribute(name, ATOM_VECTOR, q, mode, nodel)
204 {
205 if (attr != NULL)
206 {
207 m_attrs.push_back(attr);
208 b_valvect vv;
209 vv.push_back(const_cast<b_value *>(&(attr->getInitVal())));
210 m_init = vv;
211 }
212 stt.add(this);
213 }
214
215 //-----------------------------------------------------------------------------
216 // Create instance data of attribute
217 //-----------------------------------------------------------------------------
218 b_attrdata * b_vector::instance(const b_object * obj) const
219 {
220 TRACE_FUNCTION(TRL_LOW, "b_vector::instance");
221
222 b_attrdata * val = new b_attrdata(obj, this);
223
224 return val;
225 }
226
227 //
228 // <<< Struct >>>
229 //
230 //-----------------------------------------------------------------------------
231 // Constructor/Destructor
232 //-----------------------------------------------------------------------------
233 b_struct::b_struct(const BCHAR * name, int mode, bool nodel)
234 : b_attribute(name, ATOM_STRUCT, 0, mode, nodel)
235 {
236 TRACE_FUNCTION(TRL_LOW, "b_struct::b_struct");
237
238 return ;
239 }
240
241 //-----------------------------------------------------------------------------
242 b_struct::b_struct(b_objtype& cls, const BCHAR * name, int mode, bool nodel)
243 : b_attribute(name, ATOM_STRUCT, 0, mode, nodel)
244 {
245 TRACE_FUNCTION(TRL_LOW, "b_struct::b_struct");
246
247 cls.add(this);
248 }
249
250 //-----------------------------------------------------------------------------
251 b_struct::b_struct(b_struct& stt, const BCHAR * name, int mode, bool nodel)
252 : b_attribute(name, ATOM_STRUCT, 0, mode, nodel)
253 {
254 TRACE_FUNCTION(TRL_LOW, "b_struct::b_struct");
255
256 stt.add(this);
257 }
258
259 //-----------------------------------------------------------------------------
260 // Create instance data of attribute
261 //-----------------------------------------------------------------------------
262 b_attrdata * b_struct::instance(const b_object * obj) const
263 {
264 TRACE_FUNCTION(TRL_LOW, "b_struct::instance");
265
266 b_attrdata * val = new b_attrdata(obj, this);
267
268 return val;
269 }
270
271 //-----------------------------------------------------------------------------
272 // Add member attributes
273 //-----------------------------------------------------------------------------
274 extern bool comp_position(b_attribute * lhs, b_attribute * rhs);
275
276 //
277 void b_struct::add(b_attribute * attr)
278 {
279 TRACE_FUNCTION(TRL_LOW, "b_struct::add");
280
281 BEEAssert(attr != NULL);
282 m_attrs.push_back(attr);
283 if (attr->position() == 0)
284 {
285 attr->position(m_attrs.size() - 1); // Set position of struct
286 }
287 b_value * v = new b_value(attr->getInitVal());
288 m_init.m._vec->push_back(v);
289
290 sort(m_attrs.begin(), m_attrs.end(), comp_position);
291
292 return ;
293 }
294
295 //-----------------------------------------------------------------------------
296 void b_struct::add(b_attribute * attrs[])
297 {
298 TRACE_FUNCTION(TRL_LOW, "b_struct::add");
299
300 BEEAssert(attrs != NULL);
301 int i = 0;
302 while (attrs[i] != NULL)
303 {
304 b_attribute * attr = attrs[i++];
305 m_attrs.push_back(attr);
306 if (attr->position() == 0)
307 {
308 attr->position(m_attrs.size() - 1); // Set position of struct
309 }
310 b_value * v = new b_value(attr->getInitVal());
311 m_init.m._vec->push_back(v);
312 }
313
314 sort(m_attrs.begin(), m_attrs.end(), comp_position);
315
316 return ;
317 }
318

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