Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _PARTS_H_
- #define _PARTS_H_
- #include <vector>
- #include <map>
- #include <string>
- //**************** Part ****************
- class Part
- {
- public:
- std::string name;
- int count = 0;
- Part* parent;
- std::vector<Part*> children;
- int count_howmanyUp(Part const* p);
- Part(std::string const& n) : name(n) {};
- void describe(){};
- int count_howmany(Part const* p)
- {
- if (p == this)
- return count;
- int ans = 0;
- for (auto elem : children)
- if (elem == p)
- ans += count_howmany(elem) * count;
- return ans;
- };
- };
- //**************** NameContainer ****************
- class NameContainer
- {
- public:
- NameContainer() {};
- //~NameContainer();
- Part* lookup(std::string const &name)
- {
- return name_map[name];
- };
- void add_part(std::string const &x, int q, std::string const &y)
- {
- lookup(x)->children.push_back(lookup(y));
- lookup(y)->parent = this;
- lookup(y)->count = q;
- lookup(y)->parent = lookup(x);
- };
- private:
- std::map<std::string, Part*> name_map;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement