-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSysFunctions.cpp
More file actions
44 lines (40 loc) · 1.15 KB
/
SysFunctions.cpp
File metadata and controls
44 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "SysFunctions.h"
#include <boost/lexical_cast.hpp>
#include <iostream>
namespace sys {
VarPtr get_input(arg_t& args)
{
std::string line;
std::getline(std::cin, line);
return VarPtr(new Variable(line));
}
VarPtr display(arg_t& args)
{
for(auto& arg : args) {
switch(arg->type) {
case Variable::Type::String:
std::cout << arg->getValue<Variable::StringType>();
break;
case Variable::Type::Number:
std::cout << arg->getValue<Variable::NumberType>();
break;
default:
throw std::runtime_error("type not supported by display");
}
}
std::cout.flush();
return VarPtr(new Variable());
}
VarPtr to_number(arg_t& args)
{
return VarPtr(new Variable(boost::lexical_cast<double>(
args[0]->getValue<std::string>()
)));
}
VarPtr to_string(arg_t& args)
{
return VarPtr(new Variable(boost::lexical_cast<std::string>(
args[0]->getValue<double>()
)));
}
}