Opened 6 years ago

Closed 6 years ago

#863 closed defect (fixed)

DEBUG_BYTEORDER_VALUES=1 does not build

Reported by: goatbar Owned by: geos-devel@…
Priority: minor Milestone: 3.6.3
Component: Default Version: 3.6.2
Severity: Annoyance Keywords: debugging
Cc:

Description

Missing includes and missing std::

Also, most other switches are #ifdef rather than #if, so maybe that should change too.

  • src/io/ByteOrderValues.cpp

    a b  
    2323#include <cstring>
    2424#include <cassert>
    2525
     26#if DEBUG_BYTEORDER_VALUES
     27#include <ios>
     28#include <iostream>
     29#endif
     30
    2631namespace geos {
    2732namespace io { // geos.io
    2833
     
    143148        int64 longValue;
    144149    std::memcpy(&longValue, &doubleValue, sizeof(double));
    145150#if DEBUG_BYTEORDER_VALUES
    146         cout<<"ByteOrderValues::putDouble("<<doubleValue<<
     151        std::cout<<"ByteOrderValues::putDouble("<<doubleValue<<
    147152                ", order:"<<byteOrder
    148                 <<") = "<<hex;
     153                <<") = "<<std::hex;
    149154        for (int i=0; i<8; i++)
    150                 cout<<"["<<(int)buf[i]<<"]";
    151         cout<<dec<<endl;
     155                std::cout<<"["<<(int)buf[i]<<"]";
     156        std::cout<<std::dec<<std::endl;
    152157#endif
    153158        putLong(longValue, buf, byteOrder);
    154159}

Change History (3)

comment:1 by goatbar, 6 years ago

I think there is still more that can be done to improve the eof checks, but here is what I ended up with after code review. I'll try to get the tests I've been working on out in the autotest2 tree in the next few days. I have more work to do for coverage.

namespace {

unsigned char ASCIIHexToUChar(char val)
{
        switch ( val )
        {
                case '0' :
                        return 0;
                case '1' :
                        return 1;
                case '2' :
                        return 2;
                case '3' :
                        return 3;
                case '4' :
                        return 4;
                case '5' :
                        return 5;
                case '6' :
                        return 6;
                case '7' :
                        return 7;
                case '8' :
                        return 8;
                case '9' :
                        return 9;
                case 'A' :
                case 'a' :
                        return 10;
                case 'B' :
                case 'b' :
                        return 11;
                case 'C' :
                case 'c' :
                        return 12;
                case 'D' :
                case 'd' :
                        return 13;
                case 'E' :
                case 'e' :
                        return 14;
                case 'F' :
                case 'f' :
                        return 15;
                default:
                        throw ParseException("Invalid HEX char");
        }
}

}  // namespace

// Must be an even number of characters in the istream.
// Throws a ParseException if there are an odd number of characters.
Geometry *
WKBReader::readHEX(istream &is)
{
        // setup input/output stream
        stringstream os(ios_base::binary|ios_base::in|ios_base::out);

        while( true )
        {
                const int input_high = is.get();
                if (input_high == char_traits<char>::eof())
                        break;

                const int input_low = is.get();
                if (input_low == char_traits<char>::eof())
                        throw ParseException("Premature end of HEX string");

                const char high = static_cast<char>(input_high);
                const char low = static_cast<char>(input_low);

                const unsigned char result_high = ASCIIHexToUChar(high);
                const unsigned char result_low = ASCIIHexToUChar(low);

                const unsigned char value =
                        static_cast<char>((result_high<<4) + result_low);

#if DEBUG_HEX_READER
        cout<<"HEX "<<high<<low<<" -> DEC "<<(int)value<<endl;
#endif
                // write the value to the output stream
                os << value;
        }

        // now call read to convert the geometry
        return this->read(os);
}

comment:3 by Kurt Schwehr <schwehr@…>, 6 years ago

Resolution: fixed
Status: newclosed

In 4101c61/git:

Fix building with DEBUG_BYTEORDER_VALUES=1 in ByteOrderValues.cpp

Add missing includes and missing std::

Fixes #863

Note: See TracTickets for help on using tickets.