Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "AScope.h"
- int CountString( std::string line, std::string occured )
- {
- int occurances_count = 0;
- int search_index = 0;
- while (line.find(occured, search_index) != std::string::npos)
- {
- occurances_count++;
- search_index = line.find(occured, search_index) + 1;
- }
- return occurances_count;
- }
- std::string GetString(std::string line, int init_position, int final_position)
- {
- return line.substr(init_position, final_position-init_position);
- }
- std::string FilterString(std::string line, std::string unwanted)
- {
- while (line.find(unwanted) != std::string::npos)
- {
- line.erase (line.find(unwanted), unwanted.length());
- }
- return line;
- }
- template < typename numeraltype > AScope<numeraltype>::AScope()
- {
- _parameter_seperator = ",";
- _parameter_list_open = "(";
- _parameter_list_close = ")";
- }
- template < typename numeraltype > AScope<numeraltype>::~AScope()
- {
- }
- template < typename numeraltype > void AScope<numeraltype>::setFunctionParameterSeperator(const char * seperator)
- {
- _parameter_seperator = seperator;
- }
- template < typename numeraltype > void AScope<numeraltype>::setFunctionParameterBrackets(const char * openning, const char * closing)
- {
- _parameter_list_open = openning;
- _parameter_list_close = closing;
- }
- template < typename numeraltype > void AScope<numeraltype>::addVariable(const char * name, numeraltype * value)
- {
- _variable_names.push_back( name );
- _variable_pointers.push_back( value );
- }
- template < typename numeraltype > void AScope<numeraltype>::addVariables(std::vector<const char*> & names, std::vector<numeraltype*> * values)
- {
- for (auto name : names)
- {
- _variable_names.push_back(name);
- }
- for (auto value : *values)
- {
- _variable_pointers.push_back(value);
- }
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction0(const char* name, numeraltype (*func)())
- {
- _function0_names.push_back(name);
- _function0_pointers.push_back(func);
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction1(const char* name, numeraltype (*func)(numeraltype))
- {
- _function1_names.push_back(name);
- _function1_pointers.push_back(func);
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction2(const char* name, numeraltype (*func)(numeraltype, numeraltype))
- {
- _function2_names.push_back(name);
- _function2_pointers.push_back(func);
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction3(const char* name, numeraltype (*func)(numeraltype, numeraltype, numeraltype))
- {
- _function3_names.push_back(name);
- _function3_pointers.push_back(func);
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction4(const char* name, numeraltype (*func)(numeraltype, numeraltype, numeraltype, numeraltype))
- {
- _function4_names.push_back(name);
- _function4_pointers.push_back(func);
- }
- template < typename numeraltype > void AScope<numeraltype>::addFunction5(const char* name, numeraltype (*func)(numeraltype, numeraltype, numeraltype, numeraltype, numeraltype))
- {
- _function5_names.push_back(name);
- _function5_pointers.push_back(func);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getVariableValue(int var_index)
- {
- return *(_variable_pointers[var_index]);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction0Value(int func_index)
- {
- return (*_function0_pointers[func_index])();
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction1Value(int func_index, numeraltype a)
- {
- return (*_function1_pointers[func_index])(a);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction2Value(int func_index, numeraltype a, numeraltype b)
- {
- return (*_function2_pointers[func_index])(a, b);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction3Value(int func_index, numeraltype a, numeraltype b, numeraltype c)
- {
- return (*_function3_pointers[func_index])(a, b, c);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction4Value(int func_index, numeraltype a, numeraltype b, numeraltype c, numeraltype d)
- {
- return (*_function4_pointers[func_index])(a, b, c, d);
- }
- template < typename numeraltype > numeraltype AScope<numeraltype>::getFunction5Value(int func_index, numeraltype a, numeraltype b, numeraltype c, numeraltype d, numeraltype e)
- {
- return (*_function5_pointers[func_index])(a, b, c, d, e);
- }
- template < typename numeraltype > void AScope<numeraltype>::setVariableValue(int var_index, numeraltype new_value)
- {
- *(_variable_pointers[var_index]) = new_value;
- }
- template <typename numeraltype> std::string AScope<numeraltype>::getFuncParameter(std::string line, int number)
- {
- int finds_count = 0, seperator_position, initial_search_position;
- while (line.rfind(_parameter_list_open)!=std::string::npos)
- {
- if (line.find(_parameter_list_close, line.rfind(_parameter_list_open)) != std::string::npos)
- {
- seperator_position = line.find(_parameter_seperator, line.rfind(_parameter_list_open));
- while (seperator_position < line.find(_parameter_list_close, line.rfind(_parameter_list_open)))
- {
- line = line.replace( seperator_position, 1, "1234557");
- seperator_position = line.find(_parameter_seperator, line.rfind(_parameter_list_open));
- }
- line = line.replace(line.rfind(_parameter_list_open), 1, "1234567");
- }
- }
- seperator_position = line.find(_parameter_seperator);
- initial_search_position = seperator_position > 0 ? 0 : _parameter_seperator.length();
- if (line.find(_parameter_seperator) == std::string::npos)
- {
- initial_search_position = 0;
- }
- while (finds_count <= CountString(line, _parameter_seperator))
- {
- if (finds_count == number)
- {
- if (line.find(_parameter_seperator, initial_search_position) != std::string::npos)
- {
- line = GetString(line, initial_search_position, line.find(_parameter_seperator, initial_search_position));
- while (line.find("1234557") != std::string::npos)
- {
- line = line.replace(line.find("1234557"), 7, _parameter_seperator);
- }
- while (line.find("1234567") != std::string::npos)
- {
- line = line.replace(line.find("1234567"), 7, _parameter_list_open);
- }
- return line;
- }
- else
- {
- line = GetString(line, initial_search_position, line.length());
- while (line.find("1234557") != std::string::npos)
- {
- line = line.replace(line.find("1234557"), 7, _parameter_seperator);
- }
- while (line.find("1234567") != std::string::npos)
- {
- line = line.replace(line.find("1234567"), 7, _parameter_list_open);
- }
- return line;
- }
- }
- finds_count++;
- seperator_position = line.find(_parameter_seperator, initial_search_position);
- initial_search_position = seperator_position + _parameter_seperator.length();
- }
- return "0";
- }
- template class AScope<float>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement