Skip to content

Commit

Permalink
Base: First pass at having base.dll: definition of
Browse files Browse the repository at this point in the history
BASE_API and a few files that use it.

BUG=76996
TEST=none
Review URL: http://codereview.chromium.org/6725001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79056 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rvargas@google.com committed Mar 22, 2011
1 parent a75573d commit f53121d
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 233 deletions.
3 changes: 2 additions & 1 deletion base/at_exit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stack>

#include "base/base_api.h"
#include "base/basictypes.h"
#include "base/synchronization/lock.h"

Expand All @@ -27,7 +28,7 @@ namespace base {
// When the exit_manager object goes out of scope, all the registered
// callbacks and singleton destructors will be called.

class AtExitManager {
class BASE_API AtExitManager {
public:
typedef void (*AtExitCallbackType)(void*);

Expand Down
1 change: 1 addition & 0 deletions base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'atomicops.h',
'atomicops_internals_x86_gcc.cc',
'atomicops_internals_x86_msvc.h',
'base_api.h',
'base_paths.cc',
'base_paths.h',
'base_paths_mac.h',
Expand Down
8 changes: 5 additions & 3 deletions base/base64.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -8,15 +8,17 @@

#include <string>

#include "base/base_api.h"

namespace base {

// Encodes the input string in base64. Returns true if successful and false
// otherwise. The output string is only modified if successful.
bool Base64Encode(const std::string& input, std::string* output);
BASE_API bool Base64Encode(const std::string& input, std::string* output);

// Decodes the base64 input string. Returns true if successful and false
// otherwise. The output string is only modified if successful.
bool Base64Decode(const std::string& input, std::string* output);
BASE_API bool Base64Decode(const std::string& input, std::string* output);

} // namespace base

Expand Down
23 changes: 23 additions & 0 deletions base/base_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_BASE_API_H_
#define BASE_BASE_API_H_
#pragma once

#if !defined(BASE_IMPLEMENTATION)
#define BASE_IMPLEMENTATION 0
#endif

#if defined(WIN32) && defined(BASE_DLL)
#if BASE_IMPLEMENTATION
#define BASE_API __declspec(dllexport)
#else
#define BASE_API __declspec(dllimport)
#endif
#else
#define BASE_API
#endif

#endif // BASE_BASE_API_H_
5 changes: 3 additions & 2 deletions base/lazy_instance.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -39,6 +39,7 @@
#include <new> // For placement new.

#include "base/atomicops.h"
#include "base/base_api.h"
#include "base/basictypes.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_restrictions.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ void (*LeakyLazyInstanceTraits<Type>::Delete)(void* instance) = NULL;

// We pull out some of the functionality into a non-templated base, so that we
// can implement the more complicated pieces out of line in the .cc file.
class LazyInstanceHelper {
class BASE_API LazyInstanceHelper {
protected:
enum {
STATE_EMPTY = 0,
Expand Down
7 changes: 4 additions & 3 deletions base/ref_counted.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -7,13 +7,14 @@
#pragma once

#include "base/atomic_ref_count.h"
#include "base/base_api.h"
#include "base/threading/thread_collision_warner.h"

namespace base {

namespace subtle {

class RefCountedBase {
class BASE_API RefCountedBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return false; }

Expand All @@ -39,7 +40,7 @@ class RefCountedBase {
DISALLOW_COPY_AND_ASSIGN(RefCountedBase);
};

class RefCountedThreadSafeBase {
class BASE_API RefCountedThreadSafeBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return true; }

Expand Down
85 changes: 44 additions & 41 deletions base/string_number_conversions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -8,6 +8,7 @@
#include <string>
#include <vector>

#include "base/base_api.h"
#include "base/basictypes.h"
#include "base/string16.h"

Expand All @@ -27,21 +28,21 @@ namespace base {

// Number -> string conversions ------------------------------------------------

std::string IntToString(int value);
string16 IntToString16(int value);
BASE_API std::string IntToString(int value);
BASE_API string16 IntToString16(int value);

std::string UintToString(unsigned value);
string16 UintToString16(unsigned value);
BASE_API std::string UintToString(unsigned value);
BASE_API string16 UintToString16(unsigned value);

std::string Int64ToString(int64 value);
string16 Int64ToString16(int64 value);
BASE_API std::string Int64ToString(int64 value);
BASE_API string16 Int64ToString16(int64 value);

std::string Uint64ToString(uint64 value);
string16 Uint64ToString16(uint64 value);
BASE_API std::string Uint64ToString(uint64 value);
BASE_API string16 Uint64ToString16(uint64 value);

// DoubleToString converts the double to a string format that ignores the
// locale. If you want to use locale specific formatting, use ICU.
std::string DoubleToString(double value);
BASE_API std::string DoubleToString(double value);

// String -> number conversions ------------------------------------------------

Expand All @@ -57,37 +58,38 @@ std::string DoubleToString(double value);
// - No characters parseable as a number at the beginning of the string.
// |*output| will be set to 0.
// - Empty string. |*output| will be set to 0.
bool StringToInt(const std::string& input, int* output);
bool StringToInt(std::string::const_iterator begin,
std::string::const_iterator end,
int* output);
bool StringToInt(const char* begin, const char* end, int* output);

bool StringToInt(const string16& input, int* output);
bool StringToInt(string16::const_iterator begin,
string16::const_iterator end,
int* output);
bool StringToInt(const char16* begin, const char16* end, int* output);

bool StringToInt64(const std::string& input, int64* output);
bool StringToInt64(std::string::const_iterator begin,
std::string::const_iterator end,
int64* output);
bool StringToInt64(const char* begin, const char* end, int64* output);

bool StringToInt64(const string16& input, int64* output);
bool StringToInt64(string16::const_iterator begin,
string16::const_iterator end,
int64* output);
bool StringToInt64(const char16* begin, const char16* end, int64* output);
BASE_API bool StringToInt(const std::string& input, int* output);
BASE_API bool StringToInt(std::string::const_iterator begin,
std::string::const_iterator end,
int* output);
BASE_API bool StringToInt(const char* begin, const char* end, int* output);

BASE_API bool StringToInt(const string16& input, int* output);
BASE_API bool StringToInt(string16::const_iterator begin,
string16::const_iterator end,
int* output);
BASE_API bool StringToInt(const char16* begin, const char16* end, int* output);

BASE_API bool StringToInt64(const std::string& input, int64* output);
BASE_API bool StringToInt64(std::string::const_iterator begin,
std::string::const_iterator end,
int64* output);
BASE_API bool StringToInt64(const char* begin, const char* end, int64* output);

BASE_API bool StringToInt64(const string16& input, int64* output);
BASE_API bool StringToInt64(string16::const_iterator begin,
string16::const_iterator end,
int64* output);
BASE_API bool StringToInt64(const char16* begin, const char16* end,
int64* output);

// For floating-point conversions, only conversions of input strings in decimal
// form are defined to work. Behavior with strings representing floating-point
// numbers in hexadecimal, and strings representing non-fininte values (such as
// NaN and inf) is undefined. Otherwise, these behave the same as the integral
// variants. This expects the input string to NOT be specific to the locale.
// If your input is locale specific, use ICU to read the number.
bool StringToDouble(const std::string& input, double* output);
BASE_API bool StringToDouble(const std::string& input, double* output);

// Hex encoding ----------------------------------------------------------------

Expand All @@ -97,20 +99,21 @@ bool StringToDouble(const std::string& input, double* output);
// you suspect that the data you want to format might be large, the absolute
// max size for |size| should be is
// std::numeric_limits<size_t>::max() / 2
std::string HexEncode(const void* bytes, size_t size);
BASE_API std::string HexEncode(const void* bytes, size_t size);

// Best effort conversion, see StringToInt above for restrictions.
bool HexStringToInt(const std::string& input, int* output);
bool HexStringToInt(std::string::const_iterator begin,
std::string::const_iterator end,
int* output);
bool HexStringToInt(const char* begin, const char* end, int* output);
BASE_API bool HexStringToInt(const std::string& input, int* output);
BASE_API bool HexStringToInt(std::string::const_iterator begin,
std::string::const_iterator end,
int* output);
BASE_API bool HexStringToInt(const char* begin, const char* end, int* output);

// Similar to the previous functions, except that output is a vector of bytes.
// |*output| will contain as many bytes as were successfully parsed prior to the
// error. There is no overflow, but input.size() must be evenly divisible by 2.
// Leading 0x or +/- are not allowed.
bool HexStringToBytes(const std::string& input, std::vector<uint8>* output);
BASE_API bool HexStringToBytes(const std::string& input,
std::vector<uint8>* output);

} // namespace base

Expand Down
5 changes: 3 additions & 2 deletions base/string_piece.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

#include <string>

#include "base/base_api.h"
#include "base/basictypes.h"

namespace base {

class StringPiece {
class BASE_API StringPiece {
public:
// standard STL container boilerplate
typedef size_t size_type;
Expand Down Expand Up @@ -163,7 +164,7 @@ class StringPiece {
size_type length_;
};

bool operator==(const StringPiece& x, const StringPiece& y);
BASE_API bool operator==(const StringPiece& x, const StringPiece& y);

inline bool operator!=(const StringPiece& x, const StringPiece& y) {
return !(x == y);
Expand Down
Loading

0 comments on commit f53121d

Please sign in to comment.