1
1
////////////////////////////////////////////////////////////////////////////////
2
/*! @file NodePtr.cpp Умный указатель на объекты сети.
2
/*! @file NodePtr.cpp A clever pointer to a node of RANet.
3
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
4
4
- Copyright(C) 1994-2010, Viktor E. Bursian, St.Petersburg, Russia.
5
5
Viktor.Bursian@mail.ioffe.ru
135
135
rsNodePtr sNodePtr::operator << (sNodePtr value_of_a_nameless_attr)
139
TheNodePtr->SetAttr(sAttribute(sAttributeName(),value_of_a_nameless_attr));
140
}catch( rxGetNullNode ){
141
throw xNetInvalidOp();
141
rsNodePtr sNodePtr::MakeSubcluster ()
147
rsNodePtr sNodePtr::MakeSubcluster (sAttributeName attr_name)
151
TheNodePtr->MakeSubcluster(attr_name);
152
}catch( rxGetNullNode ){
153
throw xNetInvalidOp();
147
159
rsNodePtr sNodePtr::operator |= (sAttribute attr)
163
TheNodePtr->AscribeAttr(attr);
164
}catch( rxGetNullNode ){
165
throw xNetInvalidOp();
153
rsNodePtr sNodePtr::operator |= (sNodePtr model)
171
rsNodePtr sNodePtr::operator |= (sNodePtr /*model*/)
173
//!@patch not implemented yet
159
178
rsNodePtr sNodePtr::operator |= (literal attr_name)
180
if( MakeSubcluster(attr_name).IsNULL() )
181
throw xMakeSubcluster(*this,attr_name);
165
186
rsNodePtr sNodePtr::operator |= (rctAttrString attr_name)
188
if( MakeSubcluster(attr_name).IsNULL() )
189
throw xMakeSubcluster(*this,attr_name);
171
194
rsNodePtr sNodePtr::operator |= (sAtom attr_name)
196
if( MakeSubcluster(attr_name).IsNULL() )
197
throw xMakeSubcluster(*this,attr_name);
177
202
rsNodePtr sNodePtr::operator |= (int attr_name)
204
if( MakeSubcluster(attr_name).IsNULL() )
205
throw xMakeSubcluster(*this,attr_name);
195
222
void sNodePtr::Clear ()
224
QMutexLocker Locker(&Mutex);
197
225
if( ! InMemory ){
198
226
ASSERT( TheNodeLocationPtr );
199
227
delete TheNodeLocationPtr; TheNodeLocationPtr=NULL;
200
}else if( TheNodePtr==NULL ){
204
// tNodeUID DEBUG_ID=NodePtr->Location.NodeUID;
205
// sLongString DEBUG_LP=NodePtr->Location.Path+NodePtr->Location.DefaultSuffix;
206
// bool DEBUG_EDITED=NodePtr->Edited;
207
// int DEBUG_NUMOFHOSTS=NodePtr->NumberOfHosts;
208
// int DEBUG_NUMOFPTRS=NodePtr->NumberOfPointers;
210
// if( Next != this ){ //meaning, there are other Ptrs to the same node
211
// ASSERT( TheNodePtr->NumberOfPointers > 1 );
212
// psNodePtr N = Next;
213
// while( N->Next != this )
216
// TheNodePtr->PtrRing=Next;
217
// TheNodePtr->NumberOfPointers--;
218
// }else{ //this is the only one Ptr to the corresponding node
219
// ASSERT( TheNodePtr->NumberOfPointers == 1 );
220
// if( TheNodePtr->NumberOfHosts == 0 ){
221
// TheNodePtr->NumberOfPointers--;
222
// delete TheNodePtr; TheNodePtr=NULL;
224
// TheNodePtr->Strip(); //may set up NodePtr->Edited flag
225
// if( TheNodePtr->Location.NodeUID != NoID ){
226
// TheNodePtr->Save();
227
// }else{ /////////////////DEBUG
228
// if( TheNodePtr->EditedFlag ){
229
// sString Erasing_edited_nonseparate_node;
230
// Erasing_edited_nonseparate_node+=TheNodePtr->Location.Path;
231
// (Erasing_edited_nonseparate_node+="|")+=TheNodePtr->Location.DefaultSuffix;
232
// ((Erasing_edited_nonseparate_node+="[")<<TheNodePtr->Location.NodeUID)+="]";
233
// TRACE( Erasing_edited_nonseparate_node );
236
// TheNodePtr->PurgeAttributes();
237
// TheNodePtr->NumberOfPointers--;
238
// /*! @todo{bomb} desinchronization between NumberOfPointers and PtrRing
239
// Here and in other places like this NumberOfPointers==0, but PtrRing!=NULL
240
// Because of it one may not use sNodePtr to the node in destructors
241
// (in particular sAttributeFinger!!!) */
242
// delete TheNodePtr; TheNodePtr=NULL;
228
}else if( TheNodePtr ){
229
TheNodePtr->UnregisterPointer(this);
256
241
QMutexLocker Locker(&Mutex);
257
242
if( ! InMemory ){
258
// sString ExpectedLocationPath = TheNodeLocationPtr->Path;
259
// ASSERT( TheNodeLocationPtr );
260
// P=sNet::Manager->GetNode(TheNodeLocationPtr);
261
// //! @todo{NetIO} lost node becomes a null node
262
// //! @todo{multitasking} critical section?
266
// if( TheNodePtr->PtrRing ){
267
// Next=TheNodePtr->PtrRing->Next;
268
// TheNodePtr->PtrRing->Next=this;
270
// TheNodePtr->PtrRing=this;
273
// TheNodePtr->NumberOfPointers++;
274
// //if not a lost node
275
// TheNodePtr->LocationEdited= TheNodePtr->Location.Path != ExpectedLocationPath;
277
// //----------------------
243
TheNodePtr = Net->GetNode(TheNodeLocationPtr);
245
TheNodePtr->KeepInTouch(this);
279
247
if( ! TheNodePtr ){
248
throw xGetNullNode(*this);
504
//------------------------------------------------------------------------------
506
class RANet_EXPORT xAscribeModel : public xNet
509
xAscribeModel (sNodePtr N ,sNodePtr M)
472
//------------------------------------------------------------- xGetNullNode ---
474
xGetNullNode::xGetNullNode (sNodePtr)
478
//------------------------------------------------------------ xAscribeModel ---
480
xAscribeModel::xAscribeModel (sNodePtr,sNodePtr)
513
484
//------------------------------------------------------------------------------