CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_int_pairs_to_points_map.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, an unpublished work by CodeSecure, Inc.
3  * ALL RIGHTS RESERVED
4  *
5  * Copyright (c) 2013-2023, an unpublished work by GrammaTech, Inc.
6  * ALL RIGHTS RESERVED
7  *
8  * This software is furnished under a license and may be used and
9  * copied only in accordance with the terms of such license and the
10  * inclusion of the above copyright notice. This software or any
11  * other copies thereof may not be provided or otherwise made
12  * available to any other person. Title to and ownership of the
13  * software is retained by CodeSecure, Inc.
14  */
15 
16 #ifndef CS_INT_PAIRS_TO_POINTS_MAP_HPP
17 #define CS_INT_PAIRS_TO_POINTS_MAP_HPP
18 
19 #include "cs_sfileinst_decl.hpp"
20 #include "cs_int_pair_set.h"
21 #include "cs_point_set_decl.hpp"
22 
25 namespace cs{
26 
34  /* Sorry, copy construction not implemented. */
36  cs_ips_to_pdgvs_map inner;
37  public:
38 
39 
53  { check(cs_ips_to_pdgvs_map_open(cglue<sfileinst>::unwrap(sfi), &inner)); }
55  { check(cs_ips_to_pdgvs_map_close(inner)); }
56 
62  CS_BOILERPLATE_HASH_TYPE hash() const
63  { return cs_ips_to_pdgvs_map_hash(inner); }
64 
65 
88  {
89  cs_pdg_vertex_set rv;
90  check(cs_ips_to_pdgvs_map_lookup(inner, i.first, i.second, &rv));
91  return cglue<point_set>::wrap(rv, false);
92  }
93 
94 #if defined(SWIG) && defined(SWIGPYTHON)
95  %rename(__contains__) contains;
96 #endif
97 
118  bool contains(int_pair i) const
119  {
120  cs_pdg_vertex_set rv;
121  cs_result r = cs_ips_to_pdgvs_map_lookup(
122  inner, i.first,
123  i.second, &rv);
124  switch( r )
125  {
126  case CS_SUCCESS:
127  {
128  bool is_empty = !!cs_pdg_vertex_set_empty(rv);
129  cs_pdg_vertex_set_close(rv);
130  return !is_empty;
131  }
132  default:
133  check(r);
134  return false;
135  }
136  }
137 
138 #if defined(SWIG) && defined(SWIGPYTHON)
139  %pythoncode{
140  def __getitem__(self, k):
141  try:
142  return self._getitem_impl(k)
143  except result as r:
144  if r == result.ELEMENT_NOT_PRESENT:
145  raise KeyError(k)
146  raise
147  def get(self, k, dflt=None):
148  try:
149  return self._getitem_impl(k)
150  except result as r:
151  if r == result.ELEMENT_NOT_PRESENT:
152  return dflt
153  raise
154  };
155 #endif
156 
158  std::string as_repr() const
159  { return CS_AS_REPR(int_pairs_to_points_map, std::string("...")); }
160 
162  std::string as_string() const
163  { return as_repr(); }
164 
165 #ifdef SWIG_BUILD
166 
167  bool operator==(const int_pairs_to_points_map& b) const
168  {
169  return !!cs_ips_to_pdgvs_map_same_instance(
170  inner, b.inner);
171  }
172 
173  bool operator!=(const int_pairs_to_points_map& b) const
174  { return !(*this == b); }
175 #else
176 
177  friend bool operator==(const int_pairs_to_points_map& a,
178  const int_pairs_to_points_map& b);
180 #endif
181  };
191  inline std::ostream &operator<<( std::ostream &out,
192  const int_pairs_to_points_map &a )
193  { return out << a.as_repr(); }
194 
195 #ifndef SWIG_BUILD
208  inline bool operator==(const int_pairs_to_points_map& a,
209  const int_pairs_to_points_map& b)
210  {
211  return !!cs_ips_to_pdgvs_map_same_instance(
212  a.inner, b.inner);
213  }
214 
227  inline bool operator!=(const int_pairs_to_points_map& a,
228  const int_pairs_to_points_map& b)
229  { return !(a == b); }
230 #endif
231 
232 }
233 
234 #endif /* CS_INT_PAIRS_TO_POINTS_MAP_HPP */
static const result ELEMENT_NOT_PRESENT
The requested element of the data structure does not exist.
Definition: cs_result_decls.hpp:33
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
std::string as_repr() const
Get a representation of a int_pairs_to_points_map object that includes information useful for debuggi...
Definition: cs_int_pairs_to_points_map.hpp:161
std::string as_string() const
Get a simple string representation of a int_pairs_to_points_map object.
Definition: cs_int_pairs_to_points_map.hpp:167
std::ostream & operator<<(std::ostream &out, const int_pairs_to_points_map &a)
Print a representation of an int_pairs_to_points_map object to the specified stream.
Definition: cs_int_pairs_to_points_map.hpp:196
A set of points (point).
Definition: cs_tplt_instantiations.hpp:214
bool operator!=(const int_pairs_to_points_map &a, const int_pairs_to_points_map &b)
Inquality operator for int_pairs_to_points_map.
Definition: cs_int_pairs_to_points_map.hpp:232
point_set operator[](int_pair i) const
Find a point_set for a specified range of source locations, relative to an int_pairs_to_points_map.
Definition: cs_int_pairs_to_points_map.hpp:87
cs_hash_t hash() const
Hash function for int_pairs_to_points_map.
Definition: cs_int_pairs_to_points_map.hpp:62
The result of an API operation.
Definition: cs_result.hpp:50
int_pairs_to_points_map(sfileinst sfi)
Constructor: create a new int_pairs_to_points_map representing the source location -> point set mappi...
Definition: cs_int_pairs_to_points_map.hpp:52
A source file instance.
Definition: cs_sfileinst_decl.hpp:302
bool operator==(const int_pairs_to_points_map &a, const int_pairs_to_points_map &b)
Equality operator for int_pairs_to_points_map.
Definition: cs_int_pairs_to_points_map.hpp:213
bool contains(int_pair i) const
Check: does an int_pairs_to_points_map include a nonempty mapping for a specified range of source loc...
Definition: cs_int_pairs_to_points_map.hpp:118
A map int_pair_set -> point_set, where each entry represents the mapping from a source position to th...
Definition: cs_int_pairs_to_points_map.hpp:32
std::pair< csuint32, csuint32 > int_pair
A std::pair of integers, used to represent a range of locations in a compilation unit.
Definition: cs_tplt_instantiations.hpp:70