CBMC
Loading...
Searching...
No Matches
string_container.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Container for C-Strings
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_UTIL_STRING_CONTAINER_H
13#define CPROVER_UTIL_STRING_CONTAINER_H
14
15#include "memory_units.h"
16#include "string_hash.h"
17
18#include <list>
19#include <string_view>
20#include <unordered_map>
21#include <vector>
22
23// NOLINTNEXTLINE(readability/identifiers)
25{
26public:
27 std::size_t operator()(std::string_view s) const
28 {
29 return hash_string(s);
30 }
31};
32
47
49{
50public:
51 unsigned operator[](std::string_view s)
52 {
53 return get(s);
54 }
55
56 // constructor and destructor
59
60 // the pointer is guaranteed to be stable
61 const char *c_str(size_t no) const
62 {
63 return string_vector[no]->c_str();
64 }
65
66 // the reference is guaranteed to be stable
67 const std::string &get_string(size_t no) const
68 {
69 return *string_vector[no];
70 }
71
73
74protected:
75 // The keys are std::string_views into the std::string objects owned by
76 // string_list below; std::list keeps those addresses stable and the interned
77 // strings are never mutated, so the keys remain valid for the lifetime of
78 // the map.
79 // the 'unsigned' ought to be size_t
80 typedef std::unordered_map<std::string_view, unsigned, string_view_hasht>
83
84 unsigned get(std::string_view);
85
86 typedef std::list<std::string> string_listt;
88
89 typedef std::vector<std::string *> string_vectort;
91};
92
95{
97 return ret;
98}
99
100#endif // CPROVER_UTIL_STRING_CONTAINER_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
std::unordered_map< std::string_view, unsigned, string_view_hasht > hash_tablet
std::vector< std::string * > string_vectort
unsigned get(std::string_view)
string_vectort string_vector
const std::string & get_string(size_t no) const
std::list< std::string > string_listt
unsigned operator[](std::string_view s)
string_listt string_list
const char * c_str(size_t no) const
string_container_statisticst compute_statistics() const
std::size_t operator()(std::string_view s) const
size_t hash_string(const dstringt &s)
Definition dstring.h:240
string_containert & get_string_container()
Get a reference to the global string container.
string hashing
Has estimated statistics about string container (estimated because this only uses public information,...
void dump_on_stream(std::ostream &out) const