codac 2.0.0
Loading...
Searching...
No Matches
codac2_FunctionArgsList.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <list>
13#include <vector>
14#include <iostream>
15#include <algorithm>
16#include "codac2_VarBase.h"
17
18namespace codac2
19{
24 class FunctionArgsList : public std::vector<std::shared_ptr<VarBase>>
25 {
26 public:
27
33
42 : std::vector<std::shared_ptr<VarBase>>(args.size())
43 {
44 size_t i = 0;
45 for(const auto& arg : args)
46 (*this)[i++] = arg->arg_copy();
47 compute_unique_arg_names();
48 }
49
58 FunctionArgsList(std::initializer_list<std::reference_wrapper<VarBase>> args)
59 : FunctionArgsList(std::vector<std::reference_wrapper<VarBase>>(args))
60 { }
61
70 FunctionArgsList(const std::vector<std::reference_wrapper<VarBase>>& args)
71 {
72 for(const auto& arg : args)
73 push_back(arg.get().arg_copy());
74 compute_unique_arg_names();
75 }
76
83 Index total_size() const
84 {
85 Index n = 0;
86 for(const auto& ai : *this)
87 n += ai->size();
88 return n;
89 }
90
91 void compute_unique_arg_names()
92 {
93 std::list<std::string> var_names;
94 for(const auto& arg : *this)
95 var_names.push_back(arg->name());
96
97 int i = 23; // default first variable is x, then y,z, then starting from a...
98 for(auto& arg : *this)
99 {
100 if(arg->name() == "?")
101 {
102 std::string new_name;
103 do {
104 new_name = 'a' + ((i++)%26);
105 } while(std::find(var_names.begin(),var_names.end(),new_name) != var_names.end());
106 arg->_name = new_name;
107 }
108 }
109 }
110 };
111}
FunctionArgsList(const FunctionArgsList &args)
Copy constructor.
Definition codac2_FunctionArgsList.h:41
FunctionArgsList()
Default constructor. It creates an empty list of arguments.
Definition codac2_FunctionArgsList.h:31
Index total_size() const
Calculates the total size of the function arguments, as the sum of the sizes of each argument.
Definition codac2_FunctionArgsList.h:83
FunctionArgsList(const std::vector< std::reference_wrapper< VarBase > > &args)
Constructor to initialize a FunctionArgsList from a vector of of references to VarBase objects.
Definition codac2_FunctionArgsList.h:70
FunctionArgsList(std::initializer_list< std::reference_wrapper< VarBase > > args)
Constructor to initialize a FunctionArgsList from an initializer list of references to VarBase object...
Definition codac2_FunctionArgsList.h:58
Abstract base class for representing variables in analytic or set functions.
Definition codac2_VarBase.h:24
virtual std::shared_ptr< VarBase > arg_copy() const =0
Creates a copy of the argument.