Break out bootstrapping code into a separate file
This commit is contained in:
parent
6a9c5ee57f
commit
280ec06a8c
85
boxedcpp/bootstrap.hpp
Normal file
85
boxedcpp/bootstrap.hpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#ifndef __bootstrap_hpp
|
||||||
|
#define __bootstrap_hpp__
|
||||||
|
|
||||||
|
#include "boxedcpp.hpp"
|
||||||
|
|
||||||
|
template<typename Ret, typename P1, typename P2>
|
||||||
|
Ret add(P1 p1, P2 p2)
|
||||||
|
{
|
||||||
|
return p1 + p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename P1, typename P2>
|
||||||
|
Ret subtract(P1 p1, P2 p2)
|
||||||
|
{
|
||||||
|
return p1 - p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename P1, typename P2>
|
||||||
|
Ret divide(P1 p1, P2 p2)
|
||||||
|
{
|
||||||
|
return p1 - p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Ret, typename P1, typename P2>
|
||||||
|
Ret multiply(P1 p1, P2 p2)
|
||||||
|
{
|
||||||
|
return p1 * p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename P1, typename P2>
|
||||||
|
P1 ×equal(P1 &p1, P2 p2)
|
||||||
|
{
|
||||||
|
return (p1 *= p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Input>
|
||||||
|
std::string to_string(Input i)
|
||||||
|
{
|
||||||
|
return boost::lexical_cast<std::string>(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bootstrap(BoxedCPP_System &s)
|
||||||
|
{
|
||||||
|
s.register_type<void>("void");
|
||||||
|
s.register_type<double>("double");
|
||||||
|
s.register_type<int>("int");
|
||||||
|
s.register_type<char>("char");
|
||||||
|
s.register_type<std::string>("string");
|
||||||
|
|
||||||
|
s.register_function(boost::function<std::string (const std::string &, const std::string&)>(&add<std::string, const std::string &, const std::string &>), "+");
|
||||||
|
|
||||||
|
s.register_function(boost::function<int (int, int)>(&add<int, int, int>), "+");
|
||||||
|
s.register_function(boost::function<double (int, double)>(&add<double, int, double>), "+");
|
||||||
|
s.register_function(boost::function<double (double, int)>(&add<double, double, int>), "+");
|
||||||
|
s.register_function(boost::function<double (double, double)>(&add<double, double, double>), "+");
|
||||||
|
|
||||||
|
s.register_function(boost::function<int (int, int)>(&subtract<int, int, int>), "-");
|
||||||
|
s.register_function(boost::function<double (int, double)>(&subtract<double, int, double>), "-");
|
||||||
|
s.register_function(boost::function<double (double, int)>(&subtract<double, double, int>), "-");
|
||||||
|
s.register_function(boost::function<double (double, double)>(&subtract<double, double, double>), "-");
|
||||||
|
|
||||||
|
s.register_function(boost::function<int (int, int)>(÷<int, int, int>), "/");
|
||||||
|
s.register_function(boost::function<double (int, double)>(÷<double, int, double>), "/");
|
||||||
|
s.register_function(boost::function<double (double, int)>(÷<double, double, int>), "/");
|
||||||
|
s.register_function(boost::function<double (double, double)>(÷<double, double, double>), "/");
|
||||||
|
|
||||||
|
s.register_function(boost::function<int (int, int)>(&multiply<int, int, int>), "*");
|
||||||
|
s.register_function(boost::function<double (int, double)>(&multiply<double, int, double>), "*");
|
||||||
|
s.register_function(boost::function<double (double, int)>(&multiply<double, double, int>), "*");
|
||||||
|
s.register_function(boost::function<double (double, double)>(&multiply<double, double, double>), "*");
|
||||||
|
|
||||||
|
s.register_function(boost::function<std::string (int)>(&to_string<int>), "to_string");
|
||||||
|
s.register_function(boost::function<std::string (const std::string &)>(&to_string<const std::string &>), "to_string");
|
||||||
|
s.register_function(boost::function<std::string (char)>(&to_string<char>), "to_string");
|
||||||
|
s.register_function(boost::function<std::string (double)>(&to_string<double>), "to_string");
|
||||||
|
|
||||||
|
s.register_function(boost::function<int &(int&, int)>(×equal<int, int>), "*=");
|
||||||
|
s.register_function(boost::function<double &(double&, int)>(×equal<double, int>), "*=");
|
||||||
|
s.register_function(boost::function<double &(double&, double)>(×equal<double, double>), "*=");
|
||||||
|
s.register_function(boost::function<int &(int&, double)>(×equal<int, double>), "*=");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -130,88 +130,6 @@ void dump_system(const BoxedCPP_System &s)
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ret, typename P1, typename P2>
|
|
||||||
Ret add(P1 p1, P2 p2)
|
|
||||||
{
|
|
||||||
return p1 + p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Ret, typename P1, typename P2>
|
|
||||||
Ret subtract(P1 p1, P2 p2)
|
|
||||||
{
|
|
||||||
return p1 - p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Ret, typename P1, typename P2>
|
|
||||||
Ret divide(P1 p1, P2 p2)
|
|
||||||
{
|
|
||||||
return p1 - p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Ret, typename P1, typename P2>
|
|
||||||
Ret multiply(P1 p1, P2 p2)
|
|
||||||
{
|
|
||||||
return p1 * p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename P1, typename P2>
|
|
||||||
P1 ×equal(P1 &p1, P2 p2)
|
|
||||||
{
|
|
||||||
return (p1 *= p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Input>
|
|
||||||
std::string to_string(Input i)
|
|
||||||
{
|
|
||||||
return boost::lexical_cast<std::string>(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bootstrap(BoxedCPP_System &s)
|
|
||||||
{
|
|
||||||
s.register_type<void>("void");
|
|
||||||
s.register_type<double>("double");
|
|
||||||
s.register_type<int>("int");
|
|
||||||
s.register_type<char>("char");
|
|
||||||
s.register_type<std::string>("string");
|
|
||||||
|
|
||||||
s.register_function(boost::function<std::string (const std::string &, const std::string&)>(&add<std::string, const std::string &, const std::string &>), "+");
|
|
||||||
|
|
||||||
s.register_function(boost::function<int (int, int)>(&add<int, int, int>), "+");
|
|
||||||
s.register_function(boost::function<double (int, double)>(&add<double, int, double>), "+");
|
|
||||||
s.register_function(boost::function<double (double, int)>(&add<double, double, int>), "+");
|
|
||||||
s.register_function(boost::function<double (double, double)>(&add<double, double, double>), "+");
|
|
||||||
|
|
||||||
s.register_function(boost::function<int (int, int)>(&subtract<int, int, int>), "-");
|
|
||||||
s.register_function(boost::function<double (int, double)>(&subtract<double, int, double>), "-");
|
|
||||||
s.register_function(boost::function<double (double, int)>(&subtract<double, double, int>), "-");
|
|
||||||
s.register_function(boost::function<double (double, double)>(&subtract<double, double, double>), "-");
|
|
||||||
|
|
||||||
s.register_function(boost::function<int (int, int)>(÷<int, int, int>), "/");
|
|
||||||
s.register_function(boost::function<double (int, double)>(÷<double, int, double>), "/");
|
|
||||||
s.register_function(boost::function<double (double, int)>(÷<double, double, int>), "/");
|
|
||||||
s.register_function(boost::function<double (double, double)>(÷<double, double, double>), "/");
|
|
||||||
|
|
||||||
s.register_function(boost::function<int (int, int)>(&multiply<int, int, int>), "*");
|
|
||||||
s.register_function(boost::function<double (int, double)>(&multiply<double, int, double>), "*");
|
|
||||||
s.register_function(boost::function<double (double, int)>(&multiply<double, double, int>), "*");
|
|
||||||
s.register_function(boost::function<double (double, double)>(&multiply<double, double, double>), "*");
|
|
||||||
|
|
||||||
s.register_function(boost::function<std::string (int)>(&to_string<int>), "to_string");
|
|
||||||
s.register_function(boost::function<std::string (const std::string &)>(&to_string<const std::string &>), "to_string");
|
|
||||||
s.register_function(boost::function<std::string (char)>(&to_string<char>), "to_string");
|
|
||||||
s.register_function(boost::function<std::string (double)>(&to_string<double>), "to_string");
|
|
||||||
|
|
||||||
s.register_function(boost::function<int &(int&, int)>(×equal<int, int>), "*=");
|
|
||||||
s.register_function(boost::function<double &(double&, int)>(×equal<double, int>), "*=");
|
|
||||||
s.register_function(boost::function<double &(double&, double)>(×equal<double, double>), "*=");
|
|
||||||
s.register_function(boost::function<int &(int&, double)>(×equal<int, double>), "*=");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
#include "boxedcpp.hpp"
|
#include "boxedcpp.hpp"
|
||||||
|
#include "bootstrap.hpp"
|
||||||
|
|
||||||
struct Test
|
struct Test
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "boxedcpp.hpp"
|
#include "boxedcpp.hpp"
|
||||||
|
#include "bootstrap.hpp"
|
||||||
|
|
||||||
#define BOOST_TEST_DYN_LINK
|
#define BOOST_TEST_DYN_LINK
|
||||||
#define BOOST_TEST_MODULE boxedcpp_unittests
|
#define BOOST_TEST_MODULE boxedcpp_unittests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user