carl  24.04
Computer ARithmetic Library
UVariable.h
Go to the documentation of this file.
1 /**
2  * @file UVariable.h
3  * @author Florian Corzilius<corzilius@cs.rwth-aachen.de>
4  * @since 2014-10-30
5  * @version 2014-10-30
6  */
7 
8 #pragma once
9 
11 #include "../sort/Sort.h"
12 #include <carl-common/util/hash.h>
13 #include "../sort/SortManager.h"
14 
15 namespace carl {
16 /**
17  * Implements an uninterpreted variable.
18  */
19 class UVariable {
20 private:
21  /// The according variable, hence, the actual content of this class.
23  /// The domain.
25 
26 public:
27  /**
28  * Default constructor.
29  * The resulting object will not be a valid variable, but a dummy object.
30  */
31  UVariable() = default;
32  UVariable(const UVariable&) = default;
33  UVariable(UVariable&&) = default;
34  UVariable& operator=(const UVariable&) = default;
35  UVariable& operator=(UVariable&&) = default;
36  ~UVariable() = default;
37 
38  explicit UVariable(Variable var)
39  : mVar(var),
40  mDomain(SortManager::getInstance().getInterpreted(var.type())) {}
41 
42  /**
43  * Constructs an uninterpreted variable.
44  * @param var The variable of the uninterpreted variable to construct.
45  * @param domain The domain of the uninterpreted variable to construct.
46  */
48  : mVar(var),
49  mDomain(domain) {}
50 
51  /**
52  * @return The according variable, hence, the actual content of this class.
53  */
54  Variable variable() const {
55  return mVar;
56  }
57 
58  /**
59  * @return The domain of this uninterpreted variable.
60  */
61  Sort domain() const {
62  return mDomain;
63  }
64 };
65 static_assert(std::is_trivially_copyable<UVariable>::value, "UVariable should be trivially copyable.");
66 static_assert(sizeof(UVariable) == sizeof(Variable) + sizeof(Sort), "UVariable should be as large as a Variable and a Sort");
67 
68 /**
69  * Prints the given uninterpreted variable on the given output stream.
70  * @param os The output stream to print on.
71  * @param uvar The uninterpreted variable to print.
72  * @return The output stream after printing the given uninterpreted variable on it.
73  */
74 inline std::ostream& operator<<(std::ostream& os, UVariable uvar) {
75  return os << uvar.variable();
76 }
77 
78 /**
79  * @param lhs The left variable.
80  * @param rhs The right variable.
81  * @return true, if the variable are equal.
82  */
83 bool inline operator==(UVariable lhs, UVariable rhs) {
84  return lhs.variable() == rhs.variable();
85 }
86 
87 /**
88  * @param lhs The left variable.
89  * @param rhs The right variable.
90  * @return true, if the left variable is smaller.
91  */
92 bool inline operator<(UVariable lhs, UVariable rhs) {
93  return lhs.variable() < rhs.variable();
94 }
95 
96 
97 } // end namespace carl
98 
99 namespace std {
100 /**
101  * Implements std::hash for uninterpreted variables.
102  */
103 template<>
104 struct hash<carl::UVariable> {
105 public:
106  /**
107  * @param uvar The uninterpreted variable to get the hash for.
108  * @return The hash of the given uninterpreted variable.
109  */
110  std::size_t operator()(carl::UVariable uvar) const {
111  return carl::hash_all(uvar.variable());
112  }
113 };
114 
115 } // namespace std
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
Definition: hash.h:71
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
static const Variable NO_VARIABLE
Instance of an invalid variable.
Definition: Variable.h:203
Implements a sort (for defining types of variables and functions).
Definition: Sort.h:20
Implements a manager for sorts, containing the actual contents of these sort and allocating their ids...
Definition: SortManager.h:105
Implements an uninterpreted variable.
Definition: UVariable.h:19
UVariable(const UVariable &)=default
UVariable(Variable var, Sort domain)
Constructs an uninterpreted variable.
Definition: UVariable.h:47
~UVariable()=default
Sort domain() const
Definition: UVariable.h:61
Variable mVar
The according variable, hence, the actual content of this class.
Definition: UVariable.h:22
Variable variable() const
Definition: UVariable.h:54
UVariable & operator=(const UVariable &)=default
UVariable(Variable var)
Definition: UVariable.h:38
Sort mDomain
The domain.
Definition: UVariable.h:24
UVariable()=default
Default constructor.
UVariable(UVariable &&)=default
UVariable & operator=(UVariable &&)=default
std::size_t operator()(carl::UVariable uvar) const
Definition: UVariable.h:110