SSoelvsten / adiar

An I/O-efficient implementation of (Binary) Decision Diagrams
https://ssoelvsten.github.io/adiar/
MIT License
24 stars 13 forks source link

Move data_types/ `toString` method from test/ to src/ #414

Open SSoelvsten opened 1 year ago

SSoelvsten commented 1 year ago

In test/test.h we have several stringizer functions that create pretty-printed version of the basic data types. These ought to be moved over into the respective classes in src/ such that they can be used in other ways, e.g. debugging and exceptions.

For each data type we ought to

  1. Create an << operator overloading that gets and returns a std::ostream&.
  2. Add a to_string() method that returns the std::string constructed with a std::stringstream.
  3. Add unit tests, that make sure, they look as they are supposed to.

Data Types

ryuusama09 commented 1 year ago

Hey @SSoelvsten do you mean test/test.cpp ? . Also the paths that you have mentioned do not exist . Can you specify the entire path

SSoelvsten commented 1 year ago

The paths are based on the major refactor in #397 where lots of stuff has been moved around (and also, I mistakenly wrote the C include path rather than the project path; I fixed them now to be relative to the root of the repo, but I apologize for the confusion).

If you are interested in contributing, your contribution should build on-top of and be pull requested for the internal-cleanup branch, not main.

ryuusama09 commented 1 year ago

I would like to help here @SSoelvsten . I am a beginner so,can you tell me what to by giving a single example, so it will be clear for me as in how to proceed . Thank you

SSoelvsten commented 1 year ago

The following is a minimal example of how one creates a to_string method and a << overload for a custom type (class) in C++

class A
{
private:
  int a1;
  int a2;

public:
  A(int arg_1, int arg_2)
    : a1(arg_1), a2(arg_2)
  { }

public:
  std::string to_string() const
  {
    std::stringstream ss;
    ss << "A(" << a1 << "," << a2 << ")";
    return ss.str();
  }
};

std::ostream& operator<< (std::ostream& os, const A &a)
{ return os << a.to_string(); }