clang-metatool
A framework for reusing code in clang tools
propagation_result.h
Go to the documentation of this file.
1 #ifndef INCLUDED_CLANGMETATOOL_PROPAGATION_PROPAGATION_RESULT_H
2 #define INCLUDED_CLANGMETATOOL_PROPAGATION_PROPAGATION_RESULT_H
3 
4 #include <iostream>
5 
6 namespace clangmetatool {
7 namespace propagation {
8 
15 template <typename ResultType> class PropagationResult {
16 private:
17  bool unresolved;
18  ResultType result;
19 
20 public:
24  PropagationResult() : unresolved(true) {}
25 
29  PropagationResult(const ResultType &result)
30  : unresolved(false), result(result) {}
31 
35  bool isUnresolved() const { return unresolved; }
36 
43  const ResultType &getResult() const { return result; }
44 
50  void print(std::ostream &stream) const {
51  if (unresolved) {
52  stream << "<UNRESOLVED>";
53  } else {
54  stream << result;
55  }
56  }
57 
58  bool operator<(const PropagationResult<ResultType> &rhs) const {
59  return result < rhs.result;
60  }
61  bool operator==(const PropagationResult<ResultType> &rhs) const {
62  if (unresolved && rhs.unresolved) {
63  return true;
64  } else if (unresolved == rhs.unresolved) {
65  return result == rhs.result;
66  }
67 
68  return false;
69  }
70  bool operator!=(const PropagationResult<ResultType> &rhs) const {
71  return !(*this == rhs);
72  }
73 };
74 
75 } // namespace propagation
76 } // namespace clangmetatool
77 
78 template <typename T>
79 std::ostream &
80 operator<<(std::ostream &stream,
82  result.print(stream);
83 
84  return stream;
85 }
86 
87 #endif
88 
89 // ----------------------------------------------------------------------------
90 // Copyright 2018 Bloomberg Finance L.P.
91 //
92 // Licensed under the Apache License, Version 2.0 (the "License");
93 // you may not use this file except in compliance with the License.
94 // You may obtain a copy of the License at
95 //
96 // http://www.apache.org/licenses/LICENSE-2.0
97 //
98 // Unless required by applicable law or agreed to in writing, software
99 // distributed under the License is distributed on an "AS IS" BASIS,
100 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101 // See the License for the specific language governing permissions and
102 // limitations under the License.
103 // ----------------------------- END-OF-FILE ----------------------------------
bool operator!=(const PropagationResult< ResultType > &rhs) const
std::ostream & operator<<(std::ostream &stream, const clangmetatool::propagation::PropagationResult< T > &result)
bool operator==(const PropagationResult< ResultType > &rhs) const
void print(std::ostream &stream) const