carl  24.04
Computer ARithmetic Library
UFInstance.h
Go to the documentation of this file.
1 /**
2  * @file UFInstance.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 "UVariable.h"
12 #include "UninterpretedFunction.h"
13 
14 #include <iostream>
15 #include <utility>
16 #include <vector>
17 
18 namespace carl
19 {
20  class UTerm;
21 
22  /**
23  * Implements an uninterpreted function instance.
24  */
25  class UFInstance {
26  public:
27  friend class UFInstanceManager;
28 
29  private:
30  /// A unique id.
31  std::size_t mId = 0;
32 
33  /**
34  * Constructs an uninterpreted function instance.
35  * @param id
36  */
37  explicit UFInstance(std::size_t id) noexcept: mId(id) {}
38 
39  public:
40  UFInstance() = default;
41  /**
42  * @return The unique id of this uninterpreted function instance.
43  */
44  std::size_t id() const {
45  return mId;
46  }
47 
48  /**
49  * @return The underlying uninterpreted function of this instance.
50  */
52 
53  /**
54  * @return The arguments of this uninterpreted function instance.
55  */
56  const std::vector<UTerm>& args() const;
57 
58  std::size_t complexity() const;
59 
60  void gatherVariables(carlVariables& vars) const;
61  void gatherUFs(std::set<UninterpretedFunction>& ufs) const;
62  };
63 
64  static_assert(std::is_trivially_copyable<UFInstance>::value, "UFInstance should be trivially copyable.");
65  static_assert(sizeof(UFInstance) == sizeof(std::size_t), "UFInstance should be as large as its id");
66 
67  /**
68  * @param lhs The left function instance.
69  * @param rhs The right function instance.
70  * @return true, if lhs == rhs.
71  */
72  inline bool operator==(const UFInstance& lhs, const UFInstance& rhs) {
73  return lhs.id() == rhs.id();
74  }
75 
76  /**
77  * @param lhs The left function instance.
78  * @param rhs The right function instance.
79  * @return true, if lhs < rhs.
80  */
81  inline bool operator<(const UFInstance& lhs, const UFInstance& rhs) {
82  return lhs.id() < rhs.id();
83  }
84 
85  /**
86  * Prints the given uninterpreted function instance on the given output stream.
87  * @param os The output stream to print on.
88  * @param ufun The uninterpreted function instance to print.
89  * @return The output stream after printing the given uninterpreted function instance on it.
90  */
91  std::ostream& operator<<(std::ostream& os, const UFInstance& ufun);
92 } // end namespace carl
93 
94 namespace std {
95  /**
96  * Implements std::hash for uninterpreted function instances.
97  */
98  template<>
99  struct hash<carl::UFInstance> {
100  public:
101  /**
102  * @param ufi The uninterpreted function instance to get the hash for.
103  * @return The hash of the given uninterpreted function instance.
104  */
105  std::size_t operator()(const carl::UFInstance& ufi) const {
106  return carl::hash_all(ufi.id());
107  }
108  };
109 }
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 an uninterpreted function instance.
Definition: UFInstance.h:25
void gatherUFs(std::set< UninterpretedFunction > &ufs) const
Definition: UFInstance.cpp:44
std::size_t complexity() const
Definition: UFInstance.cpp:29
void gatherVariables(carlVariables &vars) const
Definition: UFInstance.cpp:39
UFInstance()=default
const UninterpretedFunction & uninterpretedFunction() const
Definition: UFInstance.cpp:21
std::size_t id() const
Definition: UFInstance.h:44
UFInstance(std::size_t id) noexcept
Constructs an uninterpreted function instance.
Definition: UFInstance.h:37
std::size_t mId
A unique id.
Definition: UFInstance.h:31
const std::vector< UTerm > & args() const
Definition: UFInstance.cpp:25
std::size_t operator()(const carl::UFInstance &ufi) const
Definition: UFInstance.h:105
Implements a manager for uninterpreted function instances, containing their actual contents and alloc...
Implements an uninterpreted function.