Skip to content

Commit

Permalink
latest from CODA-OSS and NITRO
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Aug 25, 2023
1 parent 49e28e2 commit 776c65c
Show file tree
Hide file tree
Showing 27 changed files with 575 additions and 1,148 deletions.
2 changes: 0 additions & 2 deletions externals/coda-oss/UnitTest/str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <string>

#include <import/str.h>
#include <str/EncodedString.h>
#include <str/EncodedStringView.h>

namespace str
{
Expand Down
5 changes: 1 addition & 4 deletions externals/coda-oss/modules/c++/coda-oss.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,12 @@
<ClInclude Include="sio.lite\include\sio\lite\UserDataDictionary.h" />
<ClInclude Include="std\include\import\std.h" />
<ClInclude Include="str\include\str\Convert.h" />
<ClInclude Include="str\include\str\EncodedString.h" />
<ClInclude Include="str\include\str\EncodedStringView.h" />
<ClInclude Include="str\include\str\Encoding.h" />
<ClInclude Include="str\include\str\Format.h" />
<ClInclude Include="str\include\str\Manip.h" />
<ClInclude Include="str\include\str\Tokenizer.h" />
<ClInclude Include="str\include\str\utf8.h" />
<ClInclude Include="str\include\str\W1252string.h" />
<ClInclude Include="sys\include\sys\AbstractOS.h" />
<ClInclude Include="sys\include\sys\AtomicCounter.h" />
<ClInclude Include="sys\include\sys\AtomicCounterCpp11.h" />
Expand Down Expand Up @@ -422,8 +421,6 @@
<ClCompile Include="sio.lite\source\SioFileWriter.cpp" />
<ClCompile Include="sio.lite\source\StreamReader.cpp" />
<ClCompile Include="str\source\Convert.cpp" />
<ClCompile Include="str\source\EncodedString.cpp" />
<ClCompile Include="str\source\EncodedStringView.cpp" />
<ClCompile Include="str\source\Encoding.cpp" />
<ClCompile Include="str\source\Format.cpp" />
<ClCompile Include="str\source\Manip.cpp" />
Expand Down
21 changes: 6 additions & 15 deletions externals/coda-oss/modules/c++/coda-oss.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@
<ClInclude Include="str\include\str\Convert.h">
<Filter>str</Filter>
</ClInclude>
<ClInclude Include="str\include\str\EncodedString.h">
<Filter>str</Filter>
</ClInclude>
<ClInclude Include="str\include\str\EncodedStringView.h">
<Filter>str</Filter>
</ClInclude>
<ClInclude Include="str\include\str\Encoding.h">
<Filter>str</Filter>
</ClInclude>
Expand Down Expand Up @@ -954,6 +948,9 @@
<ClInclude Include="mem\include\mem\AutoPtr.h">
<Filter>mem</Filter>
</ClInclude>
<ClInclude Include="str\include\str\W1252string.h">
<Filter>str</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand All @@ -972,12 +969,6 @@
<ClCompile Include="str\source\Convert.cpp">
<Filter>str</Filter>
</ClCompile>
<ClCompile Include="str\source\EncodedString.cpp">
<Filter>str</Filter>
</ClCompile>
<ClCompile Include="str\source\EncodedStringView.cpp">
<Filter>str</Filter>
</ClCompile>
<ClCompile Include="str\source\Encoding.cpp">
<Filter>str</Filter>
</ClCompile>
Expand Down Expand Up @@ -1415,9 +1406,6 @@
<Filter Include="gsl">
<UniqueIdentifier>{619ad1da-f21c-4027-9b5d-23f08225b96f}</UniqueIdentifier>
</Filter>
<Filter Include="coda_oss">
<UniqueIdentifier>{59f3d9a1-06d3-4779-aef2-cc55223c3017}</UniqueIdentifier>
</Filter>
<Filter Include="std">
<UniqueIdentifier>{3051f4b6-dad4-47ea-b4bd-d25d9e09f782}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -1502,6 +1490,9 @@
<Filter Include="unique">
<UniqueIdentifier>{79aa73a7-ed0d-4826-b7ed-c8d91d96998a}</UniqueIdentifier>
</Filter>
<Filter Include="coda_oss">
<UniqueIdentifier>{59f3d9a1-06d3-4779-aef2-cc55223c3017}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="gsl\include\gsl\algorithm">
Expand Down
3 changes: 1 addition & 2 deletions externals/coda-oss/modules/c++/include/UnitTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>

#include "TestCase.h"
#include "str/EncodedStringView.h"

#if !_MSC_VER
#error "This file is for use with a Visual Studio 'UnitTest' project."
Expand Down Expand Up @@ -133,7 +132,7 @@ inline void assert_almost_eq(const std::string& testName, long double X1, long d
#define TEST_ASSERT_EQ_MSG(msg, X1, X2) testName, Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(msg.c_str()); TEST_ASSERT_EQ(X1, X2)

#undef TEST_FAIL_MSG
#define TEST_FAIL_MSG(msg) { (void)testName; Microsoft::VisualStudio::CppUnitTestFramework::Assert::Fail(str::EncodedStringView(msg).wstring().c_str()); }
#define TEST_FAIL_MSG(msg) { (void)testName; Microsoft::VisualStudio::CppUnitTestFramework::Assert::Fail(str::toWString(msg).c_str()); }

#undef TEST_EXCEPTION
#undef TEST_THROWS
Expand Down
14 changes: 7 additions & 7 deletions externals/coda-oss/modules/c++/mem/unittests/test_unique_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ TEST_CASE(testStdUniquePtr)
TEST_ASSERT_NULL(fooCtor.get());

fooCtor.reset(new Foo(123));
TEST_ASSERT_NOT_EQ(nullptr, fooCtor.get());
TEST_ASSERT_NOT_NULL(fooCtor.get());
TEST_ASSERT_EQ(123, fooCtor->mVal);
}
{
auto fooCtor = std::make_unique<Foo>(123);
TEST_ASSERT_NOT_EQ(nullptr, fooCtor.get());
TEST_ASSERT_NOT_NULL(fooCtor.get());
TEST_ASSERT_EQ(123, fooCtor->mVal);
}
{
auto pFoos = std::make_unique<Foo[]>(123); // 123 instances of Foo
TEST_ASSERT_NOT_EQ(nullptr, pFoos.get());
TEST_ASSERT_NOT_NULL(pFoos.get());
TEST_ASSERT_EQ(0, pFoos[0].mVal);
TEST_ASSERT_EQ(0, pFoos[122].mVal);
}
Expand All @@ -65,24 +65,24 @@ TEST_CASE(test_make_unique)
{
{
auto fooCtor = std::make_unique<Foo>(123);
TEST_ASSERT_NOT_EQ(nullptr, fooCtor.get());
TEST_ASSERT_NOT_NULL(fooCtor.get());
TEST_ASSERT_EQ(123, fooCtor->mVal);
}
{
auto pFoos = std::make_unique<Foo[]>(123); // 123 instances of Foo
TEST_ASSERT_NOT_EQ(nullptr, pFoos.get());
TEST_ASSERT_NOT_NULL(pFoos.get());
TEST_ASSERT_EQ(0, pFoos[0].mVal);
TEST_ASSERT_EQ(0, pFoos[122].mVal);
}

{
auto fooCtor = std::make_unique<Foo>(123);
TEST_ASSERT_NOT_EQ(nullptr, fooCtor.get());
TEST_ASSERT_NOT_NULL(fooCtor.get());
TEST_ASSERT_EQ(123, fooCtor->mVal);
}
{
auto pFoos = std::make_unique<Foo[]>(123); // 123 instances of Foo
TEST_ASSERT_NOT_EQ(nullptr, pFoos.get());
TEST_ASSERT_NOT_NULL(pFoos.get());
TEST_ASSERT_EQ(0, pFoos[0].mVal);
TEST_ASSERT_EQ(0, pFoos[122].mVal);
}
Expand Down
45 changes: 36 additions & 9 deletions externals/coda-oss/modules/c++/str/include/str/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "coda_oss/cstddef.h"
#include "types/Complex.h"
#include "import/except.h"
#include "gsl/gsl.h"
#include "str/Encoding.h"

namespace str
{
Expand Down Expand Up @@ -145,7 +147,7 @@ inline std::string toString(double value)
{
return details::default_toString(value);
}
inline std::string oString(long double value)
inline std::string toString(long double value)
{
return details::default_toString(value);
}
Expand All @@ -158,34 +160,53 @@ inline std::string toString(bool value)
}
inline std::string toString(uint8_t value)
{
return toString(static_cast<unsigned int>(value));
return toString(gsl::narrow<unsigned int>(value));
}
inline std::string toString(int8_t value)
{
return toString(static_cast<int>(value));
return toString(gsl::narrow<int>(value));
}
inline std::string toString(coda_oss::byte value)
{
return toString(static_cast<uint8_t>(value));
return toString(gsl::narrow<uint8_t>(value));
}

inline std::string toString(std::nullptr_t)
{
return "<nullptr>";
}

CODA_OSS_API std::string toString(const coda_oss::u8string&);
inline std::string toString(const std::string& value)
{
return value;
}
inline std::string toString(char value)
// can't be a template; `bool` overload above is a better match
inline std::string toString(std::string::const_pointer pStr)
{
return std::string(1, value);
return toString(std::string(pStr));
}

// The resultant `std::string`s have "native" encoding (which is lost) depending
// on the platform: UTF-8 on Linux and Windows-1252 on Windows.
CODA_OSS_API std::string toString(const coda_oss::u8string&);
CODA_OSS_API std::string toString(const str::W1252string&);
CODA_OSS_API std::string toString(const std::wstring&); // input is UTF-16 or UTF-32 depending on the platform
// can't be a template; `bool` overload above is a better match
std::string toString(std::wstring::const_pointer) = delete; // only used in unittests
std::string toString(std::u16string::const_pointer) = delete; // only used in unittests
std::string toString(std::u32string::const_pointer) = delete; // only used in unittests

CODA_OSS_API coda_oss::u8string u8FromString(const std::string&); // platform determines Windows-1252 or UTF-8 input

inline std::ostream& operator<<(std::ostream& os, const coda_oss::u8string& s)
{
os << toString(s);
return os;
}
inline std::string toString(const char* pStr)

inline std::string toString(char value)
{
return std::string(pStr);
return std::string(1, value);
}

template <typename T>
Expand All @@ -207,6 +228,12 @@ inline std::string toString(const T* ptr)
return details::default_toString(ptr);
}

CODA_OSS_API std::wstring toWString(const std::string&); // platform determines Windows-1252 or UTF-8 input and output encoding
CODA_OSS_API std::wstring toWString(const coda_oss::u8string&); // platform determines UTF-16 or UTF-32 output encoding
CODA_OSS_API std::wstring toWString(const str::W1252string&); // platform determines UTF-16 or UTF-32 output encoding

CODA_OSS_API coda_oss::u8string u8FromWString(const std::wstring&); // platform determines UTF16 or UTF-32 input

template <typename T>
T toType(const std::string& s)
{
Expand Down
Loading

0 comments on commit 776c65c

Please sign in to comment.