NumberingPolicy.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <rtm/NumberingPolicy.h>
21 #include <coil/stringutil.h>
22 
23 //============================================================
24 // DefaultNumberingPolicy
25 //============================================================
33 std::string DefaultNumberingPolicy::onCreate(void* obj)
34 {
35  std::vector<void*>::size_type pos;
36 
37  ++m_num;
38 
39  try
40  {
41  pos = find(NULL);
42  m_objects[pos] = obj;
43  return coil::otos(pos);
44  }
45  catch (ObjectNotFound& e)
46  {
47  (void)(e);
48  m_objects.push_back(obj);
49  return coil::otos((int)(m_objects.size() - 1));
50  }
51 }
52 
61 {
62  std::vector<void*>::size_type pos;
63  pos = find(obj);
64  if (pos < m_objects.size())
65  {
66  m_objects[pos] = NULL;
67  }
68  --m_num;
69 }
70 
78 long int DefaultNumberingPolicy::find(void* obj)
79 {
80  std::vector<void*>::size_type len(m_objects.size());
81  std::vector<void*>::size_type i(0);
82  for (i = 0; i < len; ++i)
83  {
84  if (m_objects[i] == obj) return i;
85  }
86  throw ObjectNotFound();
87  return i;
88 }
89 
std::string otos(Printable n)
Convert the given object to std::string.
Definition: stringutil.h:566
virtual void onDelete(void *obj)
Delete the name when deleting object.
std::vector< void * > m_objects
virtual std::string onCreate(void *obj)
Create the name when creating object.
Object numbering policy class.
The structures for exception handling when object was not found.
long int find(void *obj)
Find the object.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53