Permalink
Browse files

Fix style

  • Loading branch information...
petya2164 committed Sep 23, 2016
1 parent 47ca8ed commit 65fed8864a19372f75dac93754c858be2aa8369a
@@ -9,34 +9,41 @@
int main()
{
// dummy functions called by the program
auto function_str =
[](std::string s){std::cout << "called with: " << s << std::endl;};
auto function_str = [](std::string s)
{
std::cout << "called with: " << s << std::endl;
};
auto function_int =
[](int i){std::cout << "called with: " << i << std::endl;};
auto function_int = [](int i)
{
std::cout << "called with: " << i << std::endl;
};
auto function_float =
[](float f){std::cout << "called with: " << f << std::endl;};
auto function_float = [](float f)
{
std::cout << "called with: " << f << std::endl;
};
auto print_function =
[](){std::cout << "prints some useful value" << std::endl;};
auto print_function = []()
{
std::cout << "prints some useful value" << std::endl;
};
using tuple_type = std::tuple<std::string, int>;
auto function_str_int_tuple = [](tuple_type t)
{
(void)t;
std::cout << "called with: "
<< std::get<0>(t) << ", " << std::get<1>(t) << std::endl;
std::cout << "called with: " << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
};
auto tuple_convert = [](std::istream& in)
{
auto v1 = skipper::default_convert<
typename std::tuple_element<0, tuple_type>::type>(in);
typename std::tuple_element<0, tuple_type>::type>(in);
auto v2 = skipper::default_convert<
typename std::tuple_element<1, tuple_type>::type>(in);
typename std::tuple_element<1, tuple_type>::type>(in);
return std::make_tuple(v1, v2);
};
@@ -57,8 +64,9 @@ int main()
// add a command that takes any string followed by any int as input
p.add_command<tuple_type>("d", "some help text for d",
function_str_int_tuple, skipper::any<tuple_type>(),
tuple_convert);
function_str_int_tuple,
skipper::any<tuple_type>(),
tuple_convert);
// add a command that prints something useful
p.add_command("p", "print something", print_function);
View
@@ -28,7 +28,7 @@ namespace skipper
/// @param os an output stream
/// @param s a set
/// @return friendly help stream
friend std::ostream& operator<<(std::ostream& os, const any &a)
friend std::ostream& operator<<(std::ostream& os, const any& a)
{
(void) a;
return os << "of type " << typeid(Type).name() << " of any value";
View
@@ -22,7 +22,7 @@ namespace skipper
const Type default_convert(std::istream& in)
{
Type value;
if(!(in >> value))
if (!(in >> value))
{
// reset the input stream error state and read all inputs
in.clear();
@@ -53,10 +53,10 @@ namespace skipper
/// @param out the output stream to use
program(std::string description,
std::istream& in = std::cin,
std::ostream& out = std::cout)
: m_description(description), m_in(in), m_out(out)
std::ostream& out = std::cout) :
m_description(description), m_in(in), m_out(out)
{
add_command("h", "print this help", [&](){m_out << *this;});
add_command("h", "print this help", [&]() {m_out << *this;});
}
/// add a command to the program
@@ -81,7 +81,7 @@ namespace skipper
const std::function<void(const Type)>& call,
const Predicate& validate = any<Type>(),
std::function<const Type(std::istream&)> convert =
default_convert<Type>)
default_convert<Type>)
{
assert(!m_commands.count(key) && "Duplicated command");
@@ -160,12 +160,12 @@ namespace skipper
/// @param os an output stream
/// @param s a set
/// @return friendly help stream
friend std::ostream& operator<<(std::ostream& os, const program &p)
friend std::ostream& operator<<(std::ostream& os, const program& p)
{
os << std::endl << p.m_description << std::endl << std::endl
<< "The following commands are accepted:" << std::endl;
for(auto i = p.m_commands.begin(); i != p.m_commands.end(); i++)
for (auto i = p.m_commands.begin(); i != p.m_commands.end(); i++)
os << i->first << " " << std::get<1>(i->second) << std::endl;
os << p.m_exit_key << " exit the program" << std::endl << std::endl;
View
@@ -16,8 +16,8 @@ namespace skipper
template<typename Type>
struct range
{
range(Type lower, Type upper)
: m_lower(lower), m_upper(upper)
range(Type lower, Type upper) :
m_lower(lower), m_upper(upper)
{
assert(lower <= upper);
}
@@ -29,10 +29,10 @@ namespace skipper
}
/// @copydoc any::operator<<
friend std::ostream& operator<<(std::ostream& os, const range &r)
friend std::ostream& operator<<(std::ostream& os, const range& r)
{
return os << "of type " << typeid(Type).name() << " in ["
<< r.m_lower << "," << r.m_upper << "]";
<< r.m_lower << "," << r.m_upper << "]";
}
private:
View
@@ -17,8 +17,8 @@ namespace skipper
template<typename Type>
struct set
{
set(const std::initializer_list<Type> values)
: m_values(values)
set(const std::initializer_list<Type> values) :
m_values(values)
{}
/// @copydoc any::operator()
@@ -29,10 +29,10 @@ namespace skipper
}
/// @copydoc any::operator<<
friend std::ostream& operator<<(std::ostream& os, const set &s)
friend std::ostream& operator<<(std::ostream& os, const set& s)
{
os << "of type " << typeid(Type).name() << " in {";
for(auto i = s.m_values.begin(); i != s.m_values.end(); i++)
for (auto i = s.m_values.begin(); i != s.m_values.end(); i++)
{
if (i != s.m_values.begin())
os << ",";
View
@@ -9,7 +9,7 @@
#include <gtest/gtest.h>
GTEST_API_ int main(int argc, char **argv)
GTEST_API_ int main(int argc, char** argv)
{
srand(static_cast<uint32_t>(time(0)));
View
@@ -24,7 +24,7 @@ TEST(test_program, void_command)
p.set_ready_indicator("");
stub::call<void(void)> m_print_function;
auto print_function = [&](){m_print_function();};
auto print_function = [&]() {m_print_function();};
p.add_command("p", "print something", print_function);
test_in.str("p\n p\n p\n q\n");
@@ -42,7 +42,7 @@ TEST(test_program, int_set_command)
p.set_ready_indicator("");
stub::call<void(int)> m_function;
std::function<void(int)> function = [&](int value){m_function(value);};
std::function<void(int)> function = [&](int value) {m_function(value);};
p.add_command<int>("a", "help", function, skipper::set<int>({0,7,42,1}));
test_in.str("a\n 42\n a\n -10\n a\n 0\n a\n 7 a\n 11\n");
@@ -60,8 +60,10 @@ TEST(test_program, string_any_command)
p.set_ready_indicator("");
stub::call<void(std::string)> m_function;
std::function<void(std::string)> function =
[&](std::string value){m_function(value);};
std::function<void(std::string)> function = [&](std::string value)
{
m_function(value);
};
p.add_command<std::string>("a", "help", function);
test_in.str("a\n hello\n a\n world\n");
@@ -80,9 +82,9 @@ TEST(test_program, float_range_command)
p.set_ready_indicator("");
stub::call<void(float)> m_function;
std::function<void(float)> function = [&](float value){m_function(value);};
std::function<void(float)> function = [&](float value) {m_function(value);};
p.add_command<float>("a", "help", function,
skipper::range<float>(-4.0F, 7.2F));
skipper::range<float>(-4.0F, 7.2F));
test_in.str("a\n 42\n a\n -1\n a\n 0\n a\n 7\n a\n 11\n");
p.run();
@@ -99,7 +101,7 @@ TEST(test_program, trigger_errors)
p.set_ready_indicator("");
stub::call<void(int)> m_function;
std::function<void(int)> function = [&](int value){m_function(value);};
std::function<void(int)> function = [&](int value) {m_function(value);};
p.add_command<int>("a", "help", function, skipper::range<int>(0, 10));
test_in.str("wrong key\n a\n wrong input\n q\n");
@@ -146,6 +148,6 @@ TEST(test_program, set_exit_key)
// after e\n the program should have terminated, so no second error message
// should appear
EXPECT_EQ("\ndummy\n\nThe following commands are accepted:\n"
"h print this help\ne exit the program\n\n> "
"Invalid command, press 'h' for help\n> ", test_out.str());
"h print this help\ne exit the program\n\n> "
"Invalid command, press 'h' for help\n> ", test_out.str());
}

0 comments on commit 65fed88

Please sign in to comment.