mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 16:36:03 +08:00
Added experimental uni_type
This commit is contained in:
parent
3cbd432a29
commit
ab7fcbee64
@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
template <size_t Size_>
|
||||
class uni_type
|
||||
class mem_type
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr size_t Size = Size_;
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
uni_type(const uni_type& other)
|
||||
//***********************************
|
||||
template <size_t Other_Size>
|
||||
mem_type(const mem_type<Other_Size& other)
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "Other size is too large");
|
||||
|
||||
memcpy(buffer, other.buffer, Size_);
|
||||
}
|
||||
|
||||
@ -29,15 +31,17 @@ public:
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
operator T()
|
||||
operator T() const
|
||||
{
|
||||
return *reinterpret_cast<T*>(buffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
uni_type& operator =(const uni_type& rhs)
|
||||
template <size_t Other_Size>
|
||||
mem_type& operator =(const mem_type<Other_Size>& rhs)
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
|
||||
|
||||
memcpy(buffer, rhs.buffer, Size_);
|
||||
|
||||
return *this;
|
||||
@ -49,30 +53,46 @@ public:
|
||||
return Size;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
constexpr char* data() const
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char buffer[Size]
|
||||
};
|
||||
|
||||
template <size_t Size_>
|
||||
class uni_type_ptr
|
||||
class mem_type_ptr
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr size_t Size = Size_;
|
||||
|
||||
//***********************************
|
||||
uni_type_ptr()
|
||||
mem_type_ptr()
|
||||
: pbuffer(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************
|
||||
uni_type_ptr(void* pbuffer_)
|
||||
: pbuffer(reinterpret_cast<char*>(pbuffer))
|
||||
mem_type_ptr(char* pbuffer_)
|
||||
: pbuffer(pbuffer_)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <size_t Other_Size>
|
||||
mem_type_ptr(const mem_type_ptr<Other_Size& other, char* pbuffer_)
|
||||
: pbuffer(pbuffer_)
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "Other size is too large");
|
||||
|
||||
memcpy(buffer, other.buffer, Size_);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
T& get()
|
||||
@ -87,18 +107,36 @@ public:
|
||||
return *reinterpret_cast<T*>(pbuffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
operator T()
|
||||
operator T() const
|
||||
{
|
||||
return *reinterpret_cast<T*>(pbuffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <size_t Other_Size>
|
||||
mem_type_ptr& operator =(const mem_type_ptr<Other_Size>& rhs)
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
|
||||
|
||||
memcpy(pbuffer, rhs.pbuffer, Size_);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
constexpr size_t size() const
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
constexpr char* data() const
|
||||
{
|
||||
return pbuffer;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char* pbuffer;
|
||||
@ -1309,7 +1309,7 @@
|
||||
<ClInclude Include="..\..\include\etl\cumulative_moving_average.h" />
|
||||
<ClInclude Include="..\..\include\etl\delegate.h" />
|
||||
<ClInclude Include="..\..\include\etl\delegate_service.h" />
|
||||
<ClInclude Include="..\..\include\etl\experimental\uni_type.h" />
|
||||
<ClInclude Include="..\..\include\etl\experimental\mem_type.h" />
|
||||
<ClInclude Include="..\..\include\etl\file_error_numbers.h" />
|
||||
<ClInclude Include="..\..\include\etl\flags.h" />
|
||||
<ClInclude Include="..\..\include\etl\format_spec.h" />
|
||||
|
||||
@ -1110,7 +1110,7 @@
|
||||
<ClInclude Include="..\..\include\etl\private\variant_new.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\experimental\uni_type.h">
|
||||
<ClInclude Include="..\..\include\etl\experimental\mem_type.h">
|
||||
<Filter>ETL\Experimental</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user