| 1 |
// $Id: b_specification.cpp,v 1.15 2003/03/15 04:35:30 fukasawa Exp $ |
| 2 |
|
| 3 |
//============================================================================= |
| 4 |
/** |
| 5 |
* @file b_specification.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_specification.h" |
| 31 |
#include "b_objtype.h" |
| 32 |
#include "b_object.h" |
| 33 |
|
| 34 |
|
| 35 |
//----------------------------------------------------------------------------- |
| 36 |
// Constructor/Destructor |
| 37 |
//----------------------------------------------------------------------------- |
| 38 |
b_specification::~b_specification() |
| 39 |
{ |
| 40 |
TRACE_FUNCTION(TRL_LOW, "b_specification::~b_specification"); |
| 41 |
|
| 42 |
this->clear(); |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
//----------------------------------------------------------------------------- |
| 47 |
void b_specification::clear() |
| 48 |
{ |
| 49 |
TRACE_FUNCTION(TRL_LOW, "b_specification::clear"); |
| 50 |
|
| 51 |
// |
| 52 |
// Erase Objects |
| 53 |
// |
| 54 |
b_objectMap::iterator obj_iter = m_objs.begin(); |
| 55 |
for ( ; obj_iter != m_objs.end(); obj_iter++) |
| 56 |
{ |
| 57 |
b_object * _object = (*obj_iter).second; |
| 58 |
delete _object; |
| 59 |
} |
| 60 |
m_objs.clear(); |
| 61 |
|
| 62 |
// |
| 63 |
// Erase ObjTypes |
| 64 |
// |
| 65 |
b_objtypeMap::iterator iter = m_classes.begin(); |
| 66 |
for ( ; iter != m_classes.end(); iter++) |
| 67 |
{ |
| 68 |
//@ b_objtype * objtype = (*iter).second; |
| 69 |
//@ delete objtype; // can't delete static objtype |
| 70 |
} |
| 71 |
m_classes.clear(); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
//----------------------------------------------------------------------------- |
| 76 |
// Make object specification name |
| 77 |
//----------------------------------------------------------------------------- |
| 78 |
void b_specification::makeObjSpec(b_object * obj, string& spec) const |
| 79 |
{ |
| 80 |
TRACE_FUNCTION(TRL_LOW, "b_specification::makeObjSpec"); |
| 81 |
|
| 82 |
// |
| 83 |
// if a parent is supported, make full path name |
| 84 |
// |
| 85 |
spec = m_name; |
| 86 |
if (m_name.size() > 0) |
| 87 |
{ |
| 88 |
spec += _TX(">"); |
| 89 |
} |
| 90 |
spec += obj->objid(); |
| 91 |
return ; |
| 92 |
} |
| 93 |
|
| 94 |
//----------------------------------------------------------------------------- |
| 95 |
// Get object id name |
| 96 |
//----------------------------------------------------------------------------- |
| 97 |
int b_specification::objSpec2ID(const string& spec, string& objid) const |
| 98 |
{ |
| 99 |
TRACE_FUNCTION(TRL_LOW, "b_specification::objSpec2ID"); |
| 100 |
|
| 101 |
// |
| 102 |
// if a parent is supported, make full path name |
| 103 |
// |
| 104 |
int diffpos = strspn(spec.c_str(), m_name.c_str()); |
| 105 |
if (diffpos == 0) |
| 106 |
{ |
| 107 |
return BEE_ERROR; |
| 108 |
} |
| 109 |
if (spec.at(diffpos) != '>') |
| 110 |
{ |
| 111 |
return BEE_ERROR; |
| 112 |
} |
| 113 |
|
| 114 |
objid = spec.substr(diffpos + 1); |
| 115 |
return BEE_SUCCESS; |
| 116 |
} |
| 117 |
|
| 118 |
//----------------------------------------------------------------------------- |
| 119 |
// Find class by name(ObjType) |
| 120 |
//----------------------------------------------------------------------------- |
| 121 |
b_objtype * b_specification::find(const string& name) const |
| 122 |
{ |
| 123 |
TRACE_FUNCTION(TRL_LOW, "b_specification::find"); |
| 124 |
|
| 125 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, |
| 126 |
const_cast<ACE_Thread_Mutex&>(this->m_typeLock), NULL, |
| 127 |
2, 200); |
| 128 |
|
| 129 |
b_objtypeMap::const_iterator iter = m_classes.find(name); |
| 130 |
if (iter == m_classes.end()) |
| 131 |
{ |
| 132 |
return NULL; |
| 133 |
} |
| 134 |
const b_objtype * result = (*iter).second; |
| 135 |
return (b_objtype *)result; |
| 136 |
} |
| 137 |
|
| 138 |
//----------------------------------------------------------------------------- |
| 139 |
b_objtype * b_specification::findByUserName(const string& name) const |
| 140 |
{ |
| 141 |
TRACE_FUNCTION(TRL_LOW, "b_specification::findByUserName"); |
| 142 |
|
| 143 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, |
| 144 |
const_cast<ACE_Thread_Mutex&>(this->m_typeLock), NULL, |
| 145 |
2, 200); |
| 146 |
|
| 147 |
string stdname; |
| 148 |
bool result = const_cast<b_specification *>(this)->standardByUserName(name, stdname); |
| 149 |
if (! result) |
| 150 |
{ |
| 151 |
return NULL; |
| 152 |
} |
| 153 |
return this->find(stdname); |
| 154 |
} |
| 155 |
|
| 156 |
//----------------------------------------------------------------------------- |
| 157 |
b_object * b_specification::findObject(const string& name) const |
| 158 |
{ |
| 159 |
TRACE_FUNCTION(TRL_LOW, "b_specification::findObject"); |
| 160 |
|
| 161 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, |
| 162 |
const_cast<ACE_Thread_Mutex&>(this->m_objLock), NULL, |
| 163 |
2, 400); |
| 164 |
|
| 165 |
b_objectMap::const_iterator iter = m_objs.find(name); |
| 166 |
if (iter == m_objs.end()) |
| 167 |
{ |
| 168 |
return NULL; |
| 169 |
} |
| 170 |
const b_object * result = (*iter).second; |
| 171 |
return (b_object *)result; |
| 172 |
} |
| 173 |
|
| 174 |
//----------------------------------------------------------------------------- |
| 175 |
// Add new class |
| 176 |
//----------------------------------------------------------------------------- |
| 177 |
int b_specification::add(b_objtype * cls) |
| 178 |
{ |
| 179 |
TRACE_FUNCTION(TRL_LOW, "b_specification::add"); |
| 180 |
|
| 181 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, this->m_typeLock, 1, |
| 182 |
10, 200); |
| 183 |
|
| 184 |
m_classes.insert(b_objtypePair(cls->typeName(), cls)); |
| 185 |
|
| 186 |
return BEE_SUCCESS; |
| 187 |
} |
| 188 |
|
| 189 |
//----------------------------------------------------------------------------- |
| 190 |
// Entry new object |
| 191 |
//----------------------------------------------------------------------------- |
| 192 |
int b_specification::addObject(b_object * obj) |
| 193 |
{ |
| 194 |
TRACE_FUNCTION(TRL_LOW, "b_specification::addObject"); |
| 195 |
|
| 196 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, this->m_objLock, 1, |
| 197 |
10, 200); |
| 198 |
|
| 199 |
string spec; |
| 200 |
makeObjSpec(obj, spec); |
| 201 |
m_objs.insert(b_objectPair(spec, obj)); |
| 202 |
|
| 203 |
return BEE_SUCCESS; |
| 204 |
} |
| 205 |
|
| 206 |
//----------------------------------------------------------------------------- |
| 207 |
// Remove object |
| 208 |
//----------------------------------------------------------------------------- |
| 209 |
int b_specification::remove(b_object * obj) |
| 210 |
{ |
| 211 |
TRACE_FUNCTION(TRL_LOW, "b_specification::remove"); |
| 212 |
|
| 213 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, this->m_objLock, BEE_SUCCESS+1, |
| 214 |
10, 300); |
| 215 |
|
| 216 |
string spec; |
| 217 |
makeObjSpec(obj, spec); |
| 218 |
size_t q = m_objs.erase(spec); |
| 219 |
if (q != 1) |
| 220 |
{ |
| 221 |
return BEE_ERROR; |
| 222 |
} |
| 223 |
return BEE_SUCCESS; |
| 224 |
} |
| 225 |
|
| 226 |
//----------------------------------------------------------------------------- |
| 227 |
// Remove object type |
| 228 |
//----------------------------------------------------------------------------- |
| 229 |
int b_specification::remove(b_objtype * cls) |
| 230 |
{ |
| 231 |
TRACE_FUNCTION(TRL_LOW, "b_specification::remove"); |
| 232 |
|
| 233 |
BEE_GUARD_RETURN(ACE_Thread_Mutex, ace_mon, this->m_typeLock, BEE_SUCCESS+1, |
| 234 |
10, 300); |
| 235 |
|
| 236 |
size_t q = m_classes.erase(cls->typeName()); |
| 237 |
if (q != 1) |
| 238 |
{ |
| 239 |
return BEE_ERROR; |
| 240 |
} |
| 241 |
return BEE_SUCCESS; |
| 242 |
} |
| 243 |
|
| 244 |
//----------------------------------------------------------------------------- |
| 245 |
// Find class by name(ObjType) |
| 246 |
//----------------------------------------------------------------------------- |
| 247 |
void b_specification::dump() const |
| 248 |
{ |
| 249 |
|
| 250 |
b_objtypeMap::const_iterator iter = m_classes.begin(); |
| 251 |
for ( ; iter != m_classes.end(); iter++) |
| 252 |
{ |
| 253 |
const b_objtype * klass = (*iter).second; |
| 254 |
klass->dump(); |
| 255 |
} |
| 256 |
} |