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