| 161 | } |
| 162 | |
| 163 | XMLSize_t E57FileInputStream::readBytes( XMLByte *const toFill, const XMLSize_t maxToRead ) |
| 164 | { |
| 165 | if ( logicalPosition_ > logicalStart_ + logicalLength_ ) |
| 166 | { |
| 167 | return ( 0 ); |
| 168 | } |
| 169 | |
| 170 | int64_t available = logicalStart_ + logicalLength_ - logicalPosition_; |
| 171 | if ( available <= 0 ) |
| 172 | { |
| 173 | return ( 0 ); |
| 174 | } |
| 175 | |
| 176 | size_t maxToRead_size = maxToRead; |
| 177 | |
| 178 | // Be careful if size_t is smaller than int64_t |
| 179 | size_t available_size; |
| 180 | |
| 181 | // Assign to var to avoid MSVC warning |
| 182 | // This section can be simplified in C++17 using a "constexpr if". |
| 183 | constexpr bool cSizeCheck = ( sizeof( size_t ) >= sizeof( int64_t ) ); |
| 184 | if ( cSizeCheck ) |
| 185 | { |
| 186 | // size_t is at least as big as int64_t |
| 187 | available_size = static_cast<size_t>( available ); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | // size_t is smaller than int64_t, Calc max that size_t can hold |
| 192 | const int64_t size_max = std::numeric_limits<size_t>::max(); |
| 193 | |
| 194 | // read smaller of size_max, available |
| 195 | //??? redo |
| 196 | if ( size_max < available ) |
| 197 | { |
| 198 | available_size = static_cast<size_t>( size_max ); |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | available_size = static_cast<size_t>( available ); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | size_t readCount = std::min( maxToRead_size, available_size ); |
| 207 | |
| 208 | cf_->seek( logicalPosition_ ); |
| 209 | cf_->read( reinterpret_cast<char *>( toFill ), readCount ); //??? cast ok? |
| 210 | logicalPosition_ += readCount; |
| 211 | return ( readCount ); |
| 212 | } |
| 213 | |
| 214 | //============================================================================= |
| 215 | // E57XmlFileInputSource |