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