OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
IntVector_api.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include "IntVector.hpp"
24
25#define _FCALL
26
27// Interface
28
29extern "C"
30{
31 void intvector_create_(std::vector<int>**);
32 void intvector_delete_(std::vector<int>**);
33 void intvector_clear_(std::vector<int>**);
34 void intvector_push_back_(std::vector<int>**, const int*);
35 void intvector_get_size_(std::vector<int>**, int*);
36 void intvector_get_redundant_(std::vector<int>**, int*, int*, int*);
37 void intvector_copy_to_(const std::vector<int>**, int*);
38 void intvector_copy_from_(std::vector<int>**, const int*, const int*);
39 void intvector_find_(const std::vector<int>**, const int*, int*);
40
41 void _FCALL INTVECTOR_CREATE(std::vector<int>** vec_ptr)
42 {
43 intvector_create_(vec_ptr);
44 }
45 void _FCALL INTVECTOR_DELETE(std::vector<int>** vec_ptr)
46 {
47 intvector_delete_(vec_ptr);
48 }
49 void _FCALL INTVECTOR_CLEAR(std::vector<int>** vec_ptr)
50 {
51 intvector_clear_(vec_ptr);
52 }
53 void _FCALL INTVECTOR_PUSH_BACK(std::vector<int>** vec_ptr, const int* i)
54 {
55 intvector_push_back_(vec_ptr, i);
56 }
57 void _FCALL INTVECTOR_GET_SIZE(std::vector<int>** vec_ptr, int* i)
58 {
59 intvector_get_size_(vec_ptr, i);
60 }
61 void _FCALL INTVECTOR_GET_REDUNDANT(std::vector<int>** vec_ptr, int* res, int* err, int* card)
62 {
63 intvector_get_redundant_(vec_ptr, res, err, card);
64 }
65 void _FCALL INTVECTOR_COPY_TO(const std::vector<int>** vec_ptr, int* res)
66 {
67 intvector_copy_to_(vec_ptr, res);
68 }
69 void _FCALL INTVECTOR_COPY_FROM(std::vector<int>** vec_ptr, const int* res, const int* size)
70 {
71 intvector_copy_from_(vec_ptr, res, size);
72 }
73 void _FCALL INTVECTOR_FIND(const std::vector<int>** vec_ptr, const int* what, int* where)
74 {
75 intvector_find_(vec_ptr, what, where);
76 }
77}
78
79// Create
80void intvector_create_(std::vector<int>** vec_ptr)
81{
82 *vec_ptr = new std::vector<int> ();
83}
84// Delete
85void intvector_delete_(std::vector<int>** vec_ptr)
86{
87 delete(*vec_ptr);
88 *vec_ptr = nullptr;
89}
90// Clear
91void intvector_clear_(std::vector<int>** vec_ptr)
92{
93 (*vec_ptr)->clear();
94}
95// Push_back
96void intvector_push_back_(std::vector<int>** vec_ptr, const int* i)
97{
98 (*vec_ptr)->push_back(*i);
99}
100// Get size
101void intvector_get_size_(std::vector<int>** vec_ptr, int* i)
102{
103 *i = (*vec_ptr)->size();
104}
105// Get the redundant element
106void intvector_get_redundant_(std::vector<int>** vec_ptr, int* res, int* err, int* card)
107{
108 auto correct_count = [&vec_ptr,&card](int ii) {return (*card == count((*vec_ptr)->begin(), (*vec_ptr)->end(), ii));};
109 auto iter = find_if((*vec_ptr)->begin(), (*vec_ptr)->end(), correct_count);
110 if (iter != (*vec_ptr)->end()) {
111 *res = *iter;
112 *err = 0;
113 } else {
114 *res = 0;
115 *err = 1;
116 }
117}
118// Copy the vector into the int*
119void intvector_copy_to_(const std::vector<int>** vec_ptr, int* res)
120{
121 auto iter = (*vec_ptr)->begin();
122 for ( ; iter != (*vec_ptr)->end() ; ++iter) {
123 (*res++) = *iter;
124 }
125}
126// Copy int array res into the vector
127void intvector_copy_from_(std::vector<int>** vec_ptr, const int* res, const int* size)
128{
129 (*vec_ptr)->resize(*size);
130 for (int i(0) ; i < *size ; ++i) {
131 (*vec_ptr)->at(i) = res[i];
132 }
133}
134// Finds value what in the int vector and returns where = position of what, or -1 if not found
135void intvector_find_(const std::vector<int>** vec_ptr, const int* what, int* where)
136{
137 *where = -1;
138 auto iter = std::find((*vec_ptr)->begin(), (*vec_ptr)->end(), *what);
139 if (iter != (*vec_ptr)->end()) {
140 *where = std::distance((*vec_ptr)->begin(), iter) + 1;
141 }
142}
void intvector_get_redundant_(std::vector< int > **, int *, int *, int *)
void _FCALL INTVECTOR_CREATE(std::vector< int > **vec_ptr)
void _FCALL INTVECTOR_GET_SIZE(std::vector< int > **vec_ptr, int *i)
void _FCALL INTVECTOR_CLEAR(std::vector< int > **vec_ptr)
void intvector_clear_(std::vector< int > **)
void intvector_copy_from_(std::vector< int > **, const int *, const int *)
void intvector_get_size_(std::vector< int > **, int *)
void _FCALL INTVECTOR_COPY_FROM(std::vector< int > **vec_ptr, const int *res, const int *size)
void intvector_copy_to_(const std::vector< int > **, int *)
void _FCALL INTVECTOR_DELETE(std::vector< int > **vec_ptr)
void _FCALL INTVECTOR_PUSH_BACK(std::vector< int > **vec_ptr, const int *i)
void intvector_push_back_(std::vector< int > **, const int *)
void intvector_create_(std::vector< int > **)
void _FCALL INTVECTOR_FIND(const std::vector< int > **vec_ptr, const int *what, int *where)
void intvector_delete_(std::vector< int > **)
void _FCALL INTVECTOR_COPY_TO(const std::vector< int > **vec_ptr, int *res)
void _FCALL INTVECTOR_GET_REDUNDANT(std::vector< int > **vec_ptr, int *res, int *err, int *card)
void intvector_find_(const std::vector< int > **, const int *, int *)
#define _FCALL