Choreonoid  1.8
DeviceList.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_BODY_DEVICE_LIST_H
7 #define CNOID_BODY_DEVICE_LIST_H
8 
9 #include "Device.h"
10 #include <cnoid/PolymorphicReferencedArray>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 template <class DeviceType = Device, class PointerType = ref_ptr<DeviceType> >
16 class DeviceList : public PolymorphicReferencedArray<DeviceType, Device, PointerType>
17 {
19 
20 public:
21  DeviceList() { }
22 
23  template <class RhsDeviceType>
25  : ArrayBase(rhs) { }
26 
28  DeviceList sorted;
29  for(size_t i=0; i < ArrayBase::size(); ++i){
30  DeviceType* device = (*this)[i];
31  const int id = device->id();
32  if(id >= 0){
33  if(static_cast<int>(sorted.size()) <= id){
34  sorted.resize(id + 1);
35  }
36  sorted[id] = device;
37  }
38  }
39  return sorted;
40  }
41 };
42 
43 }
44 
45 #endif
Device.h
cnoid::DeviceList::getSortedById
DeviceList getSortedById() const
Definition: DeviceList.h:27
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::PolymorphicReferencedArrayBase< Device >
cnoid::DeviceList::DeviceList
DeviceList(const DeviceList< RhsDeviceType > &rhs)
Definition: DeviceList.h:24
cnoid::DeviceList::DeviceList
DeviceList()
Definition: DeviceList.h:21
cnoid::PolymorphicReferencedArray::resize
void resize(size_t size)
Definition: PolymorphicReferencedArray.h:123
cnoid::DeviceList
Definition: DeviceList.h:16
cnoid::PolymorphicReferencedArray::size
std::size_t size() const
Definition: PolymorphicReferencedArray.h:127
cnoid::PolymorphicReferencedArray
Definition: PolymorphicReferencedArray.h:27