Skip to content

Commit

Permalink
latest from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Aug 6, 2022
1 parent fbd90da commit a02e669
Show file tree
Hide file tree
Showing 36 changed files with 632 additions and 1,898 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class Line2D
double distanceToPoint(const Point& P) const;
//Return a point that is a distance d from the point P which is on the line
Point offsetFromPoint(const Point& P, double distance) const;
//
bool equals(const Line2D& other) const;

friend bool operator==(const Line2D& lhs, const Line2D& rhs)
{
return lhs.equals(rhs);
}
private:
Line2DType mType;
double mSlope;
Expand Down
20 changes: 20 additions & 0 deletions externals/coda-oss/modules/c++/math.linear/source/Line2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ Line2D::Point Line2D::offsetFromPoint(const Point& P, double distance) const
ret.col += distance * std::sin(theta);
return ret;
}

bool Line2D::equals(const Line2D& other) const
{
if (mType == other.mType)
{
if (mType != Line2D::NORMAL)
{
return true;
}
else
{
if ((getSlope() == other.getSlope())
&& (getYIntercept() == other.getYIntercept()))
{
return true;
}
}
}
return false;
}
}
}

17 changes: 8 additions & 9 deletions externals/coda-oss/modules/c++/std/include/std/bit
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
// Make it (too?) easy for clients to get our various std:: implementations
#ifndef CODA_OSS_NO_std_endian
#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
// Some C++17 implementations have <bit>
#if CODA_OSS_cpp20
// Some implementations cliam to be C++20 w/o <bit>
#if __has_include(<bit>) // __has_include is C++17
#include <bit>
#define CODA_OSS_NO_std_endian 1 // provided by implementation, probably C++20
#else
#include "coda_oss/bit.h"
#define CODA_OSS_NO_std_endian 0 // no <bit>, use our own
#include <bit>
#define CODA_OSS_NO_std_endian 1 // provided by implementation, probably C++20
#endif
#else
#endif
// At this point, CODA_OSS_NO_std_endian will be set only if we were able to successfully use <bit> (above)
#ifndef CODA_OSS_NO_std_endian
#include "coda_oss/bit.h"
#define CODA_OSS_NO_std_endian 0 // < C++17, use our own
#define CODA_OSS_NO_std_endian 0 // <= C++17, use our own
#endif
#endif

Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/std/include/std/string
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
// Make it (too?) easy for clients to get our various std:: implementations
#ifndef CODA_OSS_NO_std_u8string
#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
#define CODA_OSS_NO_std_u8string 1 // part of C++17
#if CODA_OSS_cpp20
#define CODA_OSS_NO_std_u8string 1 // part of C++20
#else
#include "coda_oss/string.h"
#define CODA_OSS_NO_std_u8string 0 // use our own
Expand Down
1 change: 0 additions & 1 deletion externals/coda-oss/modules/c++/str/include/str/Encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ CODA_OSS_API str::W1252string to_w1252string(coda_oss::u8string::const_pointer p
namespace details // YOU should use EncodedStringView
{
void w1252to8(str::W1252string::const_pointer p, size_t sz, std::string&); // encoding is lost
void utf16to8(std::u16string::const_pointer, size_t, std::string&); // encoding is lost
void utf8to1252(coda_oss::u8string::const_pointer p, size_t sz, std::string&); // encoding is lost
}
}
Expand Down
3 changes: 1 addition & 2 deletions externals/coda-oss/modules/c++/str/source/EncodedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
* see <http://www.gnu.org/licenses/>.
*
*/
#include "str/EncodedString.h"

#include <type_traits>

#include "str/EncodedString.h"

void str::EncodedString::assign(coda_oss::u8string::const_pointer s)
{
using char_t = std::remove_pointer<decltype(s)>::type; // avoid copy-paste error
Expand Down
15 changes: 10 additions & 5 deletions externals/coda-oss/modules/c++/str/source/Encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include <assert.h>
#include <string.h>
#if _WIN32
#include <comdef.h> // _bstr_t
#endif

#include <map>
#include <locale>
Expand Down Expand Up @@ -171,7 +174,13 @@ void str::details::w1252to8(str::W1252string::const_pointer p, size_t sz, std::s
}
std::u16string str::to_u16string(str::W1252string::const_pointer p, size_t sz)
{
return to_Tstring<std::u16string>(p, sz);
auto retval = to_Tstring<std::u16string>(p, sz);
#if defined(_WIN32) && (!defined(_NDEBUG) || defined(DEBUG))
const _bstr_t bstr(str::cast<const char*>(p));
const std::wstring wstr(static_cast<const wchar_t*>(bstr));
assert(retval == str::cast<std::u16string::const_pointer>(wstr.c_str()));
#endif
return retval;
}
str::ui16string str::to_ui16string(str::W1252string::const_pointer p, size_t sz)
{
Expand Down Expand Up @@ -299,10 +308,6 @@ coda_oss::u8string str::to_u8string(std::u16string::const_pointer p, size_t sz)
utf8::utf8to16(begin, begin+result.size(), std::back_inserter(utf16line));
*/
}
void str::details::utf16to8(std::u16string::const_pointer p, size_t sz, std::string& result)
{
utf8::utf16to8(p, p + sz, std::back_inserter(result));
}

std::u16string str::to_u16string(coda_oss::u8string::const_pointer p_, size_t sz)
{
Expand Down
23 changes: 10 additions & 13 deletions externals/coda-oss/modules/c++/str/unittests/test_base_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@

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

#include "TestCase.h"

inline static void test_assert_eq(const std::string& testName, const std::u8string& actual, const std::u8string& expected)
{
TEST_ASSERT_EQ(actual, expected);
}
inline static void test_assert_eq(const std::string& testName, const std::u8string& actual, const std::u32string& expected)
{
test_assert_eq(testName, actual, str::to_u8string(expected));
TEST_ASSERT_EQ(actual, str::to_u8string(expected));
}

TEST_CASE(testConvert)
Expand Down Expand Up @@ -106,7 +103,7 @@ TEST_CASE(test_string_to_u8string_ascii)
const std::string input { '|', static_cast<std::string::value_type>(ch), '|'};
const auto actual = fromWindows1252(input);
const std::u8string expected8{cast8('|'), cast8(ch), cast8('|')};
test_assert_eq(testName, actual, expected8);
TEST_ASSERT_EQ(actual, expected8);
const std::u32string expected{U'|', U(ch), U'|'};
test_assert_eq(testName, actual, expected);
}
Expand All @@ -119,16 +116,16 @@ TEST_CASE(test_string_to_u8string_windows_1252)
const std::string input = "|\x80|"; // Windows-1252, "|€|"
const auto actual = fromWindows1252(input);
const std::u8string expected8{cast8('|'), cast8('\xE2'), cast8('\x82'), cast8('\xAC'), cast8('|')}; // UTF-8, "|€|"
test_assert_eq(testName, actual, expected8);
const std::u32string expected{U"|\U000020AC|"}; // UTF-32, "|€|"
TEST_ASSERT_EQ(actual, expected8);
const std::u32string expected{U"|\u20AC|"}; // UTF-32, "|€|"
test_assert_eq(testName, actual, expected);
}
{
const std::string input = "|\x9F|"; // Windows-1252, "|Ÿ|"
const auto actual = fromWindows1252(input);
const std::u8string expected8{cast8('|'), cast8('\xC5'), cast8('\xB8'), cast8('|')}; // UTF-8, "|Ÿ|"
test_assert_eq(testName, actual, expected8);
const std::u32string expected{U"|\U00000178|"}; // UTF-32, "|Ÿ|"
TEST_ASSERT_EQ(actual, expected8);
const std::u32string expected{U"|\u0178|"}; // UTF-32, "|Ÿ|"
test_assert_eq(testName, actual, expected);
}
{
Expand All @@ -138,8 +135,8 @@ TEST_CASE(test_string_to_u8string_windows_1252)
const std::string input{'|', ch, '|'};
const auto actual = fromWindows1252(input);
static const std::u8string expected8{cast8('|'), cast8('\xEF'), cast8('\xBF'), cast8('\xBD'), cast8('|')}; // UTF-8, "|<REPLACEMENT CHARACTER>|"
test_assert_eq(testName, actual, expected8);
const std::u32string expected{U"|\U0000fffd|"}; // UTF-32, "|<REPLACEMENT CHARACTER>|"
TEST_ASSERT_EQ(actual, expected8);
const std::u32string expected{U"|\ufffd|"}; // UTF-32, "|<REPLACEMENT CHARACTER>|"
test_assert_eq(testName, actual, expected);
}
}
Expand Down Expand Up @@ -183,7 +180,7 @@ TEST_CASE(test_string_to_u8string_windows_1252)
// are mapped one-by-one. However, we can test that UTF-8 to Windows-1252
// works as that walks through a UTF-8 string which can have 1-, 2-, 3- and 4-bytes
// for a single code-point.
const auto w1252 = str::EncodedStringView::details::w1252string(str::EncodedStringView(actual));
const auto w1252 = str::to_w1252string(actual.data(), actual.size());
TEST_ASSERT(input == w1252);

// Can't compare the values with == because TEST_ASSERT_EQ()
Expand Down
13 changes: 4 additions & 9 deletions externals/coda-oss/modules/c++/sys/source/sys_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <stdlib.h>
#ifdef _WIN32
#include <direct.h>
#include <comdef.h> // _bstr_t
#else
#include <unistd.h>
#endif
Expand All @@ -17,6 +16,7 @@

#include "sys/Path.h"
#include "gsl/gsl.h"
#include "str/EncodedString.h"

namespace fs = sys::filesystem;

Expand Down Expand Up @@ -47,9 +47,9 @@ static inline std::string make_what(const char* curfile, const int lineNum, cons

fs::path::string_type fs::path::to_native(const std::string& s_)
{

#ifdef _WIN32
const _bstr_t s(s_.c_str()); // convert to wchar_t
return static_cast<const wchar_t*>(s);
return str::EncodedStringView(s_).wstring();
#else
return s_;
#endif
Expand Down Expand Up @@ -104,12 +104,7 @@ fs::path::operator string_type() const

std::string fs::path::string() const
{
#ifdef _WIN32
const _bstr_t p(c_str());
return static_cast<const char*>(p);
#else
return native();
#endif
return str::EncodedString(p_).native();
}

fs::path fs::path::root_path() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ class ContentHandler
* \param length The length of the new data
*/
virtual void characters(const char *data, int length) = 0;

virtual bool vcharacters(const void/*XMLCh*/*, size_t /*length*/) // avoid XMLCh, it's specific to Xerces
{ return false; /* continue on to existing characters()*/ } /* =0 would break existing code */
virtual bool call_vcharacters() const // =0 would break existing code
{
return false; // don't call vcharacters(const void*)
}
virtual bool vcharacters(const void/*XMLCh*/*, size_t /*length*/) = 0; // avoid XMLCh, it's specific to Xerces

/*!
* Receive notification of the beginning of an element.
Expand Down
Loading

0 comments on commit a02e669

Please sign in to comment.