carl  24.04
Computer ARithmetic Library
SortValue.h
Go to the documentation of this file.
1 /**
2  * @file SortValue.h
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  * @since 2014-10-24
5  * @version 2014-10-24
6  */
7 
8 #pragma once
9 
10 #include <carl-common/util/hash.h>
11 #include <carl-formula/sort/Sort.h>
12 
13 #include <cassert>
14 #include <iostream>
15 #include <utility>
16 
17 namespace carl {
18 
19 /**
20  * Implements a sort value, being a value of the uninterpreted domain specified by this sort.
21  */
22 class SortValue {
23 public:
24  friend class SortValueManager;
25 
26 private:
27  // Members.
28 
29  /// The sort defining the domain in which this value is.
31  /// A unique id to identify this sort in the sort value manager.
32  std::size_t mId = 0;
33 
34  /**
35  * Constructs a sort value.
36  * @parem _sort The sort.
37  * @param _id The id of the sort value to construct.
38  */
39  explicit SortValue(Sort _sort, std::size_t _id)
40  : mSort(_sort),
41  mId(_id) {}
42 
43 public:
44  SortValue() noexcept = default;
45 
46  /**
47  * @return The sort of this value.
48  */
49  const carl::Sort& sort() const noexcept {
50  return mSort;
51  }
52 
53  /**
54  * @return The id of this sort value.
55  */
56  std::size_t id() const noexcept {
57  return mId;
58  }
59 };
60 
61 /**
62  * Prints the given sort value on the given output stream.
63  * @param os The output stream to print on.
64  * @param sv The sort value to print.
65  * @return The output stream after printing the given sort value on it.
66  */
67 inline std::ostream& operator<<(std::ostream& os, const SortValue& sv) {
68  return os << sv.sort() << "!val!" << sv.id();
69 }
70 
71 /**
72  * Compares two sort values for equality.
73  */
74 inline bool operator==(const SortValue& lhs, const SortValue& rhs) {
75  assert(lhs.sort() == rhs.sort());
76  return lhs.id() == rhs.id();
77 }
78 
79 /**
80  * Orders two sort values.
81  */
82 inline bool operator<(const SortValue& lhs, const SortValue& rhs) {
83  assert(lhs.sort() == rhs.sort());
84  return lhs.id() < rhs.id();
85 }
86 
87 } // namespace carl
88 
89 namespace std {
90 /**
91  * Implements std::hash for sort value.
92  */
93 template<>
94 struct hash<carl::SortValue> {
95  /**
96  * @param sv The sort value to get the hash for.
97  * @return The hash of the given sort value.
98  */
99  std::size_t operator()(const carl::SortValue& sv) const {
100  return carl::hash_all(sv.id(), sv.sort());
101  }
102 };
103 } // 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
Implements a sort (for defining types of variables and functions).
Definition: Sort.h:20
Implements a sort value, being a value of the uninterpreted domain specified by this sort.
Definition: SortValue.h:22
std::size_t mId
A unique id to identify this sort in the sort value manager.
Definition: SortValue.h:32
std::size_t id() const noexcept
Definition: SortValue.h:56
SortValue(Sort _sort, std::size_t _id)
Constructs a sort value.
Definition: SortValue.h:39
carl::Sort mSort
The sort defining the domain in which this value is.
Definition: SortValue.h:30
const carl::Sort & sort() const noexcept
Definition: SortValue.h:49
SortValue() noexcept=default
std::size_t operator()(const carl::SortValue &sv) const
Definition: SortValue.h:99
Implements a manager for sort values, containing the actual contents of these sort and allocating the...