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