0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
clanguml::common::eid_t Class Reference

Universal class for representing all kinds of Id's in the diagram model. More...

Detailed Description

Universal class for representing all kinds of Id's in the diagram model.

This class provides a convenient way of representing id's in the diagram model. The main problem it solves is that it allows to store both Clang AST ID's (obtained using getID() method), which are local to a single translation unit and have a type int64_t as well as global (across multiple translation units) id's used by clang-uml in the intermediate model (which are uint64_t).

The class is aware which kind of value it holds and tries to ensure that mistakes such as using AST local ID in place where global id is needed do not happen.

Definition at line 47 of file types.h.

#include <types.h>

Public Types

using type = uint64_t
 

Public Member Functions

 eid_t ()
 
 eid_t (int64_t id)
 
 eid_t (type id)
 
 eid_t (const eid_t &)=default
 
 eid_t (eid_t &&) noexcept=default
 
eid_toperator= (const eid_t &)=default
 
eid_toperator= (eid_t &&) noexcept=default
 
eid_toperator= (int64_t ast_id)
 
 ~eid_t ()=default
 
bool is_global () const
 
type value () const
 
int64_t ast_local_value () const
 

Private Attributes

type value_
 
bool is_global_
 

Friends

bool operator== (const eid_t &lhs, const eid_t &rhs)
 
bool operator== (const eid_t &lhs, const uint64_t &v)
 
bool operator!= (const eid_t &lhs, const uint64_t &v)
 
bool operator!= (const eid_t &lhs, const eid_t &rhs)
 
bool operator< (const eid_t &lhs, const eid_t &rhs)
 

Member Typedef Documentation

◆ type

Definition at line 49 of file types.h.

Constructor & Destructor Documentation

◆ eid_t() [1/5]

clanguml::common::eid_t::eid_t ( )

Definition at line 23 of file types.cc.

24 : value_{0ULL}
25 , is_global_{true}
26{
27}

◆ eid_t() [2/5]

clanguml::common::eid_t::eid_t ( int64_t  id)
explicit

Definition at line 29 of file types.cc.

30 : value_{static_cast<type>(id)}
31 , is_global_{false}
32{
33}

◆ eid_t() [3/5]

clanguml::common::eid_t::eid_t ( type  id)
explicit

Definition at line 35 of file types.cc.

36 : value_{id}
37 , is_global_{true}
38{
39}

◆ eid_t() [4/5]

clanguml::common::eid_t::eid_t ( const eid_t )
default

◆ eid_t() [5/5]

clanguml::common::eid_t::eid_t ( eid_t &&  )
defaultnoexcept

◆ ~eid_t()

clanguml::common::eid_t::~eid_t ( )
default

Member Function Documentation

◆ ast_local_value()

int64_t clanguml::common::eid_t::ast_local_value ( ) const

Definition at line 85 of file types.cc.

86{
87 assert(!is_global_);
88
89 return static_cast<int64_t>(value_);
90}

◆ is_global()

bool clanguml::common::eid_t::is_global ( ) const

Definition at line 50 of file types.cc.

50{ return is_global_; }

◆ operator=() [1/3]

eid_t & clanguml::common::eid_t::operator= ( const eid_t )
default

◆ operator=() [2/3]

eid_t & clanguml::common::eid_t::operator= ( eid_t &&  )
defaultnoexcept

◆ operator=() [3/3]

eid_t & clanguml::common::eid_t::operator= ( int64_t  ast_id)

Definition at line 41 of file types.cc.

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}

◆ value()

eid_t::type clanguml::common::eid_t::value ( ) const

Definition at line 83 of file types.cc.

83{ return value_; }

Friends And Related Symbol Documentation

◆ operator!= [1/2]

bool operator!= ( const eid_t lhs,
const eid_t rhs 
)
friend

Definition at line 72 of file types.cc.

72{ return !(lhs == rhs); }

◆ operator!= [2/2]

bool operator!= ( const eid_t lhs,
const uint64_t &  v 
)
friend

Definition at line 59 of file types.cc.

60{
61 // This is sadly necessary to catch accidental comparisons to empty
62 // std::optional<id_t>:
63 //
64 // std::optional<id_t> id{};
65 // if(id != 0) { /* id is nullopt, not 0 - so this executes... */ }
66 //
67 assert(v != 0);
68
69 return lhs.value_ != v;
70}

◆ operator<

bool operator< ( const eid_t lhs,
const eid_t rhs 
)
friend

Definition at line 74 of file types.cc.

75{
76 if (lhs.is_global_ != rhs.is_global_) {
77 return lhs.value_ < rhs.value_ + 1;
78 }
79
80 return lhs.value_ < rhs.value_; // Compare values if is_global_ are the same
81}

◆ operator== [1/2]

bool operator== ( const eid_t lhs,
const eid_t rhs 
)
friend

Definition at line 52 of file types.cc.

53{
54 return (lhs.is_global_ == rhs.is_global_) && (lhs.value_ == rhs.value_);
55}

◆ operator== [2/2]

bool operator== ( const eid_t lhs,
const uint64_t &  v 
)
friend

Definition at line 57 of file types.cc.

57{ return lhs.value_ == v; }

Member Data Documentation

◆ is_global_

bool clanguml::common::eid_t::is_global_
private

Definition at line 80 of file types.h.

◆ value_

type clanguml::common::eid_t::value_
private

Definition at line 79 of file types.h.


The documentation for this class was generated from the following files: