Advertisement
demmeln

addToWorkingMemoryDynamicType

Mar 26th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1.  
  2. namespace cast {
  3.  
  4. /**
  5.  *   Provide the name of the dynamic type of an object
  6.  */  
  7. template <class T>
  8. const std::string& dynamicTypeName(const IceInternal::Handle<T> object) {
  9.   return object->ice_id();
  10. }
  11.  
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18.   /**
  19.    * Add new data to working memory. The data will be stored with the given
  20.    * id. Determines the dynamic type of _data instead of using the static
  21.    * type.
  22.    *
  23.    * @param _id
  24.    *            The id the data will be stored with.
  25.    * @param _subarchitectureID
  26.    *            The subarchitecture to write to.
  27.    * @param _data
  28.    *            The data itself. Must be a ref-counted pointer to an instance of an Ice class.
  29.    * @throws AlreadyExistsOnWMException
  30.    *             If an entry exists at the given id.
  31.    */
  32.   template <class T>
  33.   void addToWorkingMemoryDynamicType(const std::string &_id,
  34.                                      const std::string &_subarch,
  35.                                      IceInternal::Handle<T>  _data)
  36.       throw (cast::AlreadyExistsOnWMException, cast::UnknownSubarchitectureException) {
  37.    
  38.     assert(!_id.empty());//id must not be empty
  39.     assert(!_subarch.empty());//subarch must not be empty
  40.     assert(_data);//data must not be null
  41.    
  42.     //UPGRADE not sure what to do with this now
  43.     //checkPrivileges(_subarch);
  44.    
  45.     std::string type(dynamicTypeName(_data));
  46.    
  47.     //logMemoryAdd(_id, _subarch, type);
  48.    
  49.     //#bug 52, testcase 2: If we are already versioning this data
  50.     //it's ok. This means we had previously written to this address.
  51.    
  52.     int versionWhichWillEndUpOnWM = 0;
  53.    
  54.     //if not versioned, start doing so
  55.     if(!isVersioned(_id)) {
  56.       debug("is not versioned: %s",_id.c_str());
  57.       startVersioning(_id);
  58.     }
  59.     //if it's already versioned, then we need to update our numbers      
  60.     else {
  61.       debug("re-adding to working memory with id %s",_id.c_str()); 
  62.       //get the last known version number, which we store + 1
  63.       versionWhichWillEndUpOnWM = getVersionNumber(_id,_subarch) + 1;
  64.       storeVersionNumber(_id, versionWhichWillEndUpOnWM);
  65.     }
  66.  
  67.     if(m_copyOnWrite) {
  68.       m_workingMemory->addToWorkingMemory(_id,_subarch,type,getComponentID(),_data->ice_clone());
  69.     }
  70.     else {
  71.       m_workingMemory->addToWorkingMemory(_id,_subarch,type,getComponentID(),_data);
  72.     }
  73.    
  74.     logAdd(_id, _subarch, type, versionWhichWillEndUpOnWM);
  75.    
  76.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement