Skip to content

Commit

Permalink
using std namespace where necessary (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
oktonion authored and onqtam committed Feb 24, 2020
1 parent 0cd62e8 commit 9f5fa6f
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,37 @@ namespace detail {

#ifndef DOCTEST_CONFIG_DISABLE

typedef uint64_t UInt64;
namespace timer_large_integer
{

#if defined(DOCTEST_PLATFORM_WINDOWS)
typedef ULONGLONG type;
#else // DOCTEST_PLATFORM_WINDOWS
using namespace std;
typedef uint64_t type;
#endif // DOCTEST_PLATFORM_WINDOWS
}

typedef timer_large_integer::type ticks_t;

#ifdef DOCTEST_CONFIG_GETCURRENTTICKS
UInt64 getCurrentTicks() { return DOCTEST_CONFIG_GETCURRENTTICKS(); }
ticks_t getCurrentTicks() { return DOCTEST_CONFIG_GETCURRENTTICKS(); }
#elif defined(DOCTEST_PLATFORM_WINDOWS)
UInt64 getCurrentTicks() {
static UInt64 hz = 0, hzo = 0;
if(!hz) {
QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&hz));
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&hzo));
ticks_t getCurrentTicks() {
static LARGE_INTEGER hz = {0}, hzo = {0};
if(!hz.QuadPart) {
QueryPerformanceFrequency(&hz);
QueryPerformanceCounter(&hzo);
}
UInt64 t;
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&t));
return ((t - hzo) * 1000000) / hz;
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
return ((t.QuadPart - hzo.QuadPart) * LONGLONG(1000000)) / hz.QuadPart;
}
#else // DOCTEST_PLATFORM_WINDOWS
UInt64 getCurrentTicks() {
ticks_t getCurrentTicks() {
timeval t;
gettimeofday(&t, nullptr);
return static_cast<UInt64>(t.tv_sec) * 1000000 + static_cast<UInt64>(t.tv_usec);
return static_cast<ticks_t>(t.tv_sec) * 1000000 + static_cast<ticks_t>(t.tv_usec);
}
#endif // DOCTEST_PLATFORM_WINDOWS

Expand All @@ -290,10 +301,10 @@ namespace detail {
//unsigned int getElapsedMilliseconds() const {
// return static_cast<unsigned int>(getElapsedMicroseconds() / 1000);
//}
double getElapsedSeconds() const { return getElapsedMicroseconds() / 1000000.0; }
double getElapsedSeconds() const { return (getCurrentTicks() - m_ticks) / 1000000.0; }

private:
UInt64 m_ticks = 0;
ticks_t m_ticks = 0;
};

// this holds both parameters from the command line and runtime data for tests
Expand Down Expand Up @@ -388,6 +399,7 @@ void String::setOnHeap() { *reinterpret_cast<unsigned char*>(&buf[last]) = 128;
void String::setLast(unsigned in) { buf[last] = char(in); }

void String::copy(const String& other) {
using namespace std;
if(other.isOnStack()) {
memcpy(buf, other.buf, len);
} else {
Expand All @@ -413,6 +425,7 @@ String::String(const char* in)
: String(in, strlen(in)) {}

String::String(const char* in, unsigned in_size) {
using namespace std;
if(in_size <= last) {
memcpy(buf, in, in_size + 1);
setLast(last - in_size);
Expand Down Expand Up @@ -442,6 +455,7 @@ String& String::operator+=(const String& other) {
const unsigned my_old_size = size();
const unsigned other_size = other.size();
const unsigned total_size = my_old_size + other_size;
using namespace std;
if(isOnStack()) {
if(total_size < len) {
// append to the current stack space
Expand Down Expand Up @@ -490,12 +504,14 @@ String& String::operator+=(const String& other) {
String String::operator+(const String& other) const { return String(*this) += other; }

String::String(String&& other) {
using namespace std;
memcpy(buf, other.buf, len);
other.buf[0] = '\0';
other.setLast();
}

String& String::operator=(String&& other) {
using namespace std;
if(this != &other) {
if(!isOnStack())
delete[] data.ptr;
Expand Down Expand Up @@ -532,7 +548,7 @@ unsigned String::capacity() const {

int String::compare(const char* other, bool no_case) const {
if(no_case)
return stricmp(c_str(), other);
return doctest::stricmp(c_str(), other);
return std::strcmp(c_str(), other);
}

Expand Down Expand Up @@ -1037,7 +1053,7 @@ namespace {
#if DOCTEST_MSVC
// this is needed because MSVC gives different case for drive letters
// for __FILE__ when evaluated in a header and a source file
const int res = stricmp(lhs->m_file, rhs->m_file);
const int res = doctest::stricmp(lhs->m_file, rhs->m_file);
#else // MSVC
const int res = std::strcmp(lhs->m_file, rhs->m_file);
#endif // MSVC
Expand Down Expand Up @@ -2031,7 +2047,7 @@ namespace {
void test_case_start_impl(const TestCaseData& in) {
bool open_ts_tag = false;
if(tc != nullptr) { // we have already opened a test suite
if(strcmp(tc->m_test_suite, in.m_test_suite) != 0) {
if(std::strcmp(tc->m_test_suite, in.m_test_suite) != 0) {
xml.endElement();
open_ts_tag = true;
}
Expand Down

0 comments on commit 9f5fa6f

Please sign in to comment.