YARP
Yet Another Robot Platform
MultiJointData.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_CONTROLBOARDWRAPPER_MULTIJOINTDATA_H
10 #define YARP_DEV_CONTROLBOARDWRAPPER_MULTIJOINTDATA_H
11 
12 #include "SubDevice.h"
13 
15 {
16 public:
17  size_t deviceNum {0};
19 
20  int* subdev_jointsVectorLen {nullptr}; // number of joints belonging to each subdevice
21  int** jointNumbers {nullptr};
22  int** modes {nullptr};
23  double** values {nullptr};
24  SubDevice** subdevices_p {nullptr};
25 
26  MultiJointData() = default;
27 
28  void resize(int _deviceNum, int _maxJointsNumForDevice, WrappedDevice* _device)
29  {
30  deviceNum = _deviceNum;
31  maxJointsNumForDevice = _maxJointsNumForDevice;
33  jointNumbers = new int*[deviceNum]; // alloc a vector of pointers
34  jointNumbers[0] = new int[deviceNum * _maxJointsNumForDevice]; // alloc real memory for data
35 
36  modes = new int*[deviceNum]; // alloc a vector of pointers
37  modes[0] = new int[deviceNum * _maxJointsNumForDevice]; // alloc real memory for data
38 
39  values = new double*[deviceNum]; // alloc a vector of pointers
40  values[0] = new double[deviceNum * _maxJointsNumForDevice]; // alloc real memory for data
41 
43  subdevices_p[0] = _device->getSubdevice(0);
44 
45  for (size_t i = 1; i < deviceNum; i++) {
46  jointNumbers[i] = jointNumbers[i - 1] + _maxJointsNumForDevice; // set pointer to correct location
47  values[i] = values[i - 1] + _maxJointsNumForDevice; // set pointer to correct location
48  modes[i] = modes[i - 1] + _maxJointsNumForDevice; // set pointer to correct location
49  subdevices_p[i] = _device->getSubdevice(i);
50  }
51  }
52 
53  void destroy()
54  {
55  // release matrix memory
56  delete[] jointNumbers[0];
57  delete[] values[0];
58  delete[] modes[0];
59 
60  // release vector of pointers
61  delete[] jointNumbers;
62  delete[] values;
63  delete[] modes;
64 
65  // delete other vectors
66  delete[] subdev_jointsVectorLen;
67  delete[] subdevices_p;
68  }
69 };
70 
71 #endif // YARP_DEV_CONTROLBOARDWRAPPER_MULTIJOINTDATA_H
SubDevice.h
WrappedDevice
Definition: SubDevice.h:123
MultiJointData::values
double ** values
Definition: MultiJointData.h:23
MultiJointData::jointNumbers
int ** jointNumbers
Definition: MultiJointData.h:21
MultiJointData::resize
void resize(int _deviceNum, int _maxJointsNumForDevice, WrappedDevice *_device)
Definition: MultiJointData.h:28
MultiJointData::maxJointsNumForDevice
size_t maxJointsNumForDevice
Definition: MultiJointData.h:18
MultiJointData::subdev_jointsVectorLen
int * subdev_jointsVectorLen
Definition: MultiJointData.h:20
MultiJointData::subdevices_p
SubDevice ** subdevices_p
Definition: MultiJointData.h:24
MultiJointData
Definition: MultiJointData.h:15
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
MultiJointData::MultiJointData
MultiJointData()=default
MultiJointData::destroy
void destroy()
Definition: MultiJointData.h:53
MultiJointData::modes
int ** modes
Definition: MultiJointData.h:22
MultiJointData::deviceNum
size_t deviceNum
Definition: MultiJointData.h:17
SubDevice
Definition: SubDevice.h:55