Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/cpp/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ class Pointer
hx::Object *obj = inVariant.asObject();
ptr = obj ? (T*)inVariant.valObject->__GetHandle() : 0;
}

#if (HXCPP_API_LEVEL >= 500)
inline Pointer(const ::cpp::marshal::PointerReference<T>);
#endif

template<typename O>
inline Pointer( const O *inValue ) : ptr( (T*) inValue) { }
Expand Down Expand Up @@ -512,12 +515,13 @@ class Pointer_obj
return AutoCast(base->GetBase());
}


#if (HXCPP_API_LEVEL >= 500)
template<typename T>
inline static Pointer<T> addressOf(const ::cpp::marshal::ValueReference<T>&);

template<typename T>
inline static Pointer<T*> addressOf(const ::cpp::marshal::PointerReference<T>&);
#endif

template<typename T>
inline static Pointer<T> addressOf(T &value) { return Pointer<T>(&value); }
Expand Down
26 changes: 1 addition & 25 deletions include/cpp/marshal/Definitions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,6 @@ namespace cpp
void set(int64_t index, K value);
};

template<class T>
struct View final
{
::cpp::Pointer<T> ptr;
int64_t length;

View(::cpp::Pointer<T> _ptr, int64_t _length);

void clear() const;
void fill(T value) const;
bool isEmpty() const;
View<T> slice(int64_t index) const;
View<T> slice(int64_t index, int64_t length) const;
void copyTo(const View<T>& destination) const;
bool tryCopyTo(const View<T>& destination) const;
template<class K> View<K> reinterpret() const;
int compare(const View<T>& inRHS) const;

bool operator==(const View<T>& inRHS) const;
bool operator!=(const View<T>& inRHS) const;

T& operator[] (int64_t index) const;
};

class RootHandle
{
::hx::Object** object;
Expand Down Expand Up @@ -327,4 +303,4 @@ template<typename T>
inline cpp::Pointer<T>::Pointer(const ::cpp::marshal::PointerReference<T> ref)
{
ptr = *ref.ptr;
}
}
33 changes: 32 additions & 1 deletion include/cpp/marshal/View.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
#pragma once

#include "Definitions.inc"
#include <stddef.h>
#include <cpp/Pointer.h>

namespace cpp {
namespace marshal {

template<class T>
struct View final {
::cpp::Pointer<T> ptr;
int64_t length;

View(::cpp::Pointer<T> _ptr, int64_t _length);

void clear() const;
void fill(T value) const;
bool isEmpty() const;
View<T> slice(int64_t index) const;
View<T> slice(int64_t index, int64_t length) const;
void copyTo(const View<T>& destination) const;
bool tryCopyTo(const View<T>& destination) const;
template<class K> View<K> reinterpret() const;
int compare(const View<T>& inRHS) const;

bool operator==(const View<T>& inRHS) const;
bool operator!=(const View<T>& inRHS) const;

T& operator[] (int64_t index) const;
};

};
};

#include <cstring>
#include <cmath>

Expand Down
12 changes: 12 additions & 0 deletions include/hx/LessThanEq.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ struct CompareTraits< T * >
inline static bool isNull(T *inValue) { return !inValue; }
};

#if (HXCPP_API_LEVEL>=500)

template <typename T>
struct CompareTraits< cpp::marshal::ValueReference<T> >
{
Expand Down Expand Up @@ -274,6 +276,8 @@ struct CompareTraits< cpp::marshal::PointerReference<T> >
inline static bool isNull(const ::cpp::marshal::PointerReference<T>& ref) { return nullptr == ref.ptr || nullptr == *ref.ptr; }
};

#endif

template<typename T1>
hx::Object *GetExistingObject(const T1 &v1)
{
Expand Down Expand Up @@ -437,6 +441,8 @@ inline bool TestLessEq(const T1 &v1, const T2 &v2)
template<typename T1, typename T2>
bool IsEq(const T1 &v1, const T2 &v2) { return TestLessEq<false,true,T1,T2>(v1,v2); }

#if (HXCPP_API_LEVEL>=500)

template<typename T1, typename T2>
bool IsEq(const ::cpp::marshal::ValueReference<T1>& v1, const ::cpp::marshal::ValueReference<T2>& v2) { return v1 == v2; }

Expand All @@ -459,15 +465,21 @@ bool IsEq(const ::cpp::marshal::PointerReference<T1>& v1, const ::cpp::marshal::
return *v1.ptr == *v2.ptr;
}

#endif

template<typename T1, typename T2>
bool IsNotEq(const T1 &v1, const T2 &v2) { return TestLessEq<false,false,T1,T2>(v1,v2); }

#if (HXCPP_API_LEVEL>=500)

template<typename T1, typename T2>
bool IsNotEq(const ::cpp::marshal::ValueReference<T1>& v1, const ::cpp::marshal::ValueReference<T2>& v2) { return v1 != v2; }

template<typename T1, typename T2>
bool IsNotEq(const ::cpp::marshal::PointerReference<T1>& v1, const ::cpp::marshal::PointerReference<T2>& v2) { return IsEq(v1, v2) == false; }

#endif

template<typename T1, typename T2>
bool IsLess(const T1 &v1, const T2 &v2) { return TestLessEq<true,false,T1,T2>(v1,v2); }

Expand Down
4 changes: 3 additions & 1 deletion include/hx/zip/Zip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <hxcpp.h>
#endif

#include <cpp/marshal/View.hpp>

HX_DECLARE_CLASS2(hx, zip, Zip)

namespace hx
Expand Down Expand Up @@ -33,4 +35,4 @@ namespace hx
virtual void close() = 0;
};
}
}
}
4 changes: 4 additions & 0 deletions include/hxString.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
static String create(const char16_t *inPtr,int inLen=-1);
static String create(const char *inPtr,int inLen=-1);

#if (HXCPP_API_LEVEL >= 500)
static String create(const ::cpp::marshal::View<char>& buffer);
static String create(const ::cpp::marshal::View<char16_t>& buffer);
#endif

// Uses non-gc memory and wont ever be collected
static ::String createPermanent(const char *inUtf8, int inLen);
Expand Down Expand Up @@ -174,8 +176,10 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
const wchar_t *wchar_str(hx::IStringAlloc *inBuffer = 0) const;
const char16_t *wc_str(hx::IStringAlloc *inBuffer = 0, int *outCharLength = 0) const;

#if (HXCPP_API_LEVEL >= 500)
bool wc_str(::cpp::marshal::View<char16_t> buffer, int* outCharLength = nullptr) const;
bool utf8_str(::cpp::marshal::View<char> buffer, int* outByteLength = nullptr) const;
#endif

const char *__CStr() const { return utf8_str(); };
const wchar_t *__WCStr() const { return wchar_str(0); }
Expand Down
26 changes: 14 additions & 12 deletions include/hxcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,15 @@ namespace hx { template<typename O> class ObjectPtr; }
namespace cpp { template<typename S,typename H> class Struct; }
namespace cpp { template<typename T> class Pointer; }
namespace cpp { template<typename T> class Function; }
#if (HXCPP_API_LEVEL>=500)
namespace cpp { namespace marshal { template<class T> class Boxed_obj; } }
namespace cpp { namespace marshal { template<class T> using Boxed =::hx::ObjectPtr<Boxed_obj<T>>; } }
namespace cpp { namespace marshal { template<class T> class ValueType; } }
namespace cpp { namespace marshal { template<class T> class ValueReference; } }
namespace cpp { namespace marshal { template<class T> class PointerType; } }
namespace cpp { namespace marshal { template<class T> class PointerReference; } }
namespace cpp { namespace marshal { template<class T> struct View; } }
#endif
template<typename ELEM_> class Array_obj;
template<typename ELEM_> class Array;
namespace hx {
Expand Down Expand Up @@ -360,21 +362,21 @@ typedef PropertyAccessMode PropertyAccess;
#endif
#include <hx/StdLibs.h>
#include <cpp/Pointer.h>
#include <cpp/marshal/Boxed.hpp>
#include <cpp/marshal/ValueType.hpp>
#include <cpp/marshal/PointerType.hpp>
#include <cpp/marshal/ValueReference.hpp>
#include <cpp/marshal/PointerReference.hpp>
#include <cpp/marshal/View.hpp>
#include <cpp/marshal/Marshal.hpp>
#include <cpp/marshal/RootHandle.hpp>
#include <cpp/encoding/Ascii.hpp>
#include <cpp/encoding/Utf8.hpp>
#include <cpp/encoding/Utf16.hpp>
#include <hx/Native.h>
#include <hx/Operators.h>
#if (HXCPP_API_LEVEL>=500)
#include <hx/Invoker.h>
#include <cpp/marshal/Boxed.hpp>
#include <cpp/marshal/ValueType.hpp>
#include <cpp/marshal/PointerType.hpp>
#include <cpp/marshal/ValueReference.hpp>
#include <cpp/marshal/PointerReference.hpp>
#include <cpp/marshal/View.hpp>
#include <cpp/marshal/Marshal.hpp>
#include <cpp/marshal/RootHandle.hpp>
#include <cpp/encoding/Ascii.hpp>
#include <cpp/encoding/Utf8.hpp>
#include <cpp/encoding/Utf16.hpp>
#include <hx/Invoker.h>
#endif
// second time ...
#include <cpp/Variant.h>
Expand Down
8 changes: 8 additions & 0 deletions src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ String String::create(const char *inString,int inLength)
return String(s,len);
}

#if (HXCPP_API_LEVEL>=500)

String String::create(const::cpp::marshal::View<char>& buffer)
{
auto start = buffer.ptr.ptr;
Expand Down Expand Up @@ -826,6 +828,8 @@ String String::create(const cpp::marshal::View<char16_t>& buffer)
return String::create(buffer.ptr.ptr, buffer.length - (end - start) - extra);
}

#endif

String::String(const Dynamic &inRHS)
{
if (inRHS.GetPtr())
Expand Down Expand Up @@ -1800,6 +1804,8 @@ const char16_t * String::wc_str(hx::IStringAlloc *inBuffer, int *outCharLength)
return str;
}

#if (HXCPP_API_LEVEL>=500)

bool String::wc_str(::cpp::marshal::View<char16_t> buffer, int* outCharLength) const
{
#ifdef HX_SMART_STRINGS
Expand Down Expand Up @@ -1922,6 +1928,8 @@ bool String::utf8_str(::cpp::marshal::View<char> buffer, int* outByteLength) con
return true;
}

#endif

const wchar_t * String::wchar_str(hx::IStringAlloc *inBuffer) const
{
if (!__s)
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/encoding/Encodings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <hxcpp.h>

#if (HXCPP_API_LEVEL>=500)
#include <array>

using namespace cpp::marshal;
Expand Down Expand Up @@ -652,3 +654,5 @@ inline char32_t cpp::encoding::Utf16::codepoint(const cpp::marshal::View<uint8_t
return static_cast<char32_t>(first);
}
}

#endif
6 changes: 5 additions & 1 deletion src/hx/thread/Scratch.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <hxcpp.h>

#if (HXCPP_API_LEVEL>=500)
#include <hx/thread/Scratch.hpp>
#include "ThreadImpl.hpp"

Expand Down Expand Up @@ -71,4 +73,6 @@ hx::thread::Scratch& hx::thread::Scratch::operator=(const Scratch& _other)
}

return *this;
}
}

#endif
Loading