sharedArray formatting with size limit.

This commit is contained in:
Michael Davidsaver
2020-03-19 16:39:15 -07:00
parent 3c937f233c
commit 078e0ea69f
6 changed files with 113 additions and 100 deletions
+49 -46
View File
@@ -73,54 +73,57 @@ std::ostream& operator<<(std::ostream& strm, ArrayType code)
return strm;
}
std::ostream& operator<<(std::ostream& strm, const shared_array<const void>& arr)
{
switch(arr.original_type()) {
case ArrayType::Null: strm<<"[null]"; break;
#define CASE(CODE, Type) case ArrayType::CODE: strm<<arr.castTo<const Type>(); 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);
CASE(Value, Value);
#undef CASE
}
return strm;
}
std::ostream& operator<<(std::ostream& strm, const shared_array<void>& arr)
{
switch(arr.original_type()) {
case ArrayType::Null: strm<<"[null]"; break;
#define CASE(CODE, Type) case ArrayType::CODE: strm<<arr.castTo<Type>(); 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);
CASE(Value, Value);
#undef CASE
}
return strm;
}
namespace detail {
namespace {
template<typename E>
void showArr(std::ostream& strm, const void* raw, size_t count, size_t limit)
{
auto base = reinterpret_cast<const E*>(raw);
if(limit==0)
limit=size_t(-1);
strm<<"{"<<count<<"}[";
for(auto i : range(count)) {
if(i!=0)
strm<<", ";
if(i>limit) {
strm<<"...";
break;
}
strm<<base[i];
}
strm<<']';
}
} // namespace
std::ostream& operator<<(std::ostream& strm, const Limiter& lim)
{
switch(lim._type) {
#define CASE(CODE, Type) case ArrayType::CODE: showArr<Type>(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;
}
Escaper::Escaper(const char* v)
:val(v)
,count(v ? strlen(v) : 0)