diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-10-16 17:54:43 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-10-23 10:38:44 -0400 |
commit | bf452ce511554505ee36648524be968a73735dde (patch) | |
tree | 5fcc283c790f3171495e58c0df5c633e47993ad1 /src/mongo/platform | |
parent | 60d3d923812932848a439cf0c3811c8de654a62f (diff) | |
download | mongo-bf452ce511554505ee36648524be968a73735dde.tar.gz |
Introduce mongo/platform/cstdint.h, to get stdint types into the mongo namespace.
Pre C++-11, GCC and MSVC put these in different files and namespaces. This
header consolidates the logic of finding them.
Diffstat (limited to 'src/mongo/platform')
-rw-r--r-- | src/mongo/platform/cstdint.h | 47 | ||||
-rw-r--r-- | src/mongo/platform/random.cpp | 5 | ||||
-rw-r--r-- | src/mongo/platform/random.h | 12 |
3 files changed, 54 insertions, 10 deletions
diff --git a/src/mongo/platform/cstdint.h b/src/mongo/platform/cstdint.h new file mode 100644 index 00000000000..496ac644c34 --- /dev/null +++ b/src/mongo/platform/cstdint.h @@ -0,0 +1,47 @@ +/* + * Copyright 2012 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/** + * Include "mongo/platform/cstdint.h" to get the C++11 cstdint types in namespace mongo. + */ + +#if defined(_MSC_VER) +#include <cstdint> +#define _MONGO_STDINT_NAMESPACE std +#elif defined(__GNUC__) +#include <tr1/cstdint> +#define _MONGO_STDINT_NAMESPACE std::tr1 +#else +#error "Unsupported compiler family" +#endif + +namespace mongo { + using _MONGO_STDINT_NAMESPACE::int8_t; + using _MONGO_STDINT_NAMESPACE::int16_t; + using _MONGO_STDINT_NAMESPACE::int32_t; + using _MONGO_STDINT_NAMESPACE::int64_t; + using _MONGO_STDINT_NAMESPACE::intptr_t; + + using _MONGO_STDINT_NAMESPACE::uint8_t; + using _MONGO_STDINT_NAMESPACE::uint16_t; + using _MONGO_STDINT_NAMESPACE::uint32_t; + using _MONGO_STDINT_NAMESPACE::uint64_t; + using _MONGO_STDINT_NAMESPACE::uintptr_t; +} // namespace mongo + +#undef _MONGO_STDINT_NAMESPACE diff --git a/src/mongo/platform/random.cpp b/src/mongo/platform/random.cpp index e7ccecf6634..5eb596186ab 100644 --- a/src/mongo/platform/random.cpp +++ b/src/mongo/platform/random.cpp @@ -15,9 +15,12 @@ * limitations under the License. */ -#include "mongo/platform/basic.h" #include "mongo/platform/random.h" +#include <cstdlib> + +#include "mongo/platform/basic.h" + namespace mongo { #ifdef _WIN32 diff --git a/src/mongo/platform/random.h b/src/mongo/platform/random.h index 84d34a05a7c..f28b929de91 100644 --- a/src/mongo/platform/random.h +++ b/src/mongo/platform/random.h @@ -17,19 +17,13 @@ #pragma once -#ifdef _WIN32 -#include <cstdint> -#else -#include <inttypes.h> -#endif - -#include <cstdlib> +#include "mongo/platform/cstdint.h" namespace mongo { - + class PseudoRandom { public: - PseudoRandom( unsigned seed ) + PseudoRandom( unsigned seed ) : _seed( seed ) { } |