36 const size_t capacity,
bool doConversion,
bool doScaling ) :
37 destImageFile_( destImageFile ), pathName_( pathName ), capacity_( capacity ), doConversion_( doConversion ),
38 doScaling_( doScaling )
44 static_assert( std::is_integral<T>::value || std::is_floating_point<T>::value,
45 "Integral or floating point required." );
47 base_ =
reinterpret_cast<char *
>(
base );
52 if ( std::is_same<T, int8_t>::value )
56 else if ( std::is_same<T, uint8_t>::value )
60 else if ( std::is_same<T, int16_t>::value )
64 else if ( std::is_same<T, uint16_t>::value )
68 else if ( std::is_same<T, int32_t>::value )
72 else if ( std::is_same<T, uint32_t>::value )
76 else if ( std::is_same<T, int64_t>::value )
80 else if ( std::is_same<T, bool>::value )
84 else if ( std::is_same<T, float>::value )
88 else if ( std::is_same<T, double>::value )
96 template void SourceDestBufferImpl::setTypeInfo<int8_t>( int8_t *base,
size_t stride );
97 template void SourceDestBufferImpl::setTypeInfo<uint8_t>( uint8_t *base,
size_t stride );
98 template void SourceDestBufferImpl::setTypeInfo<int16_t>( int16_t *base,
size_t stride );
99 template void SourceDestBufferImpl::setTypeInfo<uint16_t>( uint16_t *base,
size_t stride );
100 template void SourceDestBufferImpl::setTypeInfo<int32_t>( int32_t *base,
size_t stride );
101 template void SourceDestBufferImpl::setTypeInfo<uint32_t>( uint32_t *base,
size_t stride );
102 template void SourceDestBufferImpl::setTypeInfo<int64_t>( int64_t *base,
size_t stride );
103 template void SourceDestBufferImpl::setTypeInfo<bool>(
bool *base,
size_t stride );
104 template void SourceDestBufferImpl::setTypeInfo<float>(
float *base,
size_t stride );
105 template void SourceDestBufferImpl::setTypeInfo<double>(
double *base,
size_t stride );
108 std::vector<ustring> *b ) :
109 destImageFile_( destImageFile ), pathName_( pathName ), memoryRepresentation_(
E57_USTRING ), ustrings_( b )
119 capacity_ = b->size();
128 template <
typename T>
void SourceDestBufferImpl::_setNextReal( T inValue )
130 static_assert( std::is_same<T, double>::value || std::is_same<T, float>::value,
131 "_setNextReal() requires float or double type" );
136 if ( nextIndex_ >= capacity_ )
143 char *p = &base_[nextIndex_ * stride_];
145 switch ( memoryRepresentation_ )
148 if ( !doConversion_ )
154 if ( inValue < E57_INT8_MIN || E57_INT8_MAX < inValue )
157 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
159 *
reinterpret_cast<int8_t *
>( p ) =
static_cast<int8_t
>( inValue );
162 if ( !doConversion_ )
166 if ( inValue < E57_UINT8_MIN || E57_UINT8_MAX < inValue )
169 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
171 *
reinterpret_cast<uint8_t *
>( p ) =
static_cast<uint8_t
>( inValue );
174 if ( !doConversion_ )
178 if ( inValue < E57_INT16_MIN || E57_INT16_MAX < inValue )
181 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
183 *
reinterpret_cast<int16_t *
>( p ) =
static_cast<int16_t
>( inValue );
186 if ( !doConversion_ )
190 if ( inValue < E57_UINT16_MIN || E57_UINT16_MAX < inValue )
193 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
195 *
reinterpret_cast<uint16_t *
>( p ) =
static_cast<uint16_t
>( inValue );
198 if ( !doConversion_ )
202 if ( inValue < E57_INT32_MIN || E57_INT32_MAX < inValue )
205 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
207 *
reinterpret_cast<int32_t *
>( p ) =
static_cast<int32_t
>( inValue );
210 if ( !doConversion_ )
214 if ( inValue < E57_UINT32_MIN || E57_UINT32_MAX < inValue )
217 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
219 *
reinterpret_cast<uint32_t *
>( p ) =
static_cast<uint32_t
>( inValue );
222 if ( !doConversion_ )
226 if ( inValue < E57_INT64_MIN || E57_INT64_MAX < inValue )
229 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
231 *
reinterpret_cast<int64_t *
>( p ) =
static_cast<int64_t
>( inValue );
234 if ( !doConversion_ )
238 *
reinterpret_cast<bool *
>( p ) = ( inValue ?
false :
true );
241 if ( std::is_same<T, double>::value )
246 if ( inValue < E57_DOUBLE_MIN || E57_DOUBLE_MAX < inValue )
249 "pathName=" + pathName_ +
" value=" +
toString( inValue ) );
251 *
reinterpret_cast<float *
>( p ) =
static_cast<float>( inValue );
257 #pragma warning( disable : 4244 )
258 *
reinterpret_cast<float *
>( p ) = inValue;
259 #pragma warning( default : 4244 )
261 *
reinterpret_cast<float *
>( p ) = inValue;
267 *
reinterpret_cast<double *
>( p ) =
static_cast<double>( inValue );
276 void SourceDestBufferImpl::checkState_()
const
289 imf->pathNameCheckWellFormed( pathName_ );
293 if ( base_ ==
nullptr )
306 if ( ustrings_ ==
nullptr )
318 if ( nextIndex_ >= capacity_ )
325 char *p = &base_[nextIndex_ * stride_];
327 switch ( memoryRepresentation_ )
330 value =
static_cast<int64_t
>( *
reinterpret_cast<int8_t *
>( p ) );
333 value =
static_cast<int64_t
>( *
reinterpret_cast<uint8_t *
>( p ) );
336 value =
static_cast<int64_t
>( *
reinterpret_cast<int16_t *
>( p ) );
339 value =
static_cast<int64_t
>( *
reinterpret_cast<uint16_t *
>( p ) );
342 value =
static_cast<int64_t
>( *
reinterpret_cast<int32_t *
>( p ) );
345 value =
static_cast<int64_t
>( *
reinterpret_cast<uint32_t *
>( p ) );
348 value = *
reinterpret_cast<int64_t *
>( p );
351 if ( !doConversion_ )
356 value = ( *
reinterpret_cast<bool *
>( p ) ) ? 1 : 0;
359 if ( !doConversion_ )
364 value =
static_cast<int64_t
>( *
reinterpret_cast<float *
>( p ) );
367 if ( !doConversion_ )
372 value =
static_cast<int64_t
>( *
reinterpret_cast<double *
>( p ) );
406 if ( nextIndex_ >= capacity_ )
413 char *p = &base_[nextIndex_ * stride_];
414 double doubleRawValue;
415 switch ( memoryRepresentation_ )
420 doubleRawValue =
floor( ( *
reinterpret_cast<int8_t *
>( p ) -
offset ) / scale + 0.5 );
425 doubleRawValue =
floor( ( *
reinterpret_cast<uint8_t *
>( p ) -
offset ) / scale + 0.5 );
430 doubleRawValue =
floor( ( *
reinterpret_cast<int16_t *
>( p ) -
offset ) / scale + 0.5 );
435 doubleRawValue =
floor( ( *
reinterpret_cast<uint16_t *
>( p ) -
offset ) / scale + 0.5 );
440 doubleRawValue =
floor( ( *
reinterpret_cast<int32_t *
>( p ) -
offset ) / scale + 0.5 );
445 doubleRawValue =
floor( ( *
reinterpret_cast<uint32_t *
>( p ) -
offset ) / scale + 0.5 );
450 doubleRawValue =
floor( ( *
reinterpret_cast<int64_t *
>( p ) -
offset ) / scale + 0.5 );
453 if ( *
reinterpret_cast<bool *
>( p ) )
455 doubleRawValue =
floor( ( 1 -
offset ) / scale + 0.5 );
459 doubleRawValue =
floor( ( 0 -
offset ) / scale + 0.5 );
463 if ( !doConversion_ )
471 doubleRawValue =
floor( ( *
reinterpret_cast<float *
>( p ) -
offset ) / scale + 0.5 );
474 if ( !doConversion_ )
482 doubleRawValue =
floor( ( *
reinterpret_cast<double *
>( p ) -
offset ) / scale + 0.5 );
490 if ( doubleRawValue < E57_INT64_MIN || E57_INT64_MAX < doubleRawValue )
493 "pathName=" + pathName_ +
" value=" +
toString( doubleRawValue ) );
496 auto rawValue =
static_cast<int64_t
>( doubleRawValue );
507 if ( nextIndex_ >= capacity_ )
514 char *p = &base_[nextIndex_ * stride_];
516 switch ( memoryRepresentation_ )
519 if ( !doConversion_ )
523 value =
static_cast<float>( *
reinterpret_cast<int8_t *
>( p ) );
526 if ( !doConversion_ )
530 value =
static_cast<float>( *
reinterpret_cast<uint8_t *
>( p ) );
533 if ( !doConversion_ )
537 value =
static_cast<float>( *
reinterpret_cast<int16_t *
>( p ) );
540 if ( !doConversion_ )
544 value =
static_cast<float>( *
reinterpret_cast<uint16_t *
>( p ) );
547 if ( !doConversion_ )
551 value =
static_cast<float>( *
reinterpret_cast<int32_t *
>( p ) );
554 if ( !doConversion_ )
558 value =
static_cast<float>( *
reinterpret_cast<uint32_t *
>( p ) );
561 if ( !doConversion_ )
565 value =
static_cast<float>( *
reinterpret_cast<int64_t *
>( p ) );
568 if ( !doConversion_ )
574 value = ( *
reinterpret_cast<bool *
>( p ) ) ? 1.0F : 0.0F;
577 value = *
reinterpret_cast<float *
>( p );
583 double d = *
reinterpret_cast<double *
>( p );
586 if ( d < E57_DOUBLE_MIN || E57_DOUBLE_MAX < d )
590 value =
static_cast<float>( d );
607 if ( nextIndex_ >= capacity_ )
614 char *p = &base_[nextIndex_ * stride_];
616 switch ( memoryRepresentation_ )
619 if ( !doConversion_ )
623 value =
static_cast<double>( *
reinterpret_cast<int8_t *
>( p ) );
626 if ( !doConversion_ )
630 value =
static_cast<double>( *
reinterpret_cast<uint8_t *
>( p ) );
633 if ( !doConversion_ )
637 value =
static_cast<double>( *
reinterpret_cast<int16_t *
>( p ) );
640 if ( !doConversion_ )
644 value =
static_cast<double>( *
reinterpret_cast<uint16_t *
>( p ) );
647 if ( !doConversion_ )
651 value =
static_cast<double>( *
reinterpret_cast<int32_t *
>( p ) );
654 if ( !doConversion_ )
658 value =
static_cast<double>( *
reinterpret_cast<uint32_t *
>( p ) );
661 if ( !doConversion_ )
665 value =
static_cast<double>( *
reinterpret_cast<int64_t *
>( p ) );
668 if ( !doConversion_ )
673 value = ( *
reinterpret_cast<bool *
>( p ) ) ? 1.0 : 0.0;
676 value =
static_cast<double>( *
reinterpret_cast<float *
>( p ) );
679 value = *
reinterpret_cast<double *
>( p );
701 if ( nextIndex_ >= capacity_ )
707 return ( ( *ustrings_ )[nextIndex_++] );
715 if ( nextIndex_ >= capacity_ )
722 char *p = &base_[nextIndex_ * stride_];
724 switch ( memoryRepresentation_ )
727 if ( value < E57_INT8_MIN || E57_INT8_MAX < value )
730 "pathName=" + pathName_ +
" value=" +
toString( value ) );
732 *
reinterpret_cast<int8_t *
>( p ) =
static_cast<int8_t
>( value );
735 if ( value < E57_UINT8_MIN || E57_UINT8_MAX < value )
738 "pathName=" + pathName_ +
" value=" +
toString( value ) );
740 *
reinterpret_cast<uint8_t *
>( p ) =
static_cast<uint8_t
>( value );
743 if ( value < E57_INT16_MIN || E57_INT16_MAX < value )
746 "pathName=" + pathName_ +
" value=" +
toString( value ) );
748 *
reinterpret_cast<int16_t *
>( p ) =
static_cast<int16_t
>( value );
751 if ( value < E57_UINT16_MIN || E57_UINT16_MAX < value )
754 "pathName=" + pathName_ +
" value=" +
toString( value ) );
756 *
reinterpret_cast<uint16_t *
>( p ) =
static_cast<uint16_t
>( value );
759 if ( value < E57_INT32_MIN || E57_INT32_MAX < value )
762 "pathName=" + pathName_ +
" value=" +
toString( value ) );
764 *
reinterpret_cast<int32_t *
>( p ) =
static_cast<int32_t
>( value );
767 if ( value < E57_UINT32_MIN || E57_UINT32_MAX < value )
770 "pathName=" + pathName_ +
" value=" +
toString( value ) );
772 *
reinterpret_cast<uint32_t *
>( p ) =
static_cast<uint32_t
>( value );
775 *
reinterpret_cast<int64_t *
>( p ) =
static_cast<int64_t
>( value );
778 *
reinterpret_cast<bool *
>( p ) = ( value ?
false :
true );
781 if ( !doConversion_ )
786 *
reinterpret_cast<float *
>( p ) =
static_cast<float>( value );
789 if ( !doConversion_ )
793 *
reinterpret_cast<double *
>( p ) =
static_cast<double>( value );
820 if ( nextIndex_ >= capacity_ )
827 char *p = &base_[nextIndex_ * stride_];
835 scaledValue = value * scale +
offset;
842 scaledValue =
floor( value * scale +
offset + 0.5 );
845 switch ( memoryRepresentation_ )
848 if ( scaledValue < E57_INT8_MIN || E57_INT8_MAX < scaledValue )
851 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
853 *
reinterpret_cast<int8_t *
>( p ) =
static_cast<int8_t
>( scaledValue );
856 if ( scaledValue < E57_UINT8_MIN || E57_UINT8_MAX < scaledValue )
859 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
861 *
reinterpret_cast<uint8_t *
>( p ) =
static_cast<uint8_t
>( scaledValue );
864 if ( scaledValue < E57_INT16_MIN || E57_INT16_MAX < scaledValue )
867 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
869 *
reinterpret_cast<int16_t *
>( p ) =
static_cast<int16_t
>( scaledValue );
872 if ( scaledValue < E57_UINT16_MIN || E57_UINT16_MAX < scaledValue )
875 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
877 *
reinterpret_cast<uint16_t *
>( p ) =
static_cast<uint16_t
>( scaledValue );
880 if ( scaledValue < E57_INT32_MIN || E57_INT32_MAX < scaledValue )
883 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
885 *
reinterpret_cast<int32_t *
>( p ) =
static_cast<int32_t
>( scaledValue );
888 if ( scaledValue < E57_UINT32_MIN || E57_UINT32_MAX < scaledValue )
891 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
893 *
reinterpret_cast<uint32_t *
>( p ) =
static_cast<uint32_t
>( scaledValue );
896 *
reinterpret_cast<int64_t *
>( p ) =
static_cast<int64_t
>( scaledValue );
899 *
reinterpret_cast<bool *
>( p ) = ( scaledValue ?
false :
true );
902 if ( !doConversion_ )
908 if ( scaledValue < E57_DOUBLE_MIN || E57_DOUBLE_MAX < scaledValue )
911 "pathName=" + pathName_ +
" scaledValue=" +
toString( scaledValue ) );
913 *
reinterpret_cast<float *
>( p ) =
static_cast<float>( scaledValue );
916 if ( !doConversion_ )
920 *
reinterpret_cast<double *
>( p ) = scaledValue;
931 _setNextReal( value );
936 _setNextReal( value );
949 if ( nextIndex_ >= capacity_ )
955 ( *ustrings_ )[nextIndex_] = value;
961 if ( pathName_ != newBuf->pathName() )
964 "pathName=" + pathName_ +
" newPathName=" + newBuf->pathName() );
966 if ( memoryRepresentation_ != newBuf->memoryRepresentation() )
969 "memoryRepresentation=" +
toString( memoryRepresentation_ ) +
970 " newMemoryType=" +
toString( newBuf->memoryRepresentation() ) );
972 if ( capacity_ != newBuf->capacity() )
975 "capacity=" +
toString( capacity_ ) +
" newCapacity=" +
toString( newBuf->capacity() ) );
977 if ( doConversion_ != newBuf->doConversion() )
980 "doConversion=" +
toString( doConversion_ ) +
981 "newDoConversion=" +
toString( newBuf->doConversion() ) );
983 if ( doConversion_ != newBuf->doConversion() )
986 "doConversion=" +
toString( doConversion_ ) +
987 " newDoConversion=" +
toString( newBuf->doConversion() ) );
989 if ( stride_ != newBuf->stride() )
992 "stride=" +
toString( stride_ ) +
" newStride=" +
toString( newBuf->stride() ) );
1002 os <<
space( indent ) <<
"memoryRepresentation: ";
1003 switch ( memoryRepresentation_ )
1042 os <<
space( indent ) <<
"base: " <<
static_cast<const void *
>( base_ ) <<
std::endl;
1043 os <<
space( indent ) <<
"ustrings: " <<
static_cast<const void *
>( ustrings_ ) <<
std::endl;
1045 os <<
space( indent ) <<
"doConversion: " << doConversion_ <<
std::endl;
1046 os <<
space( indent ) <<
"doScaling: " << doScaling_ <<
std::endl;
1048 os <<
space( indent ) <<
"nextIndex: " << nextIndex_ <<
std::endl;
void setNextString(const ustring &value)
void setTypeInfo(T *base, size_t stride=sizeof(T))
void setNextInt64(int64_t value)
void setNextFloat(float value)
void dump(int indent=0, std::ostream &os=std::cout)
void setNextDouble(double value)
SourceDestBufferImpl(ImageFileImplWeakPtr destImageFile, const ustring &pathName, const size_t capacity, bool doConversion=false, bool doScaling=false)
void checkCompatible(const std::shared_ptr< SourceDestBufferImpl > &newBuf) const
ImageFileImplWeakPtr destImageFile() const
QTextStream & endl(QTextStream &stream)
MiniVec< float, N > floor(const MiniVec< float, N > &a)
std::weak_ptr< class ImageFileImpl > ImageFileImplWeakPtr
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
@ E57_ERROR_BUFFERS_NOT_COMPATIBLE
SourceDestBuffers not compatible with previously given ones.
@ E57_ERROR_CONVERSION_REQUIRED
conversion required to assign element value, but not requested
@ E57_ERROR_INTERNAL
An unrecoverable inconsistent internal state was detected.
@ E57_ERROR_REAL64_TOO_LARGE
a 64 bit IEEE float was too large to store in a 32 bit IEEE float
@ E57_ERROR_IMAGEFILE_NOT_OPEN
destImageFile is no longer open
@ E57_ERROR_EXPECTING_NUMERIC
Expecting numeric representation in user's buffer, found ustring.
@ E57_ERROR_VALUE_NOT_REPRESENTABLE
a value could not be represented in the requested type
@ E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE
@ E57_ERROR_BAD_BUFFER
bad SourceDestBuffer
@ E57_ERROR_EXPECTING_USTRING
Expecting string representation in user's buffer, found numeric.
std::string ustring
UTF-8 encodeded Unicode string.
@ E57_USTRING
Unicode UTF-8 std::string.
@ E57_UINT32
32 bit unsigned integer
@ E57_INT32
32 bit signed integer
@ E57_UINT8
8 bit unsigned integer
@ E57_INT64
64 bit signed integer
@ E57_INT8
8 bit signed integer
@ E57_REAL32
C++ float type.
@ E57_UINT16
16 bit unsigned integer
@ E57_BOOL
C++ boolean type.
@ E57_INT16
16 bit signed integer
@ E57_REAL64
C++ double type.
std::string toString(T x)
std::string space(size_t n)