NumberingPolicy.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <rtm/NumberingPolicy.h>
00021 #include <coil/stringutil.h>
00022 
00023 //============================================================
00024 // DefaultNumberingPolicy
00025 //============================================================
00033 std::string DefaultNumberingPolicy::onCreate(void* obj)
00034 {
00035   std::vector<void*>::size_type pos;
00036   
00037   ++m_num;
00038   
00039   try
00040     {
00041       pos = find(NULL);
00042       m_objects[pos] = obj;
00043       return coil::otos(pos);
00044     }
00045   catch (ObjectNotFound& e)
00046     {
00047       (void)(e);
00048       m_objects.push_back(obj);
00049       return coil::otos((int)(m_objects.size() - 1));
00050     }
00051 }
00052 
00060 void DefaultNumberingPolicy::onDelete(void* obj)
00061 {
00062   std::vector<void*>::size_type pos;
00063   pos = find(obj);
00064   if (pos < m_objects.size())
00065     {
00066       m_objects[pos] = NULL;
00067     }
00068   --m_num;
00069 }
00070 
00078 long int DefaultNumberingPolicy::find(void* obj)
00079 {
00080   std::vector<void*>::size_type len(m_objects.size());
00081   std::vector<void*>::size_type i(0);
00082   for (i = 0; i < len; ++i)
00083     {
00084       if (m_objects[i] == obj) return i;
00085     }
00086   throw ObjectNotFound();
00087   return i;
00088 }
00089 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:16