Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:22:35

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Wouter Deconinck, Sylvester Joosten
0003 //
0004 // Dummy that instantiates some objects to trigger compile errors early on in case of
0005 // bugs. This should be migrated to tests TODO.
0006 #include <algorithms/logger.h>
0007 
0008 #include <algorithms/algorithm.h>
0009 #include <algorithms/random.h>
0010 
0011 #include <fmt/ranges.h>
0012 
0013 using namespace algorithms;
0014 
0015 class testLogger : public LoggerMixin {
0016 public:
0017   testLogger() : LoggerMixin("testLogger") {
0018     std::cout << "should display an info message" << std::endl;
0019     info() << "1" << endmsg;
0020     std::cout << "next debug message should not display" << std::endl;
0021     debug() << "2" << endmsg;
0022     level(LogLevel::kTrace);
0023     std::cout << "Changed the log level to trace, so the following message should display"
0024               << std::endl;
0025     debug() << "3" << endmsg;
0026     std::cout << "error message should display" << std::endl;
0027     error() << "4" << endmsg;
0028 
0029     std::cout << std::endl;
0030     info() << "Checking the existing services:" << endmsg;
0031     for (const auto& [key, value] : ServiceSvc::instance().services()) {
0032       info() << " - " << key << endmsg;
0033     }
0034   }
0035 };
0036 
0037 class propTest : public PropertyMixin, LoggerMixin {
0038 public:
0039   propTest() : LoggerMixin("propTest") {}
0040   void print() const {
0041     info() << "integer property: " << m_int << endmsg;
0042     info() << "foo property: " << m_foo << endmsg;
0043     if (hasProperty("bar")) {
0044       info() << "bar property: " << m_bar << endmsg;
0045     }
0046     if (hasProperty("double")) {
0047       info() << "double (non-def.) property: " << m_double << endmsg;
0048     }
0049   }
0050 
0051 private:
0052   Property<int> m_int{this, "integer", 3, "test integer property"};
0053   Property<std::string> m_foo{this, "foo", "foo_property_value", "test foo property"};
0054   // and one without a default
0055   Property<std::string> m_bar{this, "bar", "test bar property without default"};
0056   Property<double> m_double{this, "double", "test double property without default"};
0057 };
0058 
0059 int dummy() {
0060   testLogger tl;
0061 
0062   std::cout << "test of property, will print set properties. Should only print 2 to start (no bar, "
0063                "as it does not have a default value\n";
0064   propTest tp;
0065   tp.print();
0066   tp.setProperty("integer", 10);
0067   tp.print();
0068   try {
0069     tp.setProperty("foo", 1.);
0070     std::cout << "Should not have been reached, as foo does not exist" << std::endl;
0071     return 1;
0072   } catch (...) {
0073     std::cout << "setting a property that didn't exist failed popperly" << std::endl;
0074   }
0075   std::cout
0076       << "Let's now also set a value for the third and fourth property so it gets printed as well"
0077       << std::endl;
0078   tp.setProperty("bar", "bar_value");
0079   tp.setProperty("double", 3.1415f);
0080   tp.print();
0081 
0082   Algorithm<Input<int, double>, Output<double, std::vector<double>>> a{
0083       "myAlgo", {"int", "double"}, {"moredouble", "variable"}, "Test algo"};
0084   fmt::print("Algo input: {}\n", a.inputNames());
0085   fmt::print("Algo output: {}\n", a.outputNames());
0086   // The following won't compile as the number of strings (variable names) and
0087   // input/output tuples don't match
0088   // Algorithm<Input<int, double>, Output<double, std::vector<double>>> a{
0089   //    "myAlgo", {"int", "double"}, {"moredouble", "variable", "bar"}};
0090 
0091   return 0;
0092 }