1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
4 // Copyright (c) 2011, 2013 Google Inc.
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
36 // This file is derived from the following files in
37 // toolkit/crashreporter/google-breakpad:
38 // src/common/module.cc
39 // src/common/unique_string.cc
41 // There's no internal-only interface for LulCommon. Hence include
42 // the external interface directly.
43 #include "LulCommonExt.h"
56 ////////////////////////////////////////////////////////////////
59 Module::Module(const string
&name
, const string
&os
,
60 const string
&architecture
, const string
&id
) :
63 architecture_(architecture
),
70 ////////////////////////////////////////////////////////////////
75 explicit UniqueString(string str
) { str_
= strdup(str
.c_str()); }
76 ~UniqueString() { free(reinterpret_cast<void*>(const_cast<char*>(str_
))); }
80 class UniqueStringUniverse
{
82 UniqueStringUniverse() {};
83 const UniqueString
* FindOrCopy(string str
) {
84 std::map
<string
, UniqueString
*>::iterator it
= map_
.find(str
);
85 if (it
== map_
.end()) {
86 UniqueString
* ustr
= new UniqueString(str
);
94 std::map
<string
, UniqueString
*> map_
;
98 const UniqueString
* ToUniqueString(string str
) {
99 // For the initialisation of sUniverse to be threadsafe,
100 // this relies on C++11's semantics.
101 static UniqueStringUniverse sUniverse
;
102 return sUniverse
.FindOrCopy(str
);
105 const char* const FromUniqueString(const UniqueString
* ustr
)