115 lines
2.8 KiB
OpenEdge ABL
115 lines
2.8 KiB
OpenEdge ABL
%module li_std_vector_as_argument
|
|
|
|
%{
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <algorithm>
|
|
#include <numeric>
|
|
|
|
%}
|
|
|
|
%{
|
|
class classA
|
|
{
|
|
public:
|
|
classA() : a(0) {}
|
|
classA(int _a) : a(_a) {}
|
|
classA(const classA& c) : a(c.a) {}
|
|
int a;
|
|
};
|
|
%}
|
|
|
|
%include stl.i
|
|
|
|
namespace std
|
|
{
|
|
%template(IntVector) vector<int>;
|
|
%template(DoubleVector) vector<double>;
|
|
%template(StringVector) vector<std::string>;
|
|
%template(BoolVector) vector<bool>;
|
|
%template(ClassAPtrVector) vector<classA*>;
|
|
}
|
|
|
|
%ignore concat_vector;
|
|
|
|
class classA
|
|
{
|
|
public:
|
|
classA() : a(0) {}
|
|
classA(int _a) : a(_a) {}
|
|
classA(const classA& c) : a(c.a) {}
|
|
int a;
|
|
};
|
|
|
|
%inline %{
|
|
template <typename T>
|
|
std::vector<T> concat_vector(const std::vector<T> vector, const std::vector<T> other_vector) {
|
|
std::vector<T> out_vector(vector);
|
|
out_vector.insert(out_vector.end(), other_vector.begin(), other_vector.end());
|
|
return out_vector;
|
|
}
|
|
|
|
// double vectors
|
|
|
|
std::vector<double> create_double_vector(const int size, const double value) {
|
|
return std::vector<double>(size, value);
|
|
}
|
|
|
|
double sum_double_vector(const std::vector<double>& vector) {
|
|
return std::accumulate(vector.begin(), vector.end(), 0);
|
|
}
|
|
|
|
std::vector<double> concat_double_vector(const std::vector<double> vector, const std::vector<double> other_vector) {
|
|
return concat_vector<double>(vector, other_vector);
|
|
}
|
|
|
|
// int vectors
|
|
|
|
std::vector<int> create_integer_vector(const int size, const int value) {
|
|
return std::vector<int>(size, value);
|
|
}
|
|
|
|
int sum_integer_vector(const std::vector<int>& vector) {
|
|
return std::accumulate(vector.begin(), vector.end(), 0);
|
|
}
|
|
|
|
std::vector<int> concat_integer_vector(const std::vector<int> vector, const std::vector<int> other_vector) {
|
|
return concat_vector<int>(vector, other_vector);
|
|
}
|
|
|
|
// string vectors
|
|
|
|
std::vector<std::string> create_string_vector(const int size, const char *value) {
|
|
return std::vector<std::string>(size, value);
|
|
}
|
|
|
|
std::vector<std::string> concat_string_vector(const std::vector<std::string> vector, const std::vector<std::string> other_vector) {
|
|
return concat_vector<std::string>(vector, other_vector);
|
|
}
|
|
|
|
// bool vectors
|
|
|
|
std::vector<bool> create_bool_vector(const int size, const bool value) {
|
|
return std::vector<bool>(size, value);
|
|
}
|
|
|
|
std::vector<bool> concat_bool_vector(const std::vector<bool> vector, const std::vector<bool> other_vector) {
|
|
return concat_vector<bool>(vector, other_vector);
|
|
}
|
|
|
|
// pointer (on object) vectors
|
|
|
|
std::vector<classA*> create_classAPtr_vector(const int size, classA *aClassAPtr) {
|
|
std::vector<classA*> out_vector;
|
|
for (int i=0; i<size; i++) {
|
|
out_vector.push_back(aClassAPtr);
|
|
}
|
|
return out_vector;
|
|
}
|
|
|
|
std::vector<classA*> concat_classAPtr_vector(const std::vector<classA*> vector, const std::vector<classA*> other_vector) {
|
|
return concat_vector<classA*>(vector, other_vector);
|
|
}
|
|
%}
|
|
|