diff --git a/src/Makefile b/src/Makefile index cf16a70..4206740 100644 --- a/src/Makefile +++ b/src/Makefile @@ -62,6 +62,7 @@ LIBRARY = pvxs LIB_SRCS += log.cpp LIB_SRCS += unittest.cpp LIB_SRCS += util.cpp +LIB_SRCS += sharedarray.cpp LIB_SRCS += bitmask.cpp LIB_SRCS += type.cpp LIB_SRCS += data.cpp diff --git a/src/sharedarray.cpp b/src/sharedarray.cpp new file mode 100644 index 0000000..183bc5f --- /dev/null +++ b/src/sharedarray.cpp @@ -0,0 +1,95 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + + +#include +#include "utilpvt.h" + +namespace pvxs { + +std::ostream& operator<<(std::ostream& strm, ArrayType code) +{ + switch(code) { +#define CASE(CODE) case ArrayType::CODE : strm<<#CODE; break + CASE(Null); + CASE(Bool); + CASE(UInt8); + CASE(UInt16); + CASE(UInt32); + CASE(UInt64); + CASE(Int8); + CASE(Int16); + CASE(Int32); + CASE(Int64); + CASE(Float32); + CASE(Float64); + CASE(Value); +#undef CASE + default: + strm<<"<\?\?\?>"; + } + return strm; +} + +namespace detail { + +namespace { +template +void showArr(std::ostream& strm, const void* raw, size_t count, size_t limit) +{ + auto base = reinterpret_cast(raw); + + if(limit==0) + limit=size_t(-1); + + strm<<"{"<limit) { + strm<<"..."; + break; + } + strm<(strm, lim._base, lim._count, lim._limit); break + CASE(Bool, bool); + CASE(UInt8, uint8_t); + CASE(UInt16, uint16_t); + CASE(UInt32, uint32_t); + CASE(UInt64, uint64_t); + CASE(Int8, int8_t); + CASE(Int16, int16_t); + CASE(Int32, int32_t); + CASE(Int64, int64_t); + CASE(Float32, float); + CASE(Float64, double); + CASE(String, std::string); +#undef CASE + case ArrayType::Null: + strm<<"{\?}[]"; + break; + default: + strm<<"[\?\?\?]"; + } + return strm; +} + +void _throw_bad_cast(ArrayType from, ArrayType to) +{ + throw std::logic_error(SB()<<"Unable to cast array from "<"; - } - return strm; -} - namespace detail { -namespace { -template -void showArr(std::ostream& strm, const void* raw, size_t count, size_t limit) -{ - auto base = reinterpret_cast(raw); - - if(limit==0) - limit=size_t(-1); - - strm<<"{"<limit) { - strm<<"..."; - break; - } - strm<(strm, lim._base, lim._count, lim._limit); break - CASE(Bool, bool); - CASE(UInt8, uint8_t); - CASE(UInt16, uint16_t); - CASE(UInt32, uint32_t); - CASE(UInt64, uint64_t); - CASE(Int8, int8_t); - CASE(Int16, int16_t); - CASE(Int32, int32_t); - CASE(Int64, int64_t); - CASE(Float32, float); - CASE(Float64, double); - CASE(String, std::string); -#undef CASE - case ArrayType::Null: - strm<<"{\?}[]"; - break; - default: - strm<<"[\?\?\?]"; - } - return strm; -} - -void _throw_bad_cast(ArrayType from, ArrayType to) -{ - throw std::logic_error(SB()<<"Unable to cast array from "<