diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 06512248..7f8eb99d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") add_subdirectory(ex1) add_subdirectory(ex2) add_subdirectory(ex3) +add_subdirectory(ex4) # ---------------------------------------------------------------- # make standard directories for std:: includes explicit diff --git a/example/ex4/CMakeLists.txt b/example/ex4/CMakeLists.txt new file mode 100644 index 00000000..02c1f301 --- /dev/null +++ b/example/ex4/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(ex4 ex4.cpp) +xo_include_options(ex4) diff --git a/example/ex4/ex4.cpp b/example/ex4/ex4.cpp new file mode 100644 index 00000000..82e361db --- /dev/null +++ b/example/ex4/ex4.cpp @@ -0,0 +1,44 @@ +/* @file ex4.cpp */ + +#include "indentlog/scope.hpp" + +using namespace xo; + +class Quadratic { +public: + Quadratic(double a, double b, double c) : a_{a}, b_{b}, c_{c} {} + + double operator() (double x) const { + scope log(XO_ENTER0(info), tag("a", a_), xtag("b", b_), xtag("c", c_), xtag("x", x)); + + double retval = (a_ * x * x) + (b_ * x) + c_; + + log.end_scope("<-", xtag("retval", retval)); + + return retval; + } + +private: + double a_ = 0.0;; + double b_ = 0.0; + double c_ = 0.0; +}; + +int +main(int argc, char ** argv) { + //log_config::style = FS_Pretty; + log_config::style = FS_Streamlined; + log_config::min_log_level = log_level::info; + + scope log(XO_ENTER0(info)); + + Quadratic quadratic(2.0, -5.0, 7.0); + + double x = 3.0; + double r = quadratic(3.0); + + log && log(tag("x", x)); + log && log("<-", xtag("quadratic(x)", r)); +} + +/* end ex4.cpp */