Template Class SciantixArray
Defined in File SciantixArray.h
Class Documentation
-
template<class T>
class SciantixArray A template class for managing a collection of variables with fast access by name or index.
This class allows for efficient storage, retrieval, and modification of elements by their name or index. It internally uses a
std::vectorfor storing the elements and astd::mapfor mapping names to indices for quick lookup.- Author
F. Bastien
- Author
G. Zullo
- Param T:
The type of elements stored in the array. The type T must have a
getName()method returning astd::string.
Public Functions
-
inline SciantixArray()
Constructor.
-
inline ~SciantixArray()
Destructor.
-
inline SciantixArray(std::vector<T> data)
Constructs a SciantixArray from a given vector of elements.
The constructor also populates the internal map with the names of the elements and their corresponding indices.
- Parameters:
data – A vector of elements to initialize the array.
-
inline void push(T element)
Adds or replaces an element in the array.
If an element with the same name already exists in the array, it will be replaced with the new element. Otherwise, the element is added to the end of the array.
- Parameters:
element – The element to be added or replaced.
-
inline void clear()
Clears all elements from the array.
This method clears both the internal vector and the map, effectively resetting the array.
-
inline bool empty()
Checks if the array is empty.
- Returns:
True if the array is empty, False otherwise.
-
inline T &operator[](int index)
Accesses an element by its index.
- Parameters:
index – The index of the element to access.
- Returns:
A reference to the element at the specified index.
-
inline T &operator[](std::string variable_name)
Accesses an element by its name.
If the element is not found, an error message is printed and the program exits.
- Parameters:
variable_name – The name of the element to access.
- Returns:
A reference to the element with the specified name.
-
inline std::vector<T>::iterator begin()
Provides an iterator to the beginning of the array.
- Returns:
An iterator pointing to the first element of the array.
-
inline std::vector<T>::iterator end()
Provides an iterator to the end of the array.
- Returns:
An iterator pointing to the past-the-end element of the array.
-
inline std::vector<T>::const_iterator begin() const
Provides a constant iterator to the beginning of the array.
- Returns:
A constant iterator pointing to the first element of the array.
-
inline std::vector<T>::const_iterator end() const
Provides a constant iterator to the end of the array.
- Returns:
A constant iterator pointing to the past-the-end element of the array.
-
inline bool isElementPresent(std::string element_name)
Checks if an element with the given name is present in the array.
- Parameters:
element_name – The name of the element to check.
- Returns:
true if the element is present, false otherwise.