MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef LIST_H
8#define LIST_H
9
10#include <iostream>
11#include <sstream>
12#include "INCLUDE/maiatypes.h"
13#include "UTIL/functions.h"
14
15template <typename T>
16class List {
17 public:
19 ~List() { delete[] a; };
20 MInt size() { return (MInt)m_size; };
21
22 MInt maxSize() { return (MInt)m_maxSize; };
23
24 void append();
25 MLong memoryUseage() { return (MLong)((m_maxSize + 1) * sizeof(T)); };
26
27 T* operator[](const MInt index);
28 T* a = nullptr;
30
31 MInt setSize(MInt inputSize) {
32 if(inputSize < m_size) m_size = inputSize;
33 return (MInt)inputSize;
34 }
35
36 MInt resetSize(MInt inputSize) {
37 if(inputSize < 0) {
38 mTerm(1, AT_, "Input size is < 0!");
39 }
40 if(inputSize > m_maxSize) {
41 std::stringstream errorMessage;
42 errorMessage << " Error in list, maxSize reached ( " << m_maxSize << " cells ).";
43 mTerm(1, AT_, errorMessage.str());
44 }
45 m_size = inputSize;
46 return (MInt)inputSize;
47 }
48
50
51 private:
54};
55
56template <typename T>
57List<T>::List(MLong inputMaxSize) {
58 m_size = 0;
59 m_rawMemoryCounter = 0;
60 m_maxSize = inputMaxSize;
61
62 a = new T[(inputMaxSize + 1)];
63}
64
65template <typename T>
67 if(m_size < m_maxSize)
68 m_size++;
69 else {
70 std::stringstream errorMessage;
71 errorMessage << " Error in list, maxSize reached ( " << m_maxSize << " cells ).";
72 mTerm(1, AT_, errorMessage.str());
73 }
74}
75
76
77template <typename T>
78T* List<T>::operator[](const MInt index) {
79 return &a[index];
80}
81#endif
Definition: list.h:16
MInt maxSize()
Definition: list.h:22
T * a
Definition: list.h:28
MLong memoryUseage()
Definition: list.h:25
~List()
Definition: list.h:19
MLong m_maxSize
Definition: list.h:52
MLong m_rawMemoryCounter
Definition: list.h:29
void append()
Definition: list.h:66
MInt setSize(MInt inputSize)
Definition: list.h:31
List(MLong maxSize)
Definition: list.h:57
MInt resetSize(MInt inputSize)
Definition: list.h:36
T * operator[](const MInt index)
Definition: list.h:78
MInt m_size
Definition: list.h:53
char * getRawPointer()
MInt size()
Definition: list.h:20
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
int32_t MInt
Definition: maiatypes.h:62
int64_t MLong
Definition: maiatypes.h:64
Definition: contexttypes.h:19