xref: /aosp_15_r20/external/google-breakpad/src/common/long_string_dictionary.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // Copyright 2017 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //     * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef COMMON_LONG_STRING_DICTIONARY_H_
30 #define COMMON_LONG_STRING_DICTIONARY_H_
31 
32 #include <string>
33 
34 #include "common/simple_string_dictionary.h"
35 
36 namespace google_breakpad {
37 // key_size is the maxium size that |key| can take in
38 // SimpleStringDictionary which is defined in simple_string_dictionary.h.
39 //
40 // value_size is the maxium size that |value| can take in
41 // SimpleStringDictionary which is defined in simple_string_dictionary.h.
42 //
43 // LongStringDictionary is a subclass of SimpleStringDictionary which supports
44 // longer values to be stored in the dictionary. The maximum length supported is
45 // (value_size - 1) * 10.
46 //
47 // For example, LongStringDictionary will store long value with key 'abc' into
48 // segment values with segment keys 'abc__1', 'abc__2', 'abc__3', ...
49 //
50 // Clients must avoid using the same suffixes as their key's suffix when
51 // LongStringDictionary is used.
52 class LongStringDictionary : public SimpleStringDictionary {
53  public:
54   // Stores |value| into |key|, or segment values into segment keys. The maxium
55   // number of segments is 10. If |value| can not be stored in 10 segments, it
56   // will be truncated. Replacing the existing value if |key| is already present
57   // and replacing the existing segment values if segment keys are already
58   // present.
59   //
60   // |key| must not be NULL. If the |value| need to be divided into segments,
61   // the lengh of |key| must be smaller enough so that lengths of segment keys
62   // which are key with suffixes are all samller than (key_size - 1). Currently,
63   // the max length of suffixes are 4.
64   //
65   // If |value| is NULL, the key and its corresponding segment keys are removed
66   // from the map. If there is no more space in the map, then the operation
67   // silently fails.
68   void SetKeyValue(const char* key, const char* value);
69 
70   // Given |key|, removes any associated value or associated segment values.
71   // |key| must not be NULL. If the key is not found, searchs its segment keys
72   // and removes corresponding segment values if found.
73   bool RemoveKey(const char* key);
74 
75   // Given |key|, returns its corresponding |value|. |key| must not be NULL. If
76   // the key is found, its corresponding |value| is returned.
77   //
78   // If no corresponding |value| is found, segment keys of the given |key| will
79   // be used to search for corresponding segment values. If segment values
80   // exist, assembled value from them is returned. If no segment value exists,
81   // NULL is returned.
82   const std::string GetValueForKey(const char* key) const;
83 };
84 } // namespace google_breakpad
85 
86 #endif // COMMON_LONG_STRING_DICTIONARY_H_
87