Scilab: add vector<class> in STL vector example
This commit is contained in:
parent
c3992df0bb
commit
111c1eb538
4 changed files with 59 additions and 11 deletions
|
|
@ -75,9 +75,37 @@ std::vector<bool> concat_bool_vector(const std::vector<bool> vector, const std::
|
|||
return concat_vector<bool>(vector, other_vector);
|
||||
}
|
||||
|
||||
// object vectors
|
||||
|
||||
std::vector<classA> create_classA_vector(const int size, const int value)
|
||||
{
|
||||
std::vector<classA> out_vector;
|
||||
for (int i=0; i<size; i++)
|
||||
{
|
||||
classA objA(value);
|
||||
out_vector.push_back(objA);
|
||||
}
|
||||
return out_vector;
|
||||
}
|
||||
|
||||
void print_classA_vector(const std::vector<classA>& vector)
|
||||
{
|
||||
std::vector<classA>::const_iterator it;
|
||||
std::cout << std::endl;
|
||||
for (it = vector.begin(); it != vector.end(); ++it)
|
||||
{
|
||||
std::cout << "<classA a:" << it->a << ">" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<classA> concat_classA_vector(const std::vector<classA> vector, const std::vector<classA> other_vector)
|
||||
{
|
||||
return concat_vector<classA>(vector, other_vector);
|
||||
}
|
||||
|
||||
// pointer (on objects) vectors
|
||||
|
||||
std::vector<classA*> create_classA_vector(const int size, const int value)
|
||||
std::vector<classA*> create_classAPtr_vector(const int size, const int value)
|
||||
{
|
||||
std::vector<classA*> out_vector;
|
||||
for (int i=0; i<size; i++)
|
||||
|
|
@ -88,17 +116,17 @@ std::vector<classA*> create_classA_vector(const int size, const int value)
|
|||
return out_vector;
|
||||
}
|
||||
|
||||
void print_classA_vector(const std::vector<classA*>& vector)
|
||||
void print_classAPtr_vector(const std::vector<classA*>& vector)
|
||||
{
|
||||
std::vector<classA*>::const_iterator it;
|
||||
std::cout << std::endl;
|
||||
for (it = vector.begin(); it != vector.end(); ++it)
|
||||
{
|
||||
std::cout << "<classA a:" << (*it)->a << ">" << std::endl;
|
||||
std::cout << "<classA* a:" << (*it)->a << ">" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<classA*> concat_classA_vector(const std::vector<classA*> vector, const std::vector<classA*> other_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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ std::vector<std::string> concat_string_vector(const std::vector<std::string> vec
|
|||
std::vector<bool> create_bool_vector(const int size, const bool value);
|
||||
std::vector<bool> concat_bool_vector(const std::vector<bool> vector, const std::vector<bool> other_vector);
|
||||
|
||||
// pointer (on objects) vectors
|
||||
|
||||
class classA
|
||||
{
|
||||
public:
|
||||
|
|
@ -31,7 +31,15 @@ public:
|
|||
int a;
|
||||
};
|
||||
|
||||
std::vector<classA*> create_classA_vector(const int size, const int value);
|
||||
void print_classA_vector(const std::vector<classA*>& pvector);
|
||||
std::vector<classA*> concat_classA_vector(const std::vector<classA*> vector, const std::vector<classA*> other_vector);
|
||||
// object vectors
|
||||
|
||||
std::vector<classA> create_classA_vector(const int size, const int value);
|
||||
void print_classA_vector(const std::vector<classA>& pvector);
|
||||
std::vector<classA> concat_classA_vector(const std::vector<classA> vector, const std::vector<classA> other_vector);
|
||||
|
||||
// pointer (on objects) vectors
|
||||
|
||||
std::vector<classA*> create_classAPtr_vector(const int size, const int value);
|
||||
void print_classAPtr_vector(const std::vector<classA*>& pvector);
|
||||
std::vector<classA*> concat_classAPtr_vector(const std::vector<classA*> vector, const std::vector<classA*> other_vector);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ namespace std
|
|||
%template(DoubleVector) vector<double>;
|
||||
%template(StringVector) vector<std::string>;
|
||||
%template(BoolVector) vector<bool>;
|
||||
%template(ClassAVector) vector<classA*>;
|
||||
%template(ClassAVector) vector<classA>;
|
||||
%template(ClassAPtrVector) vector<classA*>;
|
||||
}
|
||||
|
||||
%include "example.hxx"
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ disp("concat this vector with the vector of bool {false, false, false} with conc
|
|||
bv3 = concat_bool_vector(bv, bv2);
|
||||
disp(bv3);
|
||||
|
||||
// pointer (on object) vectors
|
||||
// object vectors
|
||||
|
||||
disp("Example of passing list of objects as vector arguments of C++ functions.");
|
||||
disp("Example of passing lists of pointer on object as vector of objects arguments of C++ functions.");
|
||||
disp("get a vector of objects {<classA a:1>, <classA a:1>, <classA a:1>} with create_classA_vector():");
|
||||
pv = create_classA_vector(3, 1);
|
||||
print_classA_vector(pv);
|
||||
|
|
@ -66,3 +66,14 @@ disp("concat this vector with the vector of objects {<classA a:5>, <classA a:5>}
|
|||
pv3 = concat_classA_vector(pv, pv2);
|
||||
print_classA_vector(pv3);
|
||||
|
||||
// pointer (on object) vectors
|
||||
|
||||
disp("Example of passing lists of pointers on object as vector of pointers on objects arguments of C++ functions.");
|
||||
disp("get a vector of pointers on object {<classA* a:1>, <classA* a:1>, <classA* a:1>} with create_classAPtr_vector():");
|
||||
pv = create_classAPtr_vector(3, 1);
|
||||
print_classAPtr_vector(pv);
|
||||
pv2 = create_classAPtr_vector(2, 5);
|
||||
disp("concat this vector with the vector of pointers on object {<classA* a:5>, <classA* a:5>} with concat_classAPtr_vector():");
|
||||
pv3 = concat_classAPtr_vector(pv, pv2);
|
||||
print_classAPtr_vector(pv3);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue