Search Results for

    Show / Hide Table of Contents

    Class utils::Range

    Inheritance
    utils::Component
    utils::Range
    Inherited Members
    ~Component
    Component
    get_status
    param

    Constructors

    Range()

    Declaration
    utils::Range::Range()

    Range()

    Declaration
    utils::Range::Range(double in_initial, double in_final)

    Methods

    ~Range()

    Declaration
    utils::Range::~Range()

    configure()

    configure the object from input

    Initialize the object's state from the input utils::Config. This is done by declaring which required and optional parameters are associated with the fields of this object. During initialization, they are checked for their presence, type and any matchers. Example:

    MyClass : public Component {
     public:
      void configure(const utils::Json& json) override {
        this->param(json, "number", my_number)
            .description("some description")
            .matches(GreaterEquals(0))
            .required();
        this->param(json, "name", my_name)
            .description("some description")
            .matches(SizeIs(GreaterThan(0)))
            .default_value("no_name");
      }
    
     private:
      int my_number;
      std::string my_name;
    }
    
    MyClass my_object;
    my_object.configure(utils::json_from_string(R"(
      {
        "number": 42,
        "name": "hello"
      }
    )"));
    
    Note

    By default, nothing is configured from input. You need to overload this method if you want to use this functionality. Don't forget to call the configure method of the parent class if it also needs to be configured (this is not the case for utils::Component itself). HINT: Parameters are not limited to scalars and strings; Any component can be a parameter; in which case it is initialized using its own configure method. utils::Json

    Declaration
    void utils::Range::configure(const utils::Json&json) override

    render()

    render the object in structured form

    Return a structured representation of the object. This is intended for output purposes. For instance, the solution your solver finds should have a render method which allows it to be returned as part of the result. Example:

    {c++}
     MySolution : public Component {
      public:
       // Represent the internal bool vector as +-1 output.
       utils::Structure render() const override {
         utils::Structure rendered;
         for (bool item : solution_) rendered.push_back(item ? 1 : -1);
         return rendered;
       }
    
      private:
       std::vector<bool> solution_;
     }
    
     MySolution solution;
     std::cout << solution.render().to_string() << std::endl;
    

    utils::Structure

    Declaration
    Structure utils::Range::render() const override

    get_class_name()

    get_class_name shows an identifier of the (derived) class name

    Its primary use is for type identification during stream output and logging, where a component is rendered as <ClassName: status>. Example:

    {c++}
     MyClass : public Component {}
    
     // This will render as '<MyClass>'
     MyClass my_object;
     std::cout << my_object << std::endl;
    
    Note

    You do not need to overload this method unless you want to change the output of the default implementation.

    Declaration
    std::string utils::Range::get_class_name() const override
    In This Article
    Back to top Generated with Doxygen and DocFX