/usr/include/trilinos/RTC_ArrayVarRTC.hh is in libtrilinos-pamgen-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | #ifndef _ARRAYRTC_H
#define _ARRAYRTC_H
#include "RTC_VariableRTC.hh"
#include "RTC_commonRTC.hh"
#include "RTC_ExecutableRTC.hh"
#include <string>
#include <iostream>
namespace PG_RuntimeCompiler {
/**
* ArrayVar objects represent variables that are arrays.
*/
template <class T>
class ArrayVar : public Variable
{
public:
/**
* Constructor -> Constructs the super class, initializes instance variables
*
* @param name - The name of the variable
* @param type - The type of the variable
* @param size - The number of elements in the array
*/
ArrayVar(const std::string& name, Type type, int size = 0)
: Variable(name, type, ArrayVarOT)
{
_size = size;
_sizeExp = NULL;
_values = NULL;
}
/**
* Constructor -> Constructs the super class, initializes instance variables
*
* @param name - The name of the variable
* @param type - The type of the variable
* @param sizePtr - An expression that, when evaluated, will be
* the array's size
*/
ArrayVar(const std::string& name, Type type, Executable* sizePtr)
: Variable(name, type, ArrayVarOT)
{
_size = 0;
_sizeExp = sizePtr;
_values = NULL;
}
/**
* Destructor -> Delete the size expression if it is not null. We also delete
* the values if we are not dealing with user provided
* argument.
*/
virtual ~ArrayVar()
{
if (_sizeExp != NULL)
delete _sizeExp;
if (!_isArg)
delete[] _values;
}
/**
* getValue -> Returns the value of the array at a certain index
*
* @param offset - The index we want the value of
*/
double getArrayValue(int offset) const
{
assert(_values != NULL);
if (offset >= _size || offset < 0) {
std::cout << "Index: " << offset << " is out of bounds on array: "
<< _name << std::endl;
return 0;
}
return (double)(_values[offset]);
}
/**
* setValue -> Sets the value of the array at a certain index
*
* @param value - The value we are going to set to
* @param offset - The location in the array being changed
*/
void setArrayValue(double value, int offset)
{
assert(_values != NULL);
if (offset >= _size || offset < 0) {
std::cout << "Went out of bounds on array: " << _name << std::endl;
return;
}
_values[offset] = (T) value;
}
/**
* getSize -> Returns the size of the array
*/
int getSize() const {return _size;}
/**
* setSize -> Sets the size of the array
*
* @param size - The new size of the array
*/
void setSize(int size) { _size = size; }
/**
* evaluateSizeExpr -> Evaluates the size expression to get the array size,
* then allocates a corresponding number of values.
*/
void evaluateSizeExpr()
{
assert(_sizeExp != NULL);
_size = (int) _sizeExp->execute()->getValue();
_isArg = false;
if (_values != NULL)
delete[] _values;
_values = new T[_size];
}
/**
* setAddress -> Only called if the array is a function argument. We make the
* array point to a user provided address.
*
* @param addr - The address of the array's values
*/
void setAddress(void* addr)
{
_isArg = true;
_values = (T*) addr;
}
std::ostream& operator<<(std::ostream& os) const
{
if (_values != NULL) {
os << "ArrayVar:" << _name << "{";
for (int i = 0; i < _size; ++i)
os << _values[i] << ", ";
os << "}";
}
else {
os << "ArrayVar:" << _name;
}
return os;
}
private:
int _size; //!< The length of the array
T* _values; //!< The array of values
bool _isArg; /**!< Tells us if the array is a user argument or declared in
* in the user defined function. This boolean will affect how
* the array memory is cleaned up. We would not want to call
* delete on an address the user provided to us as we have no
* way of knowing if it points to heap memory.
*/
Executable* _sizeExp; //!< When evaluated, this will be the size of Array
};
}
#endif
|