/** * src/uml/class_diagram_model.h * * Copyright (c) 2021 Bartek Kryza * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "decorators.h" #include "util/error.h" #include "util/util.h" #include #include #include #include #include #include #include #include #include #include namespace clanguml { namespace model { namespace class_diagram { enum class scope_t { kPublic, kProtected, kPrivate, kNone }; enum class relationship_t { kNone, kExtension, kComposition, kAggregation, kContainment, kOwnership, kAssociation, kInstantiation, kFriendship, kDependency }; std::string to_string(relationship_t r); struct stylable_element { std::string style; }; struct decorated_element { std::vector> decorators; bool skip() const; bool skip_relationship() const; std::pair relationship() const; std::string style_spec(); }; class element : public decorated_element { public: element(); std::string alias() const; std::string name; std::vector namespace_; protected: const uint64_t m_id{0}; private: static std::atomic_uint64_t m_nextId; }; struct class_element : public decorated_element { scope_t scope; std::string name; std::string type; }; struct class_member : public class_element { bool is_relationship{false}; bool is_static{false}; }; struct method_parameter : public decorated_element { std::string type; std::string name; std::string default_value; std::string to_string( const std::vector &using_namespaces) const; }; struct class_method : public class_element { std::vector parameters; bool is_pure_virtual{false}; bool is_virtual{false}; bool is_const{false}; bool is_defaulted{false}; bool is_static{false}; }; struct class_parent { enum class access_t { kPublic, kProtected, kPrivate }; std::string name; bool is_virtual{false}; access_t access; }; struct class_relationship : public decorated_element, public stylable_element { relationship_t type{relationship_t::kAssociation}; std::string destination; std::string multiplicity_source; std::string multiplicity_destination; std::string label; scope_t scope{scope_t::kNone}; friend bool operator==( const class_relationship &l, const class_relationship &r); }; struct class_template { std::string name; std::string type; std::string default_value; bool is_variadic{false}; friend bool operator==(const class_template &l, const class_template &r); }; struct type_alias { std::string alias; std::string underlying_type; }; class class_ : public element, public stylable_element { public: std::string usr; bool is_struct{false}; bool is_template{false}; bool is_template_instantiation{false}; std::vector members; std::vector methods; std::vector bases; std::vector inner_classes; std::vector relationships; std::vector templates; std::string base_template_usr; std::map type_aliases; friend bool operator==(const class_ &l, const class_ &r); void add_type_alias(type_alias &&ta); void add_relationship(class_relationship &&cr); std::string full_name( const std::vector &using_namespaces) const; bool is_abstract() const; }; struct enum_ : public element, public stylable_element { std::vector constants; std::vector relationships; friend bool operator==(const enum_ &l, const enum_ &r); std::string full_name( const std::vector &using_namespaces) const; }; struct diagram { std::string name; std::vector classes; std::vector enums; std::map type_aliases; bool has_class(const std::string &usr) const; void add_type_alias(type_alias &&ta); void add_class(class_ &&c); void add_enum(enum_ &&e); std::string to_alias(const std::vector &using_namespaces, const std::string &full_name) const; std::string usr_to_name(const std::vector &using_namespaces, const std::string &usr) const; }; } } }