This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new 154bbf1 GEODE-7612: Technical debt 01 - remove inlining in logging
and statistics classes (#563)
154bbf1 is described below
commit 154bbf17b6b94bdf012a3c06801015bd4d997601
Author: Matthew Reddington <[email protected]>
AuthorDate: Mon Dec 23 13:31:54 2019 -0800
GEODE-7612: Technical debt 01 - remove inlining in logging and statistics
classes (#563)
* Moved some implementation from headers into source files. Replaced some
usage of NonCopyable and NonAssignable. Also, in C++ 11 you are explicitly
allowed to default a virtual destructor.
* Changed some implementation in Log::enabled and Log::debugEnabled on
account of Apple - sins hidden by inline complicating matters.
---
.gitignore | 1 +
cppcache/src/Log.cpp | 214 +++++++++++++++
cppcache/src/TcrMessage.cpp | 1 +
cppcache/src/statistics/AtomicStatisticsImpl.hpp | 25 +-
cppcache/src/statistics/GeodeStatisticsFactory.hpp | 7 +-
cppcache/src/statistics/HostStatSampler.hpp | 10 +-
cppcache/src/statistics/OsStatisticsImpl.hpp | 36 +--
cppcache/src/statistics/PoolStatsSampler.hpp | 2 +-
cppcache/src/statistics/ProcessStats.cpp | 8 -
cppcache/src/statistics/ProcessStats.hpp | 10 +-
cppcache/src/statistics/StatArchiveWriter.cpp | 3 +
cppcache/src/statistics/StatArchiveWriter.hpp | 39 +--
cppcache/src/statistics/StatSamplerStats.hpp | 1 -
cppcache/src/statistics/StatisticDescriptor.hpp | 9 +-
.../src/statistics/StatisticDescriptorImpl.hpp | 17 --
cppcache/src/statistics/Statistics.hpp | 10 -
cppcache/src/statistics/StatisticsFactory.hpp | 10 +-
cppcache/src/statistics/StatisticsManager.cpp | 13 +
cppcache/src/statistics/StatisticsManager.hpp | 11 +-
cppcache/src/statistics/StatisticsType.hpp | 6 +-
cppcache/src/statistics/StatisticsTypeImpl.hpp | 12 -
cppcache/src/statistics/StatsDef.hpp | 3 -
cppcache/src/util/JavaModifiedUtf8.cpp | 155 +++++++++++
cppcache/src/util/JavaModifiedUtf8.hpp | 128 +--------
cppcache/src/util/Log.hpp | 292 ++++-----------------
.../util/chrono/{time_point.hpp => time_point.cpp} | 41 +--
cppcache/src/util/chrono/time_point.hpp | 48 +---
.../concurrent/spinlock_mutex.cpp} | 25 +-
cppcache/src/util/concurrent/spinlock_mutex.hpp | 10 +-
cppcache/src/util/queue.hpp | 2 +-
cppcache/src/util/{string.hpp => string.cpp} | 23 +-
cppcache/src/util/string.hpp | 135 +---------
32 files changed, 525 insertions(+), 782 deletions(-)
diff --git a/.gitignore b/.gitignore
index 9e0f0cd..9db11cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@
.ruby-version
.DS_Store
+.history/
diff --git a/cppcache/src/Log.cpp b/cppcache/src/Log.cpp
index 07d8362..c5e0a30 100644
--- a/cppcache/src/Log.cpp
+++ b/cppcache/src/Log.cpp
@@ -177,6 +177,13 @@ using apache::geode::log::globals::g_uname;
/*****************************************************************************/
+LogLevel Log::logLevel() { return s_logLevel; }
+
+/**
+ * Set the current log level.
+ */
+void Log::setLogLevel(LogLevel level) { s_logLevel = level; }
+
void Log::init(LogLevel level, const char* logFileName, int32_t logFileLimit,
int64_t logDiskSpaceLimit) {
if (g_log != nullptr) {
@@ -718,6 +725,181 @@ void Log::exitFn(LogLevel level, const char*
functionName) {
put(level, buf);
}
+bool Log::enabled(LogLevel level) {
+#ifdef DEBUG
+ return (((level == LogLevel::Debug) || GEODE_HIGHEST_LOG_LEVEL >= level) &&
+ s_logLevel >= level);
+#else
+ return (((level != LogLevel::Debug) && GEODE_HIGHEST_LOG_LEVEL >= level) &&
+ s_logLevel >= level);
+#endif
+}
+
+void Log::log(LogLevel level, const char* msg) {
+ if (enabled(level)) put(level, msg);
+}
+
+void Log::logThrow(LogLevel level, const char* msg, const Exception& ex) {
+ if (enabled(level)) putThrow(level, msg, ex);
+}
+
+void Log::logCatch(LogLevel level, const char* msg, const Exception& ex) {
+ if (enabled(level)) putCatch(level, msg, ex);
+}
+
+bool Log::errorEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Error &&
+ s_logLevel >= LogLevel::Error;
+}
+
+void Log::error(const char* msg) {
+ if (errorEnabled()) put(LogLevel::Error, msg);
+}
+
+void Log::error(const std::string& msg) {
+ if (errorEnabled()) put(LogLevel::Error, msg.c_str());
+}
+
+void Log::errorThrow(const char* msg, const Exception& ex) {
+ if (errorEnabled()) putThrow(LogLevel::Error, msg, ex);
+}
+
+void Log::errorCatch(const char* msg, const Exception& ex) {
+ if (errorEnabled()) putCatch(LogLevel::Error, msg, ex);
+}
+
+bool Log::warningEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Warning &&
+ s_logLevel >= LogLevel::Warning;
+}
+
+void Log::warning(const char* msg) {
+ if (warningEnabled()) put(LogLevel::Warning, msg);
+}
+
+void Log::warningThrow(const char* msg, const Exception& ex) {
+ if (warningEnabled()) putThrow(LogLevel::Warning, msg, ex);
+}
+
+void Log::warningCatch(const char* msg, const Exception& ex) {
+ if (warningEnabled()) putCatch(LogLevel::Warning, msg, ex);
+}
+
+bool Log::infoEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Info &&
+ s_logLevel >= LogLevel::Info;
+}
+
+void Log::info(const char* msg) {
+ if (infoEnabled()) put(LogLevel::Info, msg);
+}
+
+void Log::infoThrow(const char* msg, const Exception& ex) {
+ if (infoEnabled()) putThrow(LogLevel::Info, msg, ex);
+}
+
+void Log::infoCatch(const char* msg, const Exception& ex) {
+ if (infoEnabled()) putCatch(LogLevel::Info, msg, ex);
+}
+
+bool Log::configEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Config &&
+ s_logLevel >= LogLevel::Config;
+}
+
+void Log::config(const char* msg) {
+ if (configEnabled()) put(LogLevel::Config, msg);
+}
+
+void Log::configThrow(const char* msg, const Exception& ex) {
+ if (configEnabled()) putThrow(LogLevel::Config, msg, ex);
+}
+
+void Log::configCatch(const char* msg, const Exception& ex) {
+ if (configEnabled()) putCatch(LogLevel::Config, msg, ex);
+}
+
+bool Log::fineEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Fine &&
+ s_logLevel >= LogLevel::Fine;
+}
+
+void Log::fine(const char* msg) {
+ if (fineEnabled()) put(LogLevel::Fine, msg);
+}
+
+void Log::fineThrow(const char* msg, const Exception& ex) {
+ if (fineEnabled()) putThrow(LogLevel::Fine, msg, ex);
+}
+
+void Log::fineCatch(const char* msg, const Exception& ex) {
+ if (fineEnabled()) putCatch(LogLevel::Fine, msg, ex);
+}
+
+bool Log::finerEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Finer &&
+ s_logLevel >= LogLevel::Finer;
+}
+
+void Log::finer(const char* msg) {
+ if (finerEnabled()) put(LogLevel::Finer, msg);
+}
+
+void Log::finerThrow(const char* msg, const Exception& ex) {
+ if (finerEnabled()) putThrow(LogLevel::Finer, msg, ex);
+}
+
+void Log::finerCatch(const char* msg, const Exception& ex) {
+ if (finerEnabled()) putCatch(LogLevel::Finer, msg, ex);
+}
+
+bool Log::finestEnabled() {
+ return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Finest &&
+ s_logLevel >= LogLevel::Finest;
+}
+
+void Log::finest(const char* msg) {
+ if (finestEnabled()) put(LogLevel::Finest, msg);
+}
+
+void Log::finestThrow(const char* msg, const Exception& ex) {
+ if (finestEnabled()) putThrow(LogLevel::Finest, msg, ex);
+}
+
+void Log::finestCatch(const char* msg, const Exception& ex) {
+ if (finestEnabled()) putCatch(LogLevel::Finest, msg, ex);
+}
+
+bool Log::debugEnabled() {
+#ifdef DEBUG
+ return s_logLevel >= LogLevel::Debug;
+#else
+ return (GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Debug) &&
+ s_logLevel >= LogLevel::Debug;
+#endif
+}
+
+void Log::debug(const char* msg) {
+ if (debugEnabled()) put(LogLevel::Debug, msg);
+}
+
+void Log::debugThrow(const char* msg, const Exception& ex) {
+ if (debugEnabled()) putThrow(LogLevel::Debug, msg, ex);
+}
+
+void Log::debugCatch(const char* msg, const Exception& ex) {
+ if (debugEnabled()) putCatch(LogLevel::Debug, msg, ex);
+}
+
+LogFn::LogFn(const char* functionName, LogLevel level)
+ : m_functionName(functionName), m_level(level) {
+ if (Log::enabled(m_level)) Log::enterFn(m_level, m_functionName);
+}
+
+LogFn::~LogFn() {
+ if (Log::enabled(m_level)) Log::exitFn(m_level, m_functionName);
+}
+
// var arg logging routines.
#ifdef _WIN32
@@ -804,6 +986,38 @@ void LogVarargs::finest(const char* fmt, ...) {
va_end(argp);
}
+void LogVarargs::debug(const std::string& message) {
+ Log::put(LogLevel::Debug, message.c_str());
+}
+
+void LogVarargs::error(const std::string& message) {
+ Log::put(LogLevel::Error, message.c_str());
+}
+
+void LogVarargs::warn(const std::string& message) {
+ Log::put(LogLevel::Warning, message.c_str());
+}
+
+void LogVarargs::info(const std::string& message) {
+ Log::put(LogLevel::Info, message.c_str());
+}
+
+void LogVarargs::config(const std::string& message) {
+ Log::put(LogLevel::Config, message.c_str());
+}
+
+void LogVarargs::fine(const std::string& message) {
+ Log::put(LogLevel::Fine, message.c_str());
+}
+
+void LogVarargs::finer(const std::string& message) {
+ Log::put(LogLevel::Finer, message.c_str());
+}
+
+void LogVarargs::finest(const std::string& message) {
+ Log::put(LogLevel::Finest, message.c_str());
+}
+
} // namespace client
} // namespace geode
} // namespace apache
diff --git a/cppcache/src/TcrMessage.cpp b/cppcache/src/TcrMessage.cpp
index 66b0d8e..aeb3917 100644
--- a/cppcache/src/TcrMessage.cpp
+++ b/cppcache/src/TcrMessage.cpp
@@ -40,6 +40,7 @@
#include "ThinClientPoolDM.hpp"
#include "ThinClientRegion.hpp"
#include "util/JavaModifiedUtf8.hpp"
+#include "util/string.hpp"
#pragma error_messages(off, SEC_UNINITIALIZED_MEM_READ)
diff --git a/cppcache/src/statistics/AtomicStatisticsImpl.hpp
b/cppcache/src/statistics/AtomicStatisticsImpl.hpp
index 2a8dfdf..bab5919 100644
--- a/cppcache/src/statistics/AtomicStatisticsImpl.hpp
+++ b/cppcache/src/statistics/AtomicStatisticsImpl.hpp
@@ -25,7 +25,6 @@
#include <geode/internal/geode_globals.hpp>
-#include "../NonCopyable.hpp"
#include "Statistics.hpp"
#include "StatisticsFactory.hpp"
#include "StatisticsTypeImpl.hpp"
@@ -42,9 +41,7 @@ namespace statistics {
* in local memory and support atomic operations
*
*/
-class AtomicStatisticsImpl : public Statistics, private client::NonCopyable {
- private:
- /**********varbs originally kept in statisticsimpl class*****************/
+class AtomicStatisticsImpl : public Statistics {
/** The type of this statistics instance */
StatisticsTypeImpl* statsType;
@@ -60,7 +57,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
/** Uniquely identifies this instance */
int64_t uniqueId;
-
/****************************************************************************/
/** An array containing the values of the int32_t statistics */
std::atomic<int32_t>* intStorage;
@@ -70,7 +66,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
/** An array containing the values of the double statistics */
std::atomic<double>* doubleStorage;
- ///////////////////////Private Methods//////////////////////////
bool isOpen() const;
int32_t getIntId(const std::shared_ptr<StatisticDescriptor> descriptor)
const;
@@ -81,15 +76,12 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
int32_t getDoubleId(
const std::shared_ptr<StatisticDescriptor> descriptor) const;
- ////////////////////// Static private Methods //////////////////////
-
int64_t calcNumericId(StatisticsFactory* system, int64_t userValue);
std::string calcTextId(StatisticsFactory* system,
const std::string& userValue);
- /////////////////////// Constructors ///////////////////////
-
+ public:
/**
* Creates a new statistics instance of the given type
*
@@ -105,15 +97,15 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
* The distributed system that determines whether or not these
* statistics are stored (and collected) in local memory
*/
-
- public:
AtomicStatisticsImpl(StatisticsType* type, const std::string& textId,
int64_t numericId, int64_t uniqueId,
StatisticsFactory* system);
- ////////////////////// Instance Methods //////////////////////
~AtomicStatisticsImpl() noexcept override;
+ AtomicStatisticsImpl(const AtomicStatisticsImpl&) = delete;
+ AtomicStatisticsImpl& operator=(const AtomicStatisticsImpl&) = delete;
+
bool usesSystemCalls();
int32_t nameToId(const std::string& name) const override;
@@ -128,7 +120,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
bool isAtomic() const override;
void close() override;
- /////////////////////////Attribute methods//////////////////////////
StatisticsType* getType() const override;
@@ -138,8 +129,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
int64_t getUniqueId() const override;
- //////////////////////// set() Methods ///////////////////////
-
void setInt(const std::string& name, int32_t value) override;
void setInt(const std::shared_ptr<StatisticDescriptor> descriptor,
@@ -161,8 +150,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
void setDouble(int32_t id, double value) override;
- /////////////////////// get() Methods ///////////////////////
-
int32_t getInt(const std::string& name) const override;
int32_t getInt(
@@ -187,8 +174,6 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
int64_t getRawBits(
const std::shared_ptr<StatisticDescriptor> descriptor) const override;
- //////////////////////// inc() Methods ////////////////////////
-
int32_t incInt(const std::string& name, int32_t delta) override;
int32_t incInt(const std::shared_ptr<StatisticDescriptor> descriptor,
diff --git a/cppcache/src/statistics/GeodeStatisticsFactory.hpp
b/cppcache/src/statistics/GeodeStatisticsFactory.hpp
index df4f8b3..f0e28ce 100644
--- a/cppcache/src/statistics/GeodeStatisticsFactory.hpp
+++ b/cppcache/src/statistics/GeodeStatisticsFactory.hpp
@@ -32,9 +32,6 @@
#include "StatisticsManager.hpp"
#include "StatisticsTypeImpl.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -46,15 +43,13 @@ class StatisticsManager;
*
*/
class GeodeStatisticsFactory : public StatisticsFactory {
- private:
std::string m_name;
int64_t m_id;
StatisticsManager* m_statMngr;
- int64_t m_statsListUniqueId; // Creates a unique id for each stats object in
- // the list
+ int64_t m_statsListUniqueId;
std::recursive_mutex m_statsListUniqueIdLock;
diff --git a/cppcache/src/statistics/HostStatSampler.hpp
b/cppcache/src/statistics/HostStatSampler.hpp
index 3091e91..a15f5e7 100644
--- a/cppcache/src/statistics/HostStatSampler.hpp
+++ b/cppcache/src/statistics/HostStatSampler.hpp
@@ -33,7 +33,6 @@
#include <geode/ExceptionTypes.hpp>
#include <geode/internal/geode_globals.hpp>
-#include "../NonCopyable.hpp"
#include "StatArchiveWriter.hpp"
#include "StatSamplerStats.hpp"
#include "StatisticDescriptor.hpp"
@@ -65,16 +64,17 @@ class StatisticsManager;
* HostStatSampler implements a thread which will monitor, sample and archive
* statistics. It only has the common functionalities which any sampler needs.
*/
-class HostStatSampler : private NonCopyable, private NonAssignable {
+class HostStatSampler {
public:
- /*
- * Constructor:
- */
HostStatSampler(const char* filePath,
std::chrono::milliseconds sampleIntervalMs,
StatisticsManager* statMngr, CacheImpl* cache,
int64_t statFileLimit = 0, int64_t statDiskSpaceLimit = 0);
+ HostStatSampler(const HostStatSampler&) = delete;
+
+ HostStatSampler& operator=(const HostStatSampler&) = delete;
+
/**
* Adds the pid to the archive file passed to it.
*/
diff --git a/cppcache/src/statistics/OsStatisticsImpl.hpp
b/cppcache/src/statistics/OsStatisticsImpl.hpp
index bafc98d..641f50c 100644
--- a/cppcache/src/statistics/OsStatisticsImpl.hpp
+++ b/cppcache/src/statistics/OsStatisticsImpl.hpp
@@ -20,14 +20,10 @@
#ifndef GEODE_STATISTICS_OSSTATISTICSIMPL_H_
#define GEODE_STATISTICS_OSSTATISTICSIMPL_H_
-#include "../NonCopyable.hpp"
#include "Statistics.hpp"
#include "StatisticsFactory.hpp"
#include "StatisticsTypeImpl.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -37,10 +33,7 @@ namespace statistics {
* in local memory and does not support atomic operations.
*
*/
-class OsStatisticsImpl : public Statistics,
- private client::NonCopyable,
- private client::NonAssignable {
- private:
+class OsStatisticsImpl : public Statistics {
/** The type of this statistics instance */
StatisticsTypeImpl* statsType;
@@ -56,7 +49,6 @@ class OsStatisticsImpl : public Statistics,
/** Uniquely identifies this instance */
int64_t uniqueId;
-
/****************************************************************************/
/** An array containing the values of the int32_t statistics */
int32_t* intStorage;
@@ -66,7 +58,6 @@ class OsStatisticsImpl : public Statistics,
/** An array containing the values of the double statistics */
double* doubleStorage;
- ///////////////////////Private Methods//////////////////////////
bool isOpen() const;
int32_t getIntId(const std::shared_ptr<StatisticDescriptor> descriptor)
const;
@@ -77,15 +68,12 @@ class OsStatisticsImpl : public Statistics,
int32_t getDoubleId(
const std::shared_ptr<StatisticDescriptor> descriptor) const;
- ////////////////////// Static private Methods //////////////////////
-
static int64_t calcNumericId(StatisticsFactory* system, int64_t userValue);
static std::string calcTextId(StatisticsFactory* system,
const std::string& userValue);
- /////////////////////// Constructors ///////////////////////
-
+ public:
/**
* Creates a new statistics instance of the given type
*
@@ -101,15 +89,15 @@ class OsStatisticsImpl : public Statistics,
* The distributed system that determines whether or not these
* statistics are stored (and collected) in local memory
*/
-
- public:
OsStatisticsImpl(StatisticsType* type, const std::string& textId,
int64_t numericId, int64_t uniqueId,
StatisticsFactory* system);
~OsStatisticsImpl() noexcept override;
- ////////////////////// Instance Methods //////////////////////
+ OsStatisticsImpl(const OsStatisticsImpl&) = delete;
+
+ OsStatisticsImpl& operator=(const OsStatisticsImpl&) = delete;
int32_t nameToId(const std::string& name) const override;
@@ -123,7 +111,6 @@ class OsStatisticsImpl : public Statistics,
bool isAtomic() const override;
void close() override;
- /////////////////////////Attribute methods//////////////////////////
StatisticsType* getType() const override;
@@ -133,8 +120,6 @@ class OsStatisticsImpl : public Statistics,
int64_t getUniqueId() const override;
- //////////////////////// set() Methods ///////////////////////
-
void setInt(const std::string& name, int32_t value) override;
void setInt(const std::shared_ptr<StatisticDescriptor> descriptor,
@@ -156,8 +141,6 @@ class OsStatisticsImpl : public Statistics,
void setDouble(int32_t id, double value) override;
- /////////////////////// get() Methods ///////////////////////
-
int32_t getInt(const std::string& name) const override;
int32_t getInt(
@@ -182,8 +165,6 @@ class OsStatisticsImpl : public Statistics,
int64_t getRawBits(
const std::shared_ptr<StatisticDescriptor> descriptor) const override;
- //////////////////////// inc() Methods ////////////////////////
-
int32_t incInt(const std::string& name, int32_t delta) override;
int32_t incInt(const std::shared_ptr<StatisticDescriptor> descriptor,
@@ -205,7 +186,6 @@ class OsStatisticsImpl : public Statistics,
double incDouble(int32_t id, double delta) override;
- //////////////////////// store() Methods ///////////////////////
protected:
/**
* Sets the value of a statistic of type <code>int</code> at the
@@ -216,7 +196,7 @@ class OsStatisticsImpl : public Statistics,
void _setLong(int32_t offset, int64_t value);
void _setDouble(int32_t offset, double value);
- /////////////////////// get() Methods ///////////////////////
+
/**
* Returns the value of the statistic of type <code>int</code> at
* the given offset, but performs no type checking.
@@ -233,7 +213,6 @@ class OsStatisticsImpl : public Statistics,
*/
int64_t _getRawBits(const std::shared_ptr<StatisticDescriptor> stat) const;
- //////////////////////// inc() Methods ////////////////////////
/**
* Increments the value of the statistic of type <code>int</code> at
* the given offset by a given amount, but performs no type checking.
@@ -245,9 +224,6 @@ class OsStatisticsImpl : public Statistics,
int64_t _incLong(int32_t offset, int64_t delta);
double _incDouble(int32_t offset, double delta);
-
- /////////////////// internal package methods //////////////////
-
}; // class
} // namespace statistics
diff --git a/cppcache/src/statistics/PoolStatsSampler.hpp
b/cppcache/src/statistics/PoolStatsSampler.hpp
index 687c47d..dc78213 100644
--- a/cppcache/src/statistics/PoolStatsSampler.hpp
+++ b/cppcache/src/statistics/PoolStatsSampler.hpp
@@ -55,7 +55,7 @@ class PoolStatsSampler {
ThinClientPoolDM* distMan);
PoolStatsSampler& operator=(const PoolStatsSampler&) = delete;
PoolStatsSampler(const PoolStatsSampler& PoolStatsSampler) = delete;
- ~PoolStatsSampler() noexcept {}
+ ~PoolStatsSampler() noexcept = default;
void start();
void stop();
diff --git a/cppcache/src/statistics/ProcessStats.cpp
b/cppcache/src/statistics/ProcessStats.cpp
index 5a2dac4..32a6c14 100644
--- a/cppcache/src/statistics/ProcessStats.cpp
+++ b/cppcache/src/statistics/ProcessStats.cpp
@@ -20,16 +20,8 @@ namespace apache {
namespace geode {
namespace statistics {
-/**
- * Creates a new <code>ProcessStats</code> that wraps the given
- * <code>Statistics</code>.
- */
-ProcessStats::ProcessStats() {}
-
int64_t ProcessStats::getProcessSize() { return 0; }
-ProcessStats::~ProcessStats() {}
-
} // namespace statistics
} // namespace geode
} // namespace apache
diff --git a/cppcache/src/statistics/ProcessStats.hpp
b/cppcache/src/statistics/ProcessStats.hpp
index 094a8d0..0d6f4f7 100644
--- a/cppcache/src/statistics/ProcessStats.hpp
+++ b/cppcache/src/statistics/ProcessStats.hpp
@@ -24,9 +24,6 @@
#include "Statistics.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -42,7 +39,7 @@ class APACHE_GEODE_EXPORT ProcessStats {
* Creates a new <code>ProcessStats</code> that wraps the given
* <code>Statistics</code>.
*/
- ProcessStats();
+ ProcessStats() = default;
/**
* Returns the CPU Usage
@@ -71,10 +68,7 @@ class APACHE_GEODE_EXPORT ProcessStats {
*/
virtual int64_t getAllCpuTime() = 0;
- /**
- * Destructor
- */
- virtual ~ProcessStats();
+ virtual ~ProcessStats() = default;
};
} // namespace statistics
} // namespace geode
diff --git a/cppcache/src/statistics/StatArchiveWriter.cpp
b/cppcache/src/statistics/StatArchiveWriter.cpp
index f10813a..16ce4d6 100644
--- a/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -153,6 +153,8 @@ void StatDataOutput::openFile(std::string filename, int64_t
size) {
bytesWritten = size;
}
+const uint8_t *StatDataOutput::getBuffer() { return dataBuffer->getBuffer(); }
+
// Constructor and Member functions of ResourceType class
ResourceType::ResourceType(int32_t idArg, const StatisticsType *typeArg)
@@ -615,6 +617,7 @@ void StatArchiveWriter::writeResourceInst(StatDataOutput
*dataOut,
dataOut->writeByte(static_cast<uint8_t>(instId));
}
}
+
} // namespace statistics
} // namespace geode
} // namespace apache
diff --git a/cppcache/src/statistics/StatArchiveWriter.hpp
b/cppcache/src/statistics/StatArchiveWriter.hpp
index 8425ff8..8658d7c 100644
--- a/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -30,7 +30,6 @@
#include <geode/ExceptionTypes.hpp>
#include <geode/internal/geode_globals.hpp>
-#include "../NonCopyable.hpp"
#include "../SerializationRegistry.hpp"
#include "../util/Log.hpp"
#include "StatisticDescriptor.hpp"
@@ -39,9 +38,6 @@
#include "StatisticsType.hpp"
#include "StatsDef.hpp"
-/**
- * some constants to be used while archiving
- */
const int8_t ARCHIVE_VERSION = 4;
const int8_t SAMPLE_TOKEN = 0;
const int8_t RESOURCE_TYPE_TOKEN = 1;
@@ -58,9 +54,6 @@ const int32_t MAX_SHORT_RESOURCE_INST_ID = 65535;
const int32_t MAX_SHORT_TIMESTAMP = 65534;
const int32_t INT_TIMESTAMP_TOKEN = 65535;
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -83,7 +76,6 @@ using std::chrono::system_clock;
* // of the Statistics object and the value of the
* // descriptors in the previous sample run.
*/
-
class APACHE_GEODE_EXPORT StatDataOutput {
public:
explicit StatDataOutput(CacheImpl *cache);
@@ -130,7 +122,7 @@ class APACHE_GEODE_EXPORT StatDataOutput {
/**
* This method is for the unit tests only for this class.
*/
- const uint8_t *getBuffer() { return dataBuffer->getBuffer(); }
+ const uint8_t *getBuffer();
void close();
void openFile(std::string, int64_t);
@@ -144,10 +136,11 @@ class APACHE_GEODE_EXPORT StatDataOutput {
friend class StatArchiveWriter;
};
-class APACHE_GEODE_EXPORT ResourceType : private NonCopyable,
- private NonAssignable {
+class APACHE_GEODE_EXPORT ResourceType {
public:
ResourceType(int32_t id, const StatisticsType *type);
+ ResourceType(const ResourceType &) = delete;
+ ResourceType &operator=(const ResourceType &) = delete;
int32_t getId() const;
const std::vector<std::shared_ptr<StatisticDescriptor>> &getStats() const;
size_t getNumOfDescriptors() const;
@@ -157,25 +150,12 @@ class APACHE_GEODE_EXPORT ResourceType : private
NonCopyable,
const StatisticsType *type;
};
-/* adongre
- * CID 28735: Other violation (MISSING_COPY)
- * Class "apache::geode::statistics::ResourceInst" owns resources
- * that are managed in its constructor and destructor but has no user-written
- * copy constructor.
- * CID 28721: Other violation (MISSING_ASSIGN)
- * Class "apache::geode::statistics::ResourceInst" owns resources that are
- * managed
- * in its constructor and destructor but has no user-written assignment
- * operator.
- *
- * FIX : Make the class NonCopyable
- */
-
-class APACHE_GEODE_EXPORT ResourceInst : private NonCopyable,
- private NonAssignable {
+class APACHE_GEODE_EXPORT ResourceInst {
public:
ResourceInst(int32_t id, Statistics *, const ResourceType *,
StatDataOutput *);
+ ResourceInst(const ResourceInst &) = delete;
+ ResourceInst &operator=(const ResourceInst &) = delete;
~ResourceInst();
int32_t getId();
Statistics *getResource();
@@ -198,12 +178,8 @@ class APACHE_GEODE_EXPORT ResourceInst : private
NonCopyable,
};
class HostStatSampler;
-/**
- * @class StatArchiveWriter
- */
class APACHE_GEODE_EXPORT StatArchiveWriter {
- private:
HostStatSampler *sampler;
StatDataOutput *dataBuffer;
CacheImpl *cache;
@@ -217,7 +193,6 @@ class APACHE_GEODE_EXPORT StatArchiveWriter {
std::map<Statistics *, std::shared_ptr<ResourceInst>> resourceInstMap;
std::map<const StatisticsType *, const ResourceType *> resourceTypeMap;
- /* private member functions */
void allocateResourceInst(Statistics *r);
void sampleResources();
void resampleResources();
diff --git a/cppcache/src/statistics/StatSamplerStats.hpp
b/cppcache/src/statistics/StatSamplerStats.hpp
index 9a5cb8d..386fe36 100644
--- a/cppcache/src/statistics/StatSamplerStats.hpp
+++ b/cppcache/src/statistics/StatSamplerStats.hpp
@@ -37,7 +37,6 @@ class StatisticsFactory;
* Statistics related to the statistic sampler.
*/
class APACHE_GEODE_EXPORT StatSamplerStats {
- private:
StatisticsType* samplerType;
Statistics* samplerStats;
int32_t sampleCountId;
diff --git a/cppcache/src/statistics/StatisticDescriptor.hpp
b/cppcache/src/statistics/StatisticDescriptor.hpp
index 9699ec3..426f61e 100644
--- a/cppcache/src/statistics/StatisticDescriptor.hpp
+++ b/cppcache/src/statistics/StatisticDescriptor.hpp
@@ -24,9 +24,6 @@
#include <geode/internal/geode_globals.hpp>
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -43,7 +40,6 @@ namespace statistics {
* StatisticDescriptors are naturally ordered by their name.
*
*/
-
class APACHE_GEODE_EXPORT StatisticDescriptor {
public:
/**
@@ -80,10 +76,7 @@ class APACHE_GEODE_EXPORT StatisticDescriptor {
*/
virtual const std::string& getUnit() const = 0;
- /*
- * Destructor
- */
- virtual ~StatisticDescriptor() {}
+ virtual ~StatisticDescriptor() = default;
}; // class
} // namespace statistics
diff --git a/cppcache/src/statistics/StatisticDescriptorImpl.hpp
b/cppcache/src/statistics/StatisticDescriptorImpl.hpp
index 3fe72b6..cdc7b03 100644
--- a/cppcache/src/statistics/StatisticDescriptorImpl.hpp
+++ b/cppcache/src/statistics/StatisticDescriptorImpl.hpp
@@ -26,9 +26,6 @@
#include "StatisticDescriptor.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -49,7 +46,6 @@ typedef enum { INT_TYPE = 5, LONG_TYPE = 6, DOUBLE_TYPE = 8 }
FieldType;
*/
class StatisticDescriptorImpl : public StatisticDescriptor {
- private:
/** The name of the statistic */
std::string name;
@@ -113,13 +109,8 @@ class StatisticDescriptorImpl : public StatisticDescriptor
{
*/
FieldType descriptorType;
- /**
- * Destructor
- */
~StatisticDescriptorImpl() override;
- /////////////////////////// Static
Methods////////////////////////////////////
-
/**
* Returns the name of the given type code
* Returns "int" for int_t, "long" for Long, "double" for Double
@@ -137,8 +128,6 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
*/
static int32_t getTypeCodeBits(FieldType code);
- ///////////////////////////Create methods
////////////////////////////////////
-
/**
* Creates a descriptor of Integer type
* whose value behaves like a counter
@@ -193,9 +182,6 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter);
- ///////////////// StatisticDescriptor(Base class) Methods
- ///////////////////////
-
const std::string& getName() const override;
const std::string& getDescription() const override;
@@ -210,8 +196,6 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
int32_t getId() const override;
- ///////////////////////////// Instance Methods ////////////////////////////
-
/**
* Returns the type code of this statistic
* Possible values are:
@@ -226,7 +210,6 @@ class StatisticDescriptorImpl : public StatisticDescriptor {
* An uninitialized id will be -1
*/
void setId(int32_t statId);
- ///////////////////////////// Check methods ///////////////////////////////
/**
* Checks whether the descriptor is of type int and returns the id if it is
diff --git a/cppcache/src/statistics/Statistics.hpp
b/cppcache/src/statistics/Statistics.hpp
index 4ea90ef..1631ffa 100644
--- a/cppcache/src/statistics/Statistics.hpp
+++ b/cppcache/src/statistics/Statistics.hpp
@@ -27,9 +27,6 @@
#include "StatisticDescriptor.hpp"
#include "StatisticsType.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -50,8 +47,6 @@ class APACHE_GEODE_EXPORT Statistics {
*/
virtual void close() = 0;
- //////////////////////// accessor Methods ///////////////////////
-
/**
* Returns the id of the statistic with the given name in this
* statistics instance.
@@ -124,8 +119,6 @@ class APACHE_GEODE_EXPORT Statistics {
*/
virtual bool isClosed() const = 0;
- //////////////////////// set() Methods ///////////////////////
-
/**
* Sets the value of a statistic with the given <code>id</code>
* whose type is <code>int</code>.
@@ -512,9 +505,6 @@ class APACHE_GEODE_EXPORT Statistics {
virtual double incDouble(const std::string& name, double delta) = 0;
protected:
- /**
- * Destructor is protected to prevent direct deletion. Use close().
- */
virtual ~Statistics() = default;
}; // class
diff --git a/cppcache/src/statistics/StatisticsFactory.hpp
b/cppcache/src/statistics/StatisticsFactory.hpp
index 0cd4549..1a4aa95 100644
--- a/cppcache/src/statistics/StatisticsFactory.hpp
+++ b/cppcache/src/statistics/StatisticsFactory.hpp
@@ -29,9 +29,6 @@
#include "Statistics.hpp"
#include "StatisticsType.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -57,11 +54,11 @@ namespace statistics {
class APACHE_GEODE_EXPORT StatisticsFactory {
protected:
- StatisticsFactory() {}
+ StatisticsFactory() = default;
StatisticsFactory(const StatisticsFactory&) = delete;
public:
- virtual ~StatisticsFactory() {}
+ virtual ~StatisticsFactory() = default;
/**
* Creates and returns a long counter {@link StatisticDescriptor}
@@ -207,8 +204,7 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
*/
virtual int64_t getId() const = 0;
- private:
- const StatisticsFactory& operator=(const StatisticsFactory&);
+ StatisticsFactory& operator=(const StatisticsFactory&) = delete;
}; // class
} // namespace statistics
diff --git a/cppcache/src/statistics/StatisticsManager.cpp
b/cppcache/src/statistics/StatisticsManager.cpp
index 1f07ed1..0da86e8 100644
--- a/cppcache/src/statistics/StatisticsManager.cpp
+++ b/cppcache/src/statistics/StatisticsManager.cpp
@@ -229,6 +229,19 @@ void StatisticsManager::deleteStatistics(Statistics*&
stat) {
stat = nullptr;
}
+void StatisticsManager::RegisterAdminRegion(
+ std::shared_ptr<AdminRegion> adminRegPtr) {
+ m_adminRegion = adminRegPtr;
+}
+
+std::shared_ptr<AdminRegion> StatisticsManager::getAdminRegion() {
+ return m_adminRegion;
+}
+
+GeodeStatisticsFactory* StatisticsManager::getStatisticsFactory() const {
+ return m_statisticsFactory.get();
+}
+
} // namespace statistics
} // namespace geode
} // namespace apache
diff --git a/cppcache/src/statistics/StatisticsManager.hpp
b/cppcache/src/statistics/StatisticsManager.hpp
index b91968d..d10f4db 100644
--- a/cppcache/src/statistics/StatisticsManager.hpp
+++ b/cppcache/src/statistics/StatisticsManager.hpp
@@ -46,7 +46,6 @@ class HostStatSampler;
*
*/
class StatisticsManager {
- private:
// interval at which the sampler will take a sample of Stats
std::chrono::milliseconds m_sampleIntervalMs;
@@ -74,11 +73,9 @@ class StatisticsManager {
client::CacheImpl* cache, int64_t statFileLimit = 0,
int64_t statDiskSpaceLimit = 0);
- void RegisterAdminRegion(std::shared_ptr<AdminRegion> adminRegPtr) {
- m_adminRegion = adminRegPtr;
- }
+ void RegisterAdminRegion(std::shared_ptr<AdminRegion> adminRegPtr);
- std::shared_ptr<AdminRegion> getAdminRegion() { return m_adminRegion; }
+ std::shared_ptr<AdminRegion> getAdminRegion();
void forceSample();
@@ -107,9 +104,7 @@ class StatisticsManager {
static void deleteStatistics(Statistics*& stat);
- GeodeStatisticsFactory* getStatisticsFactory() const {
- return m_statisticsFactory.get();
- }
+ GeodeStatisticsFactory* getStatisticsFactory() const;
}; // class
} // namespace statistics
diff --git a/cppcache/src/statistics/StatisticsType.hpp
b/cppcache/src/statistics/StatisticsType.hpp
index 4a46475..527a9c8 100644
--- a/cppcache/src/statistics/StatisticsType.hpp
+++ b/cppcache/src/statistics/StatisticsType.hpp
@@ -88,11 +88,7 @@ class APACHE_GEODE_EXPORT StatisticsType {
*/
virtual size_t getDescriptorsCount() const = 0;
- // protected:
- /**
- * Destructor
- */
- virtual ~StatisticsType() {}
+ virtual ~StatisticsType() = default;
};
} // namespace statistics
diff --git a/cppcache/src/statistics/StatisticsTypeImpl.hpp
b/cppcache/src/statistics/StatisticsTypeImpl.hpp
index 19a8d73..c91ce8c 100644
--- a/cppcache/src/statistics/StatisticsTypeImpl.hpp
+++ b/cppcache/src/statistics/StatisticsTypeImpl.hpp
@@ -30,9 +30,6 @@
#include "StatisticsType.hpp"
#include "StatsDef.hpp"
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
@@ -47,7 +44,6 @@ typedef std::map<std::string,
std::shared_ptr<StatisticDescriptor>>
StatisticsDescMap;
class StatisticsTypeImpl : public StatisticsType {
- private:
std::string name;
std::string description;
std::vector<std::shared_ptr<StatisticDescriptor>> stats;
@@ -62,8 +58,6 @@ class StatisticsTypeImpl : public StatisticsType {
~StatisticsTypeImpl() override;
- //////////////// StatisticsType(Base class) Methods ///////////////////
-
const std::string& getName() const override;
const std::string& getDescription() const override;
@@ -76,8 +70,6 @@ class StatisticsTypeImpl : public StatisticsType {
std::shared_ptr<StatisticDescriptor> nameToDescriptor(
const std::string& name) const override;
- ////////////////////// Instance Methods //////////////////////
-
/**
* Gets the number of statistics in this type that are ints.
*/
@@ -97,10 +89,6 @@ class StatisticsTypeImpl : public StatisticsType {
* Gets the total number of statistic descriptors in the Type
*/
size_t getDescriptorsCount() const override;
-
- // static StatisticsType[] fromXml(Reader reader,
- // StatisticsTypeFactory factory);
-
}; // class
} // namespace statistics
} // namespace geode
diff --git a/cppcache/src/statistics/StatsDef.hpp
b/cppcache/src/statistics/StatsDef.hpp
index 52ad787..6e1696e 100644
--- a/cppcache/src/statistics/StatsDef.hpp
+++ b/cppcache/src/statistics/StatsDef.hpp
@@ -20,9 +20,6 @@
* limitations under the License.
*/
-/** @file
- */
-
namespace apache {
namespace geode {
namespace statistics {
diff --git a/cppcache/src/util/JavaModifiedUtf8.cpp
b/cppcache/src/util/JavaModifiedUtf8.cpp
new file mode 100644
index 0000000..d6f53b8
--- /dev/null
+++ b/cppcache/src/util/JavaModifiedUtf8.cpp
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include "JavaModifiedUtf8.hpp"
+
+#include <codecvt>
+#include <locale>
+
+#include "string.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+size_t JavaModifiedUtf8::encodedLength(const std::string& utf8) {
+ if (utf8.empty()) {
+ return 0;
+ }
+
+ return encodedLength(to_utf16(utf8));
+}
+
+size_t JavaModifiedUtf8::encodedLength(const std::u16string& utf16) {
+ return encodedLength(utf16.data(), utf16.length());
+}
+
+size_t JavaModifiedUtf8::encodedLength(const char16_t* data, size_t length) {
+ size_t encodedLen = 0;
+ while (length-- > 0) {
+ const char16_t c = *(data++);
+ if (c == 0) {
+ // NUL
+ encodedLen += 2;
+ } else if (c < 0x80) {
+ // ASCII
+ encodedLen++;
+ } else if (c < 0x800) {
+ encodedLen += 2;
+ } else {
+ encodedLen += 3;
+ }
+ }
+ return encodedLen;
+}
+
+std::string JavaModifiedUtf8::fromString(const std::string& utf8) {
+ return fromString(to_utf16(utf8));
+}
+
+std::string JavaModifiedUtf8::fromString(const std::u16string& utf16) {
+ std::string jmutf8;
+ jmutf8.reserve(utf16.length());
+
+ for (auto&& c : utf16) {
+ encode(c, jmutf8);
+ }
+
+ return jmutf8;
+}
+
+void JavaModifiedUtf8::encode(const char16_t c, std::string& jmutf8) {
+ if (c == 0) {
+ // NUL
+ jmutf8 += static_cast<uint8_t>(0xc0);
+ jmutf8 += static_cast<uint8_t>(0x80);
+ } else if (c < 0x80) {
+ // ASCII character
+ jmutf8 += static_cast<uint8_t>(c);
+ } else if (c < 0x800) {
+ jmutf8 += static_cast<uint8_t>(0xC0 | c >> 6);
+ jmutf8 += static_cast<uint8_t>(0x80 | (c & 0x3F));
+ } else {
+ jmutf8 += static_cast<uint8_t>(0xE0 | c >> 12);
+ jmutf8 += static_cast<uint8_t>(0x80 | ((c >> 6) & 0x3F));
+ jmutf8 += static_cast<uint8_t>(0x80 | (c & 0x3F));
+ }
+}
+
+std::u16string JavaModifiedUtf8::decode(const char* buf, uint16_t len) {
+ std::u16string value;
+ const auto end = buf + len;
+ while (buf < end) {
+ value += decodeJavaModifiedUtf8Char(&buf);
+ }
+ return value;
+}
+
+char16_t JavaModifiedUtf8::decodeJavaModifiedUtf8Char(const char** pbuf) {
+ char16_t c;
+
+ // get next byte unsigned
+ int32_t b = **pbuf & 0xff;
+ (*pbuf)++;
+ int32_t k = b >> 5;
+ // classify based on the high order 3 bits
+ switch (k) {
+ case 6: {
+ // two byte encoding
+ // 110yyyyy 10xxxxxx
+ // use low order 6 bits
+ int32_t y = b & 0x1f;
+ // use low order 6 bits of the next byte
+ // It should have high order bits 10, which we don't check.
+ int32_t x = **pbuf & 0x3f;
+ (*pbuf)++;
+ // 00000yyy yyxxxxxx
+ c = (y << 6 | x);
+ break;
+ }
+ case 7: {
+ // three byte encoding
+ // 1110zzzz 10yyyyyy 10xxxxxx
+ // use low order 4 bits
+ int32_t z = b & 0x0f;
+ // use low order 6 bits of the next byte
+ // It should have high order bits 10, which we don't check.
+ int32_t y = **pbuf & 0x3f;
+ (*pbuf)++;
+ // use low order 6 bits of the next byte
+ // It should have high order bits 10, which we don't check.
+ int32_t x = **pbuf & 0x3f;
+ (*pbuf)++;
+ // zzzzyyyy yyxxxxxx
+ c = static_cast<char16_t>(z << 12 | y << 6 | x);
+ break;
+ }
+ default:
+ // one byte encoding
+ // 0xxxxxxx
+ // use just low order 7 bits
+ // 00000000 0xxxxxxx
+ c = static_cast<char16_t>(b & 0x7f);
+ break;
+ }
+ return c;
+}
+
+} // namespace internal
+} // namespace client
+} // namespace geode
+} // namespace apache
diff --git a/cppcache/src/util/JavaModifiedUtf8.hpp
b/cppcache/src/util/JavaModifiedUtf8.hpp
index 9c9880b..f6d1722 100644
--- a/cppcache/src/util/JavaModifiedUtf8.hpp
+++ b/cppcache/src/util/JavaModifiedUtf8.hpp
@@ -20,12 +20,8 @@
#ifndef GEODE_UTIL_JAVAMODIFIEDUTF8_H_
#define GEODE_UTIL_JAVAMODIFIEDUTF8_H_
-#include <codecvt>
-#include <locale>
#include <string>
-#include "string.hpp"
-
namespace apache {
namespace geode {
namespace client {
@@ -36,142 +32,34 @@ struct JavaModifiedUtf8 {
* Calculate the length of the given UTF-8 string when encoded in Java
* Modified UTF-8.
*/
- inline static size_t encodedLength(const std::string& utf8) {
- if (utf8.empty()) {
- return 0;
- }
-
- // TODO string optimize for direct calculation
- return encodedLength(to_utf16(utf8));
- }
+ static size_t encodedLength(const std::string& utf8);
/**
* Calculate the length of the given UTF-16 string when encoded in Java
* Modified UTF-8.
*/
- inline static size_t encodedLength(const std::u16string& utf16) {
- return encodedLength(utf16.data(), utf16.length());
- }
+ static size_t encodedLength(const std::u16string& utf16);
- inline static size_t encodedLength(const char16_t* data, size_t length) {
- size_t encodedLen = 0;
- while (length-- > 0) {
- const char16_t c = *(data++);
- if (c == 0) {
- // NUL
- encodedLen += 2;
- } else if (c < 0x80) {
- // ASCII
- encodedLen++;
- } else if (c < 0x800) {
- encodedLen += 2;
- } else {
- encodedLen += 3;
- }
- }
- return encodedLen;
- }
+ static size_t encodedLength(const char16_t* data, size_t length);
/**
* Converts given UTF-8 string to Java Modified UTF-8 string.
*/
- inline static std::string fromString(const std::string& utf8) {
- return fromString(to_utf16(utf8));
- }
+ static std::string fromString(const std::string& utf8);
/**
* Converts given UTF-16 string to Java Modified UTF-8 string.
*/
- inline static std::string fromString(const std::u16string& utf16) {
- std::string jmutf8;
- jmutf8.reserve(utf16.length());
-
- for (auto&& c : utf16) {
- encode(c, jmutf8);
- }
-
- return jmutf8;
- }
+ static std::string fromString(const std::u16string& utf16);
/**
* Converts a single UTF-16 code unit into Java Modified UTF-8 code units.
*/
- inline static void encode(const char16_t c, std::string& jmutf8) {
- if (c == 0) {
- // NUL
- jmutf8 += static_cast<uint8_t>(0xc0);
- jmutf8 += static_cast<uint8_t>(0x80);
- } else if (c < 0x80) {
- // ASCII character
- jmutf8 += static_cast<uint8_t>(c);
- } else if (c < 0x800) {
- jmutf8 += static_cast<uint8_t>(0xC0 | c >> 6);
- jmutf8 += static_cast<uint8_t>(0x80 | (c & 0x3F));
- } else {
- jmutf8 += static_cast<uint8_t>(0xE0 | c >> 12);
- jmutf8 += static_cast<uint8_t>(0x80 | ((c >> 6) & 0x3F));
- jmutf8 += static_cast<uint8_t>(0x80 | (c & 0x3F));
- }
- }
-
- inline static std::u16string decode(const char* buf, uint16_t len) {
- std::u16string value;
- const auto end = buf + len;
- while (buf < end) {
- value += decodeJavaModifiedUtf8Char(&buf);
- }
- return value;
- }
+ static void encode(const char16_t c, std::string& jmutf8);
- inline static char16_t decodeJavaModifiedUtf8Char(const char** pbuf) {
- char16_t c;
+ static std::u16string decode(const char* buf, uint16_t len);
- // get next byte unsigned
- int32_t b = **pbuf & 0xff;
- (*pbuf)++;
- int32_t k = b >> 5;
- // classify based on the high order 3 bits
- switch (k) {
- case 6: {
- // two byte encoding
- // 110yyyyy 10xxxxxx
- // use low order 6 bits
- int32_t y = b & 0x1f;
- // use low order 6 bits of the next byte
- // It should have high order bits 10, which we don't check.
- int32_t x = **pbuf & 0x3f;
- (*pbuf)++;
- // 00000yyy yyxxxxxx
- c = (y << 6 | x);
- break;
- }
- case 7: {
- // three byte encoding
- // 1110zzzz 10yyyyyy 10xxxxxx
- // use low order 4 bits
- int32_t z = b & 0x0f;
- // use low order 6 bits of the next byte
- // It should have high order bits 10, which we don't check.
- int32_t y = **pbuf & 0x3f;
- (*pbuf)++;
- // use low order 6 bits of the next byte
- // It should have high order bits 10, which we don't check.
- int32_t x = **pbuf & 0x3f;
- (*pbuf)++;
- // zzzzyyyy yyxxxxxx
- c = static_cast<char16_t>(z << 12 | y << 6 | x);
- break;
- }
- default:
- // one byte encoding
- // 0xxxxxxx
- // use just low order 7 bits
- // 00000000 0xxxxxxx
- c = static_cast<char16_t>(b & 0x7f);
- break;
- }
- return c;
- }
+ static char16_t decodeJavaModifiedUtf8Char(const char** pbuf);
};
} // namespace internal
diff --git a/cppcache/src/util/Log.hpp b/cppcache/src/util/Log.hpp
index 740a13d..6ac930d 100644
--- a/cppcache/src/util/Log.hpp
+++ b/cppcache/src/util/Log.hpp
@@ -43,27 +43,12 @@
#define _GF_MSG_LIMIT 8192
-/******************************************************************************/
-
-/** @file
- */
-
namespace apache {
namespace geode {
namespace client {
class Exception;
-/******************************************************************************/
-/******************************************************************************/
-
-/* Logs the message if the given level is less than or equal to the current
- * logging level. */
-#define GF_LOG(level, expr) \
- if (level > apache::geode::client::Log::logLevel()) { \
- } else \
- apache::geode::client::Log::log(level, expr)
-
/** Defines methods available to clients that want to write a log message
* to their Geode system's shared log file.
* <p>
@@ -142,19 +127,15 @@ class Exception;
class APACHE_GEODE_EXPORT Log {
public:
- /******/
-
- /******/
-
/**
* Returns the current log level.
*/
- static LogLevel logLevel() { return s_logLevel; }
+ static LogLevel logLevel();
/**
* Set the current log level.
*/
- static void setLogLevel(LogLevel level) { s_logLevel = level; }
+ static void setLogLevel(LogLevel level);
/**
* Initializes logging facility with given level and filenames.
@@ -203,338 +184,221 @@ class APACHE_GEODE_EXPORT Log {
*/
static char* formatLogLine(char* buf, LogLevel level);
- /******/
-
/**
* Returns whether log messages at given level are enabled.
*/
- static bool enabled(LogLevel level) {
- return (((s_doingDebug && level == LogLevel::Debug) ||
- GEODE_HIGHEST_LOG_LEVEL >= level) &&
- s_logLevel >= level);
- }
+ static bool enabled(LogLevel level);
/**
* Logs a message at given level.
*/
- static void log(LogLevel level, const char* msg) {
- if (enabled(level)) put(level, msg);
- }
+ static void log(LogLevel level, const char* msg);
/**
* Logs both a message and thrown exception.
*/
- static void logThrow(LogLevel level, const char* msg, const Exception& ex) {
- if (enabled(level)) putThrow(level, msg, ex);
- }
+ static void logThrow(LogLevel level, const char* msg, const Exception& ex);
/**
* Logs both a message and caught exception.
*/
- static void logCatch(LogLevel level, const char* msg, const Exception& ex) {
- if (enabled(level)) putCatch(level, msg, ex);
- }
-
- /******/
+ static void logCatch(LogLevel level, const char* msg, const Exception& ex);
/**
* Returns whether "error" log messages are enabled.
*/
- static bool errorEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Error &&
- s_logLevel >= LogLevel::Error;
- }
+ static bool errorEnabled();
/**
* Logs a message.
* The message level is "error".
*/
- static void error(const char* msg) {
- if (errorEnabled()) put(LogLevel::Error, msg);
- }
+ static void error(const char* msg);
- static void error(const std::string& msg) {
- if (errorEnabled()) put(LogLevel::Error, msg.c_str());
- }
+ static void error(const std::string& msg);
/**
* Logs both a message and thrown exception.
* The message level is "error".
*/
- static void errorThrow(const char* msg, const Exception& ex) {
- if (errorEnabled()) putThrow(LogLevel::Error, msg, ex);
- }
+ static void errorThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "error".
*/
- static void errorCatch(const char* msg, const Exception& ex) {
- if (errorEnabled()) putCatch(LogLevel::Error, msg, ex);
- }
-
- /******/
+ static void errorCatch(const char* msg, const Exception& ex);
/**
* Returns whether "warning" log messages are enabled.
*/
- static bool warningEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Warning &&
- s_logLevel >= LogLevel::Warning;
- }
+ static bool warningEnabled();
/**
* Logs a message.
* The message level is "warning".
*/
- static void warning(const char* msg) {
- if (warningEnabled()) put(LogLevel::Warning, msg);
- }
+ static void warning(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "warning".
*/
- static void warningThrow(const char* msg, const Exception& ex) {
- if (warningEnabled()) putThrow(LogLevel::Warning, msg, ex);
- }
+ static void warningThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "warning".
*/
- static void warningCatch(const char* msg, const Exception& ex) {
- if (warningEnabled()) putCatch(LogLevel::Warning, msg, ex);
- }
-
- /******/
+ static void warningCatch(const char* msg, const Exception& ex);
/**
* Returns whether "info" log messages are enabled.
*/
- static bool infoEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Info &&
- s_logLevel >= LogLevel::Info;
- }
+ static bool infoEnabled();
/**
* Logs a message.
* The message level is "info".
*/
- static void info(const char* msg) {
- if (infoEnabled()) put(LogLevel::Info, msg);
- }
+ static void info(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "info".
*/
- static void infoThrow(const char* msg, const Exception& ex) {
- if (infoEnabled()) putThrow(LogLevel::Info, msg, ex);
- }
+ static void infoThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "info".
*/
- static void infoCatch(const char* msg, const Exception& ex) {
- if (infoEnabled()) putCatch(LogLevel::Info, msg, ex);
- }
-
- /******/
+ static void infoCatch(const char* msg, const Exception& ex);
/**
* Returns whether "config" log messages are enabled.
*/
- static bool configEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Config &&
- s_logLevel >= LogLevel::Config;
- }
+ static bool configEnabled();
/**
* Logs a message.
* The message level is "config".
*/
- static void config(const char* msg) {
- if (configEnabled()) put(LogLevel::Config, msg);
- }
+ static void config(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "config".
*/
- static void configThrow(const char* msg, const Exception& ex) {
- if (configEnabled()) putThrow(LogLevel::Config, msg, ex);
- }
+ static void configThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "config".
*/
- static void configCatch(const char* msg, const Exception& ex) {
- if (configEnabled()) putCatch(LogLevel::Config, msg, ex);
- }
-
- /******/
+ static void configCatch(const char* msg, const Exception& ex);
/**
* Returns whether "fine" log messages are enabled.
*/
- static bool fineEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Fine &&
- s_logLevel >= LogLevel::Fine;
- }
+ static bool fineEnabled();
/**
* Logs a message.
* The message level is "fine".
*/
- static void fine(const char* msg) {
- if (fineEnabled()) put(LogLevel::Fine, msg);
- }
+ static void fine(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "fine".
*/
- static void fineThrow(const char* msg, const Exception& ex) {
- if (fineEnabled()) putThrow(LogLevel::Fine, msg, ex);
- }
+ static void fineThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "fine".
*/
- static void fineCatch(const char* msg, const Exception& ex) {
- if (fineEnabled()) putCatch(LogLevel::Fine, msg, ex);
- }
-
- /******/
+ static void fineCatch(const char* msg, const Exception& ex);
/**
* Returns whether "finer" log messages are enabled.
*/
- static bool finerEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Finer &&
- s_logLevel >= LogLevel::Finer;
- }
+ static bool finerEnabled();
/**
* Logs a message.
* The message level is "finer".
*/
- static void finer(const char* msg) {
- if (finerEnabled()) put(LogLevel::Finer, msg);
- }
+ static void finer(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "finer".
*/
- static void finerThrow(const char* msg, const Exception& ex) {
- if (finerEnabled()) putThrow(LogLevel::Finer, msg, ex);
- }
+ static void finerThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "finer".
*/
- static void finerCatch(const char* msg, const Exception& ex) {
- if (finerEnabled()) putCatch(LogLevel::Finer, msg, ex);
- }
-
- /******/
+ static void finerCatch(const char* msg, const Exception& ex);
/**
* Returns whether "finest" log messages are enabled.
*/
- static bool finestEnabled() {
- return GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Finest &&
- s_logLevel >= LogLevel::Finest;
- }
+ static bool finestEnabled();
/**
* Logs a message.
* The message level is "finest".
*/
- static void finest(const char* msg) {
- if (finestEnabled()) put(LogLevel::Finest, msg);
- }
+ static void finest(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "finest".
*/
- static void finestThrow(const char* msg, const Exception& ex) {
- if (finestEnabled()) putThrow(LogLevel::Finest, msg, ex);
- }
+ static void finestThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "finest".
*/
- static void finestCatch(const char* msg, const Exception& ex) {
- if (finestEnabled()) putCatch(LogLevel::Finest, msg, ex);
- }
-
- /******/
+ static void finestCatch(const char* msg, const Exception& ex);
/**
* Returns whether "debug" log messages are enabled.
*/
- static bool debugEnabled() {
- return (s_doingDebug || GEODE_HIGHEST_LOG_LEVEL >= LogLevel::Debug) &&
- s_logLevel >= LogLevel::Debug;
- }
+ static bool debugEnabled();
/**
* Logs a message.
* The message level is "debug".
*/
- static void debug(const char* msg) {
- if (debugEnabled()) put(LogLevel::Debug, msg);
- }
+ static void debug(const char* msg);
/**
* Logs both a message and thrown exception.
* The message level is "debug".
*/
- static void debugThrow(const char* msg, const Exception& ex) {
- if (debugEnabled()) putThrow(LogLevel::Debug, msg, ex);
- }
+ static void debugThrow(const char* msg, const Exception& ex);
/**
* Writes both a message and caught exception.
* The message level is "debug".
*/
- static void debugCatch(const char* msg, const Exception& ex) {
- if (debugEnabled()) putCatch(LogLevel::Debug, msg, ex);
- }
-
- /******/
+ static void debugCatch(const char* msg, const Exception& ex);
static void enterFn(LogLevel level, const char* functionName);
static void exitFn(LogLevel level, const char* functionName);
- /******/
-
private:
static LogLevel s_logLevel;
- /******/
-
-#ifdef DEBUG
- enum { s_doingDebug = 1 };
-#else
- enum { s_doingDebug = 0 };
-#endif
-
- /******/
-
static void writeBanner();
- /******/
public:
static void put(LogLevel level, const std::string& msg);
@@ -545,35 +409,19 @@ class APACHE_GEODE_EXPORT Log {
static void putCatch(LogLevel level, const char* msg, const Exception& ex);
};
-/******************************************************************************/
-/******************************************************************************/
-
-class LogFn {
+class APACHE_GEODE_EXPORT LogFn {
const char* m_functionName;
LogLevel m_level;
public:
- explicit LogFn(const char* functionName, LogLevel level = LogLevel::Finest)
- : m_functionName(functionName), m_level(level) {
- if (Log::enabled(m_level)) Log::enterFn(m_level, m_functionName);
- }
+ explicit LogFn(const char* functionName, LogLevel level = LogLevel::Finest);
- ~LogFn() {
- if (Log::enabled(m_level)) Log::exitFn(m_level, m_functionName);
- }
+ ~LogFn();
- private:
- LogFn(const LogFn& rhs); // never defined
- void operator=(const LogFn& rhs); // never defined
+ LogFn(const LogFn& rhs) = delete;
+ LogFn& operator=(const LogFn& rhs) = delete;
};
-/******************************************************************************/
-/******************************************************************************/
-
-/**
- * These functions are added to facilitate logging in printf format.
- */
-
class APACHE_GEODE_EXPORT LogVarargs {
public:
static void debug(const char* fmt, ...);
@@ -585,100 +433,64 @@ class APACHE_GEODE_EXPORT LogVarargs {
static void finer(const char* fmt, ...);
static void finest(const char* fmt, ...);
- inline static void debug(const std::string& message) {
- Log::put(LogLevel::Debug, message.c_str());
- }
+ static void debug(const std::string& message);
- inline static void error(const std::string& message) {
- Log::put(LogLevel::Error, message.c_str());
- }
+ static void error(const std::string& message);
- inline static void warn(const std::string& message) {
- Log::put(LogLevel::Warning, message.c_str());
- }
+ static void warn(const std::string& message);
- inline static void info(const std::string& message) {
- Log::put(LogLevel::Info, message.c_str());
- }
+ static void info(const std::string& message);
- inline static void config(const std::string& message) {
- Log::put(LogLevel::Config, message.c_str());
- }
+ static void config(const std::string& message);
- inline static void fine(const std::string& message) {
- Log::put(LogLevel::Fine, message.c_str());
- }
+ static void fine(const std::string& message);
- inline static void finer(const std::string& message) {
- Log::put(LogLevel::Finer, message.c_str());
- }
+ static void finer(const std::string& message);
- inline static void finest(const std::string& message) {
- Log::put(LogLevel::Finest, message.c_str());
- }
+ static void finest(const std::string& message);
};
} // namespace client
} // namespace geode
} // namespace apache
-/************************ LOGDEBUG ***********************************/
-
#define LOGDEBUG \
if (::apache::geode::client::LogLevel::Debug <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::debug
-/************************ LOGERROR ***********************************/
-
#define LOGERROR \
if (::apache::geode::client::LogLevel::Error <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::error
-/************************ LOGWARN ***********************************/
-
#define LOGWARN \
if (::apache::geode::client::LogLevel::Warning <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::warn
-/************************ LOGINFO ***********************************/
-
#define LOGINFO \
if (::apache::geode::client::LogLevel::Info <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::info
-/************************ LOGCONFIG ***********************************/
-
#define LOGCONFIG \
if (::apache::geode::client::LogLevel::Config <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::config
-/************************ LOGFINE ***********************************/
-
#define LOGFINE \
if (::apache::geode::client::LogLevel::Fine <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::fine
-/************************ LOGFINER ***********************************/
-
#define LOGFINER \
if (::apache::geode::client::LogLevel::Finer <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::finer
-/************************ LOGFINEST ***********************************/
-
#define LOGFINEST \
if (::apache::geode::client::LogLevel::Finest <= \
::apache::geode::client::Log::logLevel()) \
::apache::geode::client::LogVarargs::finest
-/******************************************************************************/
-
-/******************************************************************************/
-
#endif // GEODE_LOG_H_
diff --git a/cppcache/src/util/chrono/time_point.hpp
b/cppcache/src/util/chrono/time_point.cpp
similarity index 66%
copy from cppcache/src/util/chrono/time_point.hpp
copy to cppcache/src/util/chrono/time_point.cpp
index 5614598..c39aa5b 100644
--- a/cppcache/src/util/chrono/time_point.hpp
+++ b/cppcache/src/util/chrono/time_point.cpp
@@ -15,27 +15,13 @@
* limitations under the License.
*/
-#pragma once
-
-#ifndef GEODE_UTIL_CHRONO_TIME_POINT_H_
-#define GEODE_UTIL_CHRONO_TIME_POINT_H_
-
-#include <iomanip>
-#include <sstream>
-
#include "time_point.hpp"
namespace apache {
namespace geode {
namespace util {
namespace chrono {
-
-/**
- * Wrapper around platform specific thread safe localtime functions.
- * @param time to get local time for
- * @return local time
- */
-inline std::tm localtime(const time_t& time) {
+std::tm localtime(const time_t& time) {
std::tm localtime;
#if defined(_WIN32)
localtime_s(&localtime, &time);
@@ -45,22 +31,11 @@ inline std::tm localtime(const time_t& time) {
return localtime;
}
-/**
- * Wrapper around platform specific thread safe localtime functions.
- * @param time to get local time for
- * @return local time
- */
-inline std::tm localtime(
- const std::chrono::system_clock::time_point& time_point) {
+std::tm localtime(const std::chrono::system_clock::time_point& time_point) {
return localtime(std::chrono::system_clock::to_time_t(time_point));
}
-/**
- * Produces string representation for given time.
- * @param time to get string for
- * @return string representation of given time
- */
-inline std::string to_string(const time_t& time) {
+std::string to_string(const time_t& time) {
std::stringstream stringstream;
const auto local = localtime(time);
@@ -84,13 +59,7 @@ inline std::string to_string(const time_t& time) {
return stringstream.str();
}
-/**
- * Produces string representation for given time_point.
- * @param time_point to get string for
- * @return string representation of given time_point
- */
-inline std::string to_string(
- const std::chrono::system_clock::time_point& time_point) {
+std::string to_string(const std::chrono::system_clock::time_point& time_point)
{
return to_string(std::chrono::system_clock::to_time_t(time_point));
}
@@ -98,5 +67,3 @@ inline std::string to_string(
} // namespace util
} // namespace geode
} // namespace apache
-
-#endif /* GEODE_UTIL_CHRONO_TIME_POINT_H_ */
diff --git a/cppcache/src/util/chrono/time_point.hpp
b/cppcache/src/util/chrono/time_point.hpp
index 5614598..498615b 100644
--- a/cppcache/src/util/chrono/time_point.hpp
+++ b/cppcache/src/util/chrono/time_point.hpp
@@ -20,11 +20,11 @@
#ifndef GEODE_UTIL_CHRONO_TIME_POINT_H_
#define GEODE_UTIL_CHRONO_TIME_POINT_H_
+#include <chrono>
+#include <ctime>
#include <iomanip>
#include <sstream>
-#include "time_point.hpp"
-
namespace apache {
namespace geode {
namespace util {
@@ -35,64 +35,28 @@ namespace chrono {
* @param time to get local time for
* @return local time
*/
-inline std::tm localtime(const time_t& time) {
- std::tm localtime;
-#if defined(_WIN32)
- localtime_s(&localtime, &time);
-#else
- localtime_r(&time, &localtime);
-#endif
- return localtime;
-}
+std::tm localtime(const time_t& time);
/**
* Wrapper around platform specific thread safe localtime functions.
* @param time to get local time for
* @return local time
*/
-inline std::tm localtime(
- const std::chrono::system_clock::time_point& time_point) {
- return localtime(std::chrono::system_clock::to_time_t(time_point));
-}
+std::tm localtime(const std::chrono::system_clock::time_point& time_point);
/**
* Produces string representation for given time.
* @param time to get string for
* @return string representation of given time
*/
-inline std::string to_string(const time_t& time) {
- std::stringstream stringstream;
- const auto local = localtime(time);
-
-#if defined(_WIN32)
- /*
- Windows does not allow for time_t to be negative (in the past). Any negative
- time_t will result in a tm with negative values. Converting this to a string
- will result in an assertion failure. The original string converstion would
- then result in something like -1/-1/1998. Rather than return a formatted but
- invalid time we should return a string indicating and invalid time failed to
- convert.
-
- TODO: replace with C++20 std::chrono::format or other date library
- */
- if (-1 == local.tm_hour) {
- return "invalid time";
- }
-#endif
-
- stringstream << std::put_time(&local, "%c %Z");
- return stringstream.str();
-}
+std::string to_string(const time_t& time);
/**
* Produces string representation for given time_point.
* @param time_point to get string for
* @return string representation of given time_point
*/
-inline std::string to_string(
- const std::chrono::system_clock::time_point& time_point) {
- return to_string(std::chrono::system_clock::to_time_t(time_point));
-}
+std::string to_string(const std::chrono::system_clock::time_point& time_point);
} // namespace chrono
} // namespace util
diff --git a/cppcache/src/statistics/ProcessStats.cpp
b/cppcache/src/util/concurrent/spinlock_mutex.cpp
similarity index 71%
copy from cppcache/src/statistics/ProcessStats.cpp
copy to cppcache/src/util/concurrent/spinlock_mutex.cpp
index 5a2dac4..79a213a 100644
--- a/cppcache/src/statistics/ProcessStats.cpp
+++ b/cppcache/src/util/concurrent/spinlock_mutex.cpp
@@ -14,22 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "ProcessStats.hpp"
+
+#include "spinlock_mutex.hpp"
namespace apache {
namespace geode {
-namespace statistics {
-
-/**
- * Creates a new <code>ProcessStats</code> that wraps the given
- * <code>Statistics</code>.
- */
-ProcessStats::ProcessStats() {}
+namespace util {
+namespace concurrent {
-int64_t ProcessStats::getProcessSize() { return 0; }
+void spinlock_mutex::lock() {
+ while (flag.test_and_set(std::memory_order_acquire)) continue;
+}
-ProcessStats::~ProcessStats() {}
+void spinlock_mutex::unlock() { flag.clear(std::memory_order_release); }
-} // namespace statistics
-} // namespace geode
-} // namespace apache
+} /* namespace concurrent */
+} /* namespace util */
+} /* namespace geode */
+} /* namespace apache */
diff --git a/cppcache/src/util/concurrent/spinlock_mutex.hpp
b/cppcache/src/util/concurrent/spinlock_mutex.hpp
index ab59159..f6c903f 100644
--- a/cppcache/src/util/concurrent/spinlock_mutex.hpp
+++ b/cppcache/src/util/concurrent/spinlock_mutex.hpp
@@ -22,21 +22,21 @@
#include <atomic>
+#include "apache-geode_export.h"
+
namespace apache {
namespace geode {
namespace util {
namespace concurrent {
-class spinlock_mutex final {
+class APACHE_GEODE_EXPORT spinlock_mutex final {
private:
std::atomic_flag flag = ATOMIC_FLAG_INIT;
public:
- void lock() {
- while (flag.test_and_set(std::memory_order_acquire)) continue;
- }
+ void lock();
- void unlock() { flag.clear(std::memory_order_release); }
+ void unlock();
spinlock_mutex() = default;
spinlock_mutex(const spinlock_mutex &) = delete;
diff --git a/cppcache/src/util/queue.hpp b/cppcache/src/util/queue.hpp
index 3e0092a..f3a26e7 100644
--- a/cppcache/src/util/queue.hpp
+++ b/cppcache/src/util/queue.hpp
@@ -35,7 +35,7 @@ namespace queue {
* @param value to coalesce
*/
template <class Queue, class Type>
-inline void coalesce(Queue& queue, const Type& value) {
+void coalesce(Queue& queue, const Type& value) {
while (!queue.empty()) {
const auto& next = queue.front();
if (next == value) {
diff --git a/cppcache/src/util/string.hpp b/cppcache/src/util/string.cpp
similarity index 90%
copy from cppcache/src/util/string.hpp
copy to cppcache/src/util/string.cpp
index f0b8d12..4bd305d 100644
--- a/cppcache/src/util/string.hpp
+++ b/cppcache/src/util/string.cpp
@@ -15,15 +15,11 @@
* limitations under the License.
*/
-#pragma once
-
-#ifndef GEODE_UTIL_STRING_H_
-#define GEODE_UTIL_STRING_H_
+#include "string.hpp"
#include <cctype>
#include <codecvt>
#include <locale>
-#include <string>
#include "type_traits.hpp"
@@ -38,7 +34,7 @@ constexpr std::codecvt_mode codecvt_mode_native_endian =
endian::native == endian::little ? std::little_endian
: static_cast<std::codecvt_mode>(0);
-inline std::u16string to_utf16(const std::string& utf8) {
+std::u16string to_utf16(const std::string& utf8) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -55,7 +51,7 @@ inline std::u16string to_utf16(const std::string& utf8) {
#endif
}
-inline std::u16string to_utf16(const std::u32string& ucs4) {
+std::u16string to_utf16(const std::u32string& ucs4) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -79,7 +75,7 @@ inline std::u16string to_utf16(const std::u32string& ucs4) {
bytes.length() / sizeof(char16_t));
}
-inline std::u16string to_utf16(const char32_t* ucs4, size_t len) {
+std::u16string to_utf16(const char32_t* ucs4, size_t len) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -103,7 +99,7 @@ inline std::u16string to_utf16(const char32_t* ucs4, size_t
len) {
bytes.length() / sizeof(char16_t));
}
-inline std::u32string to_ucs4(const std::u16string& utf16) {
+std::u32string to_ucs4(const std::u16string& utf16) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -126,7 +122,7 @@ inline std::u32string to_ucs4(const std::u16string& utf16) {
#endif
}
-inline std::string to_utf8(const std::u16string& utf16) {
+std::string to_utf8(const std::u16string& utf16) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -141,7 +137,7 @@ inline std::string to_utf8(const std::u16string& utf16) {
#endif
}
-inline std::string to_utf8(const std::u32string& ucs4) {
+std::string to_utf8(const std::u32string& ucs4) {
#if defined(_MSC_VER) && _MSC_VER >= 1900
/*
* Workaround for missing std:codecvt identifier.
@@ -156,8 +152,7 @@ inline std::string to_utf8(const std::u32string& ucs4) {
#endif
}
-inline bool equal_ignore_case(const std::string& str1,
- const std::string& str2) {
+bool equal_ignore_case(const std::string& str1, const std::string& str2) {
return ((str1.size() == str2.size()) &&
std::equal(str1.begin(), str1.end(), str2.begin(),
[](const char& c1, const char& c2) {
@@ -169,5 +164,3 @@ inline bool equal_ignore_case(const std::string& str1,
} // namespace client
} // namespace geode
} // namespace apache
-
-#endif // GEODE_UTIL_STRING_H_
diff --git a/cppcache/src/util/string.hpp b/cppcache/src/util/string.hpp
index f0b8d12..6f3bec2 100644
--- a/cppcache/src/util/string.hpp
+++ b/cppcache/src/util/string.hpp
@@ -31,140 +31,19 @@ namespace apache {
namespace geode {
namespace client {
-/**
- * Native codecvt_mode endianess
- */
-constexpr std::codecvt_mode codecvt_mode_native_endian =
- endian::native == endian::little ? std::little_endian
- : static_cast<std::codecvt_mode>(0);
-
-inline std::u16string to_utf16(const std::string& utf8) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto int16String =
- std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t>{}
- .from_bytes(utf8);
- return std::u16string(reinterpret_cast<const char16_t*>(int16String.data()),
- int16String.size());
-#else
- return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}
- .from_bytes(utf8);
-#endif
-}
-
-inline std::u16string to_utf16(const std::u32string& ucs4) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto data = reinterpret_cast<const int32_t*>(ucs4.data());
- auto bytes =
- std::wstring_convert<
- std::codecvt_utf16<int32_t, 0x10ffff, codecvt_mode_native_endian>,
- int32_t>{}
- .to_bytes(data, data + ucs4.size());
-#else
- auto bytes =
- std::wstring_convert<
- std::codecvt_utf16<char32_t, 0x10ffff, codecvt_mode_native_endian>,
- char32_t>{}
- .to_bytes(ucs4);
-#endif
-
- return std::u16string(reinterpret_cast<const char16_t*>(bytes.c_str()),
- bytes.length() / sizeof(char16_t));
-}
+std::u16string to_utf16(const std::string& utf8);
-inline std::u16string to_utf16(const char32_t* ucs4, size_t len) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto data = reinterpret_cast<const int32_t*>(ucs4);
- auto bytes =
- std::wstring_convert<
- std::codecvt_utf16<int32_t, 0x10ffff, codecvt_mode_native_endian>,
- int32_t>{}
- .to_bytes(data, data + len);
-#else
- auto bytes =
- std::wstring_convert<
- std::codecvt_utf16<char32_t, 0x10ffff, codecvt_mode_native_endian>,
- char32_t>{}
- .to_bytes(ucs4, ucs4 + len);
-#endif
+std::u16string to_utf16(const std::u32string& ucs4);
- return std::u16string(reinterpret_cast<const char16_t*>(bytes.c_str()),
- bytes.length() / sizeof(char16_t));
-}
+std::u16string to_utf16(const char32_t* ucs4, size_t len);
-inline std::u32string to_ucs4(const std::u16string& utf16) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto data = reinterpret_cast<const char*>(utf16.data());
- auto tmp =
- std::wstring_convert<
- std::codecvt_utf16<int32_t, 0x10ffff, codecvt_mode_native_endian>,
- int32_t>{}
- .from_bytes(data, data + (utf16.length() * sizeof(char16_t)));
- return std::u32string(reinterpret_cast<const char32_t*>(tmp.data()),
- tmp.length());
-#else
- auto data = reinterpret_cast<const char*>(utf16.data());
- return std::wstring_convert<
- std::codecvt_utf16<char32_t, 0x10ffff,
codecvt_mode_native_endian>,
- char32_t>{}
- .from_bytes(data, data + (utf16.length() * sizeof(char16_t)));
-#endif
-}
+std::u32string to_ucs4(const std::u16string& utf16);
-inline std::string to_utf8(const std::u16string& utf16) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto data = reinterpret_cast<const int16_t*>(utf16.data());
- return std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t>{}
- .to_bytes(data, data + utf16.size());
-#else
- return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}
- .to_bytes(utf16);
-#endif
-}
+std::string to_utf8(const std::u16string& utf16);
-inline std::string to_utf8(const std::u32string& ucs4) {
-#if defined(_MSC_VER) && _MSC_VER >= 1900
- /*
- * Workaround for missing std:codecvt identifier.
- *
https://stackoverflow.com/questions/32055357/visual-studio-c-2015-stdcodecvt-with-char16-t-or-char32-t
- */
- auto data = reinterpret_cast<const int32_t*>(ucs4.data());
- return std::wstring_convert<std::codecvt_utf8<int32_t>, int32_t>{}.to_bytes(
- data, data + ucs4.size());
-#else
- return std::wstring_convert<std::codecvt_utf8<char32_t>,
char32_t>{}.to_bytes(
- ucs4);
-#endif
-}
+std::string to_utf8(const std::u32string& ucs4);
-inline bool equal_ignore_case(const std::string& str1,
- const std::string& str2) {
- return ((str1.size() == str2.size()) &&
- std::equal(str1.begin(), str1.end(), str2.begin(),
- [](const char& c1, const char& c2) {
- return (c1 == c2 ||
- std::toupper(c1) == std::toupper(c2));
- }));
-}
+bool equal_ignore_case(const std::string& str1, const std::string& str2);
} // namespace client
} // namespace geode