~vbursian/research-assistant/intervers

« back to all changes in this revision

Viewing changes to RANet/NodePtr.cpp

  • Committer: Viktor Bursian at blin-Ubuntu
  • Date: 2013-06-29 18:01:41 UTC
  • mto: (4.2.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: vbursian@gmail.com-20130629180141-oby3p7oezibrddqm
перед переделкой sStorable & related changes in descendants

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
125
125
  try{
126
126
    GetNode();
127
127
    TheNodePtr->SetAttr(attr);
128
 
  }catch( rxNet/*GetNullNode*/ ){
129
 
    throw xNet/*InvalidOp*/();
 
128
  }catch( rxGetNullNode ){
 
129
    throw xNetInvalidOp();
130
130
  }
131
131
  return *this;
132
132
}
134
134
 
135
135
rsNodePtr  sNodePtr::operator << (sNodePtr value_of_a_nameless_attr)
136
136
{
 
137
  try{
 
138
    GetNode();
 
139
    TheNodePtr->SetAttr(sAttribute(sAttributeName(),value_of_a_nameless_attr));
 
140
  }catch( rxGetNullNode ){
 
141
    throw xNetInvalidOp();
 
142
  }
137
143
  return *this;
138
144
}
139
145
 
140
146
 
141
 
rsNodePtr  sNodePtr::MakeSubcluster ()
 
147
rsNodePtr  sNodePtr::MakeSubcluster (sAttributeName  attr_name)
142
148
{
 
149
  try{
 
150
    GetNode();
 
151
    TheNodePtr->MakeSubcluster(attr_name);
 
152
  }catch( rxGetNullNode ){
 
153
    throw xNetInvalidOp();
 
154
  }
143
155
  return *this;
144
156
}
145
157
 
146
158
 
147
159
rsNodePtr  sNodePtr::operator |= (sAttribute  attr)
148
160
{
 
161
  try{
 
162
    GetNode();
 
163
    TheNodePtr->AscribeAttr(attr);
 
164
  }catch( rxGetNullNode ){
 
165
    throw xNetInvalidOp();
 
166
  }
149
167
  return *this;
150
168
}
151
169
 
152
170
 
153
 
rsNodePtr  sNodePtr::operator |= (sNodePtr  model)
 
171
rsNodePtr  sNodePtr::operator |= (sNodePtr  /*model*/)
154
172
{
 
173
  //!@patch not implemented yet
155
174
  return *this;
156
175
}
157
176
 
158
177
 
159
178
rsNodePtr  sNodePtr::operator |= (literal  attr_name)
160
179
{
 
180
  if( MakeSubcluster(attr_name).IsNULL() )
 
181
    throw xMakeSubcluster(*this,attr_name);
161
182
  return *this;
162
183
}
163
184
 
164
185
 
165
186
rsNodePtr  sNodePtr::operator |= (rctAttrString  attr_name)
166
187
{
 
188
  if( MakeSubcluster(attr_name).IsNULL() )
 
189
    throw xMakeSubcluster(*this,attr_name);
167
190
  return *this;
168
191
}
169
192
 
170
193
 
171
194
rsNodePtr  sNodePtr::operator |= (sAtom  attr_name)
172
195
{
 
196
  if( MakeSubcluster(attr_name).IsNULL() )
 
197
    throw xMakeSubcluster(*this,attr_name);
173
198
  return *this;
174
199
}
175
200
 
176
201
 
177
202
rsNodePtr  sNodePtr::operator |= (int  attr_name)
178
203
{
 
204
  if( MakeSubcluster(attr_name).IsNULL() )
 
205
    throw xMakeSubcluster(*this,attr_name);
179
206
  return *this;
180
207
}
181
208
 
194
221
 
195
222
void  sNodePtr::Clear ()
196
223
{
 
224
  QMutexLocker                Locker(&Mutex);
197
225
  if( ! InMemory ){
198
226
    ASSERT( TheNodeLocationPtr );
199
227
    delete TheNodeLocationPtr;  TheNodeLocationPtr=NULL;
200
 
  }else if( TheNodePtr==NULL ){
201
 
    //nothing to do
202
 
  }else{
203
 
//    /*/////////DEBUG
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;
209
 
//    */
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 )
214
 
//        N=N->Next;
215
 
//      N->Next=Next;
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;
223
 
//      }else{
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 );
234
 
//          };
235
 
//        };
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;
243
 
//      };
244
 
//    };
 
228
  }else if( TheNodePtr ){
 
229
    TheNodePtr->UnregisterPointer(this);
245
230
  };
246
231
  Net=NULL;
247
232
  InMemory=true;
255
240
{
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?
263
 
//    InMemory=true;
264
 
//    TheNodePtr=P;
265
 
//    if( TheNodePtr ){
266
 
//      if( TheNodePtr->PtrRing ){
267
 
//        Next=TheNodePtr->PtrRing->Next;
268
 
//        TheNodePtr->PtrRing->Next=this;
269
 
//      }else{
270
 
//        TheNodePtr->PtrRing=this;
271
 
//        Next=this;
272
 
//      };
273
 
//      TheNodePtr->NumberOfPointers++;
274
 
//      //if not a lost node
275
 
//      TheNodePtr->LocationEdited= TheNodePtr->Location.Path != ExpectedLocationPath;
276
 
//    };
277
 
//    //----------------------
 
243
    TheNodePtr = Net->GetNode(TheNodeLocationPtr);
 
244
    if( TheNodePtr )
 
245
      TheNodePtr->KeepInTouch(this);
278
246
  };
279
247
  if( ! TheNodePtr ){
280
 
    throw xNet();
 
248
    throw xGetNullNode(*this);
281
249
  };
282
250
}
283
251
 
501
469
//  };
502
470
//};
503
471
 
504
 
//------------------------------------------------------------------------------
505
 
 
506
 
class RANet_EXPORT  xAscribeModel : public xNet
507
 
{
508
 
  public:
509
 
                              xAscribeModel (sNodePtr  N ,sNodePtr  M)
510
 
                                {}
511
 
};
 
472
//------------------------------------------------------------- xGetNullNode ---
 
473
 
 
474
xGetNullNode::xGetNullNode (sNodePtr)
 
475
{
 
476
}
 
477
 
 
478
//------------------------------------------------------------ xAscribeModel ---
 
479
 
 
480
xAscribeModel::xAscribeModel (sNodePtr,sNodePtr)
 
481
{
 
482
}
512
483
 
513
484
//------------------------------------------------------------------------------
514
485
} //namespace RA