float VFSPlugin_LWO::ReadFloat(void) { float f; memcpy(&f,&m_buffer[m_offset],sizeof(float)); m_offset+=sizeof(float); ReverseByteOrder((char *)&f,sizeof(float),1); return f; }
typename enable_if<is_pod<T>::value, ReverseMapVisitor &>::type operator()( T & val, char const * /* name */) { T * valPtr = reinterpret_cast<T *>(m_cur); *valPtr = ReverseByteOrder(*valPtr); val = *valPtr; m_cur = Align8Ptr(m_cur + sizeof(T)); return *this; }
short VFSPlugin_LWO::ReadShort(void) { short s; memcpy(&s,&m_buffer[m_offset],sizeof(short)); m_offset+=sizeof(short); ReverseByteOrder((char *)&s,sizeof(short),1); return s; }
//===================================================== // THESE METHODS DO MISC TASKS REQUIRED BY THE FORMAT // TO PRODUCE VALID MESHES //===================================================== long VFSPlugin_LWO::ReadLong(void) { long l; memcpy(&l,&m_buffer[m_offset],sizeof(long)); m_offset+=sizeof(long); ReverseByteOrder((char *)&l,sizeof(long),1); return l; }
ReverseMapVisitor & operator()(succinct::mapper::mappable_vector<T> & vec, char const * /* name */) { vec.clear(); (*this)(vec.m_size, "size"); T * data = reinterpret_cast<T *>(m_cur); for (uint64_t i = 0; i < vec.m_size; ++i) data[i] = ReverseByteOrder(data[i]); vec.m_data = data; m_cur = Align8Ptr(m_cur + vec.m_size * sizeof(T)); return *this; }
int main(void) { static uint32_t testcase[] = { 0x12345678, 0x0000FFFF, 0x00FF00FF } ; InitializeHardware(HEADER, PROJECT_NAME) ; for (;;) { int k ; for (k = 0; k < ENTRIES(testcase); k++) { uint32_t word = testcase[k] ; uint32_t result, answer = REV(word) ; uint32_t before, after, cycles ; before = GetClockCycleCount() ; result = ReverseByteOrder(word) ; after = GetClockCycleCount() ; cycles = after - before ; printf(" Test Case %d: %08X (hex)\n", k+1, (unsigned) word) ; printf("Correct Result: %08X\n", (unsigned) answer) ; printf(" Your Result: %08X", (unsigned) result) ; if (result != answer) printf(" %s", ERROR_FLAG) ; printf("\n") ; printf(" Clock Cycles: %lu\n\n", cycles) ; WaitForPushButton() ; } printf("Press button to start over.\n") ; WaitForPushButton() ; ClearDisplay() ; } }
SrtmTile::THeight SrtmTile::GetHeight(ms::LatLon const & coord) { if (!IsValid()) return kInvalidHeight; double ln = coord.lon - static_cast<int>(coord.lon); if (ln < 0) ln += 1; double lt = coord.lat - static_cast<int>(coord.lat); if (lt < 0) lt += 1; lt = 1 - lt; // from North to South size_t const row = kArcSecondsInDegree * lt; size_t const col = kArcSecondsInDegree * ln; size_t const ix = row * (kArcSecondsInDegree + 1) + col; if (ix >= Size()) return kInvalidHeight; return ReverseByteOrder(Data()[ix]); }