Skip to content

Commit d3f2c27

Browse files
committed
New C++ helper classes.
This adds a few useful C++ helper classes to android/base/ that will be used in the future by other patches. + Add android/base/String.h, a slightly more efficient version of std::string. + Add android/base/containers/StringVector.h, an optimized vector of strings that is much more efficient than std::vector<std::string> and should use less memory. + Add android/base/containers/PodVector.h which defines an efficient std::vector<> equivalent for POD-struct compatible types. + Modify PathUtils.h to use StringVector instead of std::vector<std::string>. + Modify android/utils/file_data.c to get rid of valgrind complaints when running the unit test suite. + Add android/base/Limits.h to get reliable integer limit macros in C++. Change-Id: Id9374aec658383c29be70a798ba17867664f69d3
1 parent 9d69084 commit d3f2c27

17 files changed

+1933
-65
lines changed

Makefile.common

+3
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ common_LOCAL_SRC_FILES += \
118118
android/avd/util.c \
119119
android/sockets.c \
120120
android/sync-utils.c \
121+
android/base/containers/PodVector.cpp \
122+
android/base/containers/StringVector.cpp \
121123
android/base/files/PathUtils.cpp \
122124
android/base/Log.cpp \
125+
android/base/String.cpp \
123126
android/base/StringView.cpp \
124127
android/filesystems/ext4_utils.cpp \
125128
android/utils/assert.c \

Makefile.tests

+3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ EMULATOR_UNITTESTS_SOURCES := \
77
android/utils/file_data_unittest.cpp \
88
android/utils/property_file_unittest.cpp \
99
android/utils/win32_cmdline_quote_unittest.cpp \
10+
android/base/containers/PodVector_unittest.cpp \
11+
android/base/containers/StringVector_unittest.cpp \
1012
android/base/EintrWrapper_unittest.cpp \
1113
android/base/files/PathUtils_unittest.cpp \
1214
android/base/files/ScopedStdioFile_unittest.cpp \
1315
android/base/Log_unittest.cpp \
1416
android/base/memory/ScopedPtr_unittest.cpp \
17+
android/base/String_unittest.cpp \
1518
android/base/StringView_unittest.cpp \
1619
android/filesystems/ext4_utils_unittest.cpp \
1720

android/base/Limits.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Android Open Source Project
2+
//
3+
// This software is licensed under the terms of the GNU General Public
4+
// License version 2, as published by the Free Software Foundation, and
5+
// may be copied, distributed, and modified under those terms.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU General Public License for more details.
11+
12+
#ifndef ANDROID_BASE_LIMITS_H
13+
#define ANDROID_BASE_LIMITS_H
14+
15+
// In C++, <stdint.h> will only define macros like SIZE_MAX if you have
16+
// defined __STDC_LIMIT_MACROS before including <stdint.h>. This header
17+
// is used to do just that and verify that the macros are properly
18+
// defined.
19+
//
20+
// NOTE: We have to define __STDC_FORMAT_MACROS in case the user wants
21+
// to use the corresponding macros as well.
22+
23+
#define __STDC_LIMIT_MACROS 1
24+
#define __STDC_FORMAT_MACROS 1
25+
#include <inttypes.h>
26+
27+
#ifndef SIZE_MAX
28+
#warning "<inttypes.h> has been included before this header."
29+
#warning "This prevents the definition of useful macros."
30+
#error "Please include <android/base/Limits.h> first!"
31+
#endif
32+
33+
#endif // ANDROID_BASE_LIMITS_H

0 commit comments

Comments
 (0)