0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
types.cc
Go to the documentation of this file.
1/**
2 * @file src/common/types.cc
3 *
4 * Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "types.h"
20
21namespace clanguml::common {
22
24 : value_{0ULL}
25 , is_global_{true}
26{
27}
28
29eid_t::eid_t(int64_t id)
30 : value_{static_cast<type>(id)}
31 , is_global_{false}
32{
33}
34
36 : value_{id}
37 , is_global_{true}
38{
39}
40
41eid_t &eid_t::operator=(int64_t ast_id)
42{
43 // Can't assign ast_id if the id is already a global one
44 assert(!is_global_);
45
46 value_ = static_cast<uint64_t>(ast_id);
47 return *this;
48}
49
50bool eid_t::is_global() const { return is_global_; }
51
52bool operator==(const eid_t &lhs, const eid_t &rhs)
53{
54 return (lhs.is_global_ == rhs.is_global_) && (lhs.value_ == rhs.value_);
55}
56
57bool operator==(const eid_t &lhs, const uint64_t &v) { return lhs.value_ == v; }
58
59bool operator!=(const eid_t &lhs, const uint64_t &v)
60{
61 assert(v != 0);
62
63 return lhs.value_ != v;
64}
65
66bool operator!=(const eid_t &lhs, const eid_t &rhs) { return !(lhs == rhs); }
67
68bool operator<(const eid_t &lhs, const eid_t &rhs)
69{
70 if (lhs.is_global_ != rhs.is_global_) {
71 return lhs.value_ < rhs.value_ + 1;
72 }
73
74 return lhs.value_ < rhs.value_; // Compare values if is_global_ are the same
75}
76
77eid_t::type eid_t::value() const { return value_; }
78
80{
81 assert(!is_global_);
82
83 return static_cast<int64_t>(value_);
84}
85
86std::string to_string(const bool v) { return v ? "true" : "false"; }
87
88std::string to_string(const std::string &s) { return s; }
89
90std::string to_string(const string_or_regex &sr) { return sr.to_string(); }
91
92std::string to_string(const std::filesystem::path &p) { return p.string(); }
93
94std::string to_string(const generator_type_t type)
95{
96 switch (type) {
98 return "plantuml";
100 return "mermaid";
102 return "json";
104 return "graphml";
105 default:
106 return "<unknown>";
107 }
108}
109} // namespace clanguml::common