Skip to content

Commit

Permalink
Merge pull request #24 from elsid/3.6_fix_endl
Browse files Browse the repository at this point in the history
Do not rely on std::endl function address and fix warnings
  • Loading branch information
psi29a authored Mar 2, 2024
2 parents 68c5c57 + f976e1c commit 675feae
Show file tree
Hide file tree
Showing 100 changed files with 471 additions and 480 deletions.
8 changes: 4 additions & 4 deletions examples/osgframerenderer/CaptureSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ static bool writeEventHandlers( osgDB::OutputStream& os, const gsc::CaptureSetti
{
const gsc::CaptureSettings::EventHandlers& pl = cs.getEventHandlers();
unsigned int size = pl.size();
os << size << os.BEGIN_BRACKET << std::endl;
os << size << os.BEGIN_BRACKET << osgDB::OutputStream::Endl{};
for ( unsigned int i=0; i<size; ++i )
{
os << pl[i].get();
}
os << os.END_BRACKET << std::endl;
os << os.END_BRACKET << osgDB::OutputStream::Endl{};
return true;
}

Expand All @@ -135,12 +135,12 @@ static bool writeProperties( osgDB::OutputStream& os, const gsc::CaptureSettings
{
const gsc::CaptureSettings::Properties& pl = cs.getProperties();
unsigned int size = pl.size();
os << size << os.BEGIN_BRACKET << std::endl;
os << size << os.BEGIN_BRACKET << osgDB::OutputStream::Endl{};
for ( unsigned int i=0; i<size; ++i )
{
os << pl[i].get();
}
os << os.END_BRACKET << std::endl;
os << os.END_BRACKET << osgDB::OutputStream::Endl{};
return true;
}

Expand Down
4 changes: 0 additions & 4 deletions include/osg/Plane
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,13 @@ class OSG_EXPORT Plane

int noAbove = 0;
int noBelow = 0;
int noOn = 0;
for(std::vector<Vec3f>::const_iterator itr=vertices.begin();
itr != vertices.end();
++itr)
{
float d = distance(*itr);
if (d>0.0f) ++noAbove;
else if (d<0.0f) ++noBelow;
else ++noOn;
}

if (noAbove>0)
Expand All @@ -270,15 +268,13 @@ class OSG_EXPORT Plane

int noAbove = 0;
int noBelow = 0;
int noOn = 0;
for(std::vector<Vec3d>::const_iterator itr=vertices.begin();
itr != vertices.end();
++itr)
{
double d = distance(*itr);
if (d>0.0) ++noAbove;
else if (d<0.0) ++noBelow;
else ++noOn;
}

if (noAbove>0)
Expand Down
3 changes: 3 additions & 0 deletions include/osgDB/OutputStream
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public:
WRITE_EXTERNAL_FILE /*!< Write Image::data() to disk and use it as external file */
};

struct Endl {};

OutputStream( const osgDB::Options* options );
virtual ~OutputStream();

Expand Down Expand Up @@ -108,6 +110,7 @@ public:
OutputStream& operator<<( const char* s ) { _out->writeString(s); return *this; }
OutputStream& operator<<( std::ostream& (*fn)(std::ostream&) ) { _out->writeStream(fn); return *this; }
OutputStream& operator<<( std::ios_base& (*fn)(std::ios_base&) ) { _out->writeBase(fn); return *this; }
OutputStream& operator<<( Endl ) { _out->writeEndl(); return *this; }

OutputStream& operator<<( const ObjectGLenum& value ) { _out->writeGLenum(value); return *this; }
OutputStream& operator<<( const ObjectProperty& prop ) { _out->writeProperty(prop); return *this; }
Expand Down
54 changes: 27 additions & 27 deletions include/osgDB/Serializer
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public:
if ( _useHex ) { os << std::hex << std::showbase; }
os << value;
if ( _useHex ) os << std::dec << std::noshowbase;
os << std::endl;
os << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -368,7 +368,7 @@ public:
}
else if ( ParentType::_defaultValue!=value )
{
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
os << os.PROPERTY((ParentType::_name).c_str()) << value << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ public:
}
else if ( ParentType::_defaultValue!=value )
{
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
os << os.PROPERTY((ParentType::_name).c_str()) << value << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -487,7 +487,7 @@ public:
}
else if ( ParentType::_defaultValue!=value )
{
os << os.PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl;
os << os.PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ public:
{
os << os.PROPERTY((ParentType::_name).c_str());
os.writeWrappedString( value );
os << std::endl;
os << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -614,11 +614,11 @@ public:
os << os.PROPERTY(_name.c_str()) << hasObject;
if ( hasObject )
{
os << os.BEGIN_BRACKET << std::endl;
os << os.BEGIN_BRACKET << OutputStream::Endl{};
os.writeObject( value );
os << os.END_BRACKET;
}
os << std::endl;
os << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -691,11 +691,11 @@ public:
os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
if ( hasObject )
{
os << os.BEGIN_BRACKET << std::endl;
os << os.BEGIN_BRACKET << OutputStream::Endl{};
os.writeImage( value );
os << os.END_BRACKET;
}
os << std::endl;
os << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -756,7 +756,7 @@ public:
}
else if ( ParentType::_defaultValue!=value )
{
os << os.PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl;
os << os.PROPERTY((ParentType::_name).c_str()) << getString(value) << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -836,14 +836,14 @@ public:
}
else if ( size>0 )
{
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << OutputStream::Endl{};
for ( ConstIterator itr=list.begin();
itr!=list.end(); ++itr )
{
os << (*itr);
}
os << std::endl;
os << os.END_BRACKET << std::endl;
os << OutputStream::Endl{};
os << os.END_BRACKET << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ public:
}
else if ( size>0 )
{
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << OutputStream::Endl{};
if (_numElementsOnRow==0)
{
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
Expand All @@ -1023,7 +1023,7 @@ public:
{
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
{
os << (*itr); os << std::endl;
os << (*itr); os << OutputStream::Endl{};
}
}
else
Expand All @@ -1032,12 +1032,12 @@ public:
for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
{
os << (*itr);
if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
if (i==0) { os << OutputStream::Endl{}; i = _numElementsOnRow-1; }
else --i;
}
if (i!=_numElementsOnRow) os << std::endl;
if (i!=_numElementsOnRow) os << OutputStream::Endl{};
}
os << os.END_BRACKET << std::endl;
os << os.END_BRACKET << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -1165,7 +1165,7 @@ public:
}
else if ( size>0 )
{
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << OutputStream::Endl{};
if (_numElementsOnRow==0)
{
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
Expand All @@ -1177,7 +1177,7 @@ public:
{
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
{
os << (*itr); os << std::endl;
os << (*itr); os << OutputStream::Endl{};
}
}
else
Expand All @@ -1186,12 +1186,12 @@ public:
for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
{
os << (*itr);
if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
if (i==0) { os << OutputStream::Endl{}; i = _numElementsOnRow-1; }
else --i;
}
if (i!=_numElementsOnRow) os << std::endl;
if (i!=_numElementsOnRow) os << OutputStream::Endl{};
}
os << os.END_BRACKET << std::endl;
os << os.END_BRACKET << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -1431,12 +1431,12 @@ public:
}
else if ( size>0 )
{
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << OutputStream::Endl{};
for ( ConstIterator itr=map.begin(); itr!=map.end(); ++itr )
{
os << itr->first << itr->second; os << std::endl;
os << itr->first << itr->second; os << OutputStream::Endl{};
}
os << os.END_BRACKET << std::endl;
os << os.END_BRACKET << OutputStream::Endl{};
}
return true;
}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ public:
if ( !maskString.size() )
maskString = std::string("NONE|");
maskString.erase(maskString.size()-1,1);
os << maskString << std::endl; //remove last "|"
os << maskString << OutputStream::Endl{}; //remove last "|"
}
return true;
}
Expand Down
16 changes: 1 addition & 15 deletions include/osgDB/StreamOperator
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public:
virtual void writeString( const std::string& s ) = 0;
virtual void writeStream( std::ostream& (*fn)(std::ostream&) ) = 0;
virtual void writeBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
virtual void writeEndl() = 0;

virtual void writeGLenum( const ObjectGLenum& value ) = 0;
virtual void writeProperty( const ObjectProperty& prop ) = 0;
Expand All @@ -59,21 +60,6 @@ public:
virtual void flush() { _out->flush(); }

protected:
// Return true if the manipulator is std::endl
bool isEndl( std::ostream& (*fn)(std::ostream&) )
{
#if defined (__sun) || (defined _WIN32 && !defined OSG_LIBRARY_STATIC)
// What a mess, but solaris does not like taking the address below
// windows std::endl is a template with different adresses in different dll's
std::stringstream ss;
ss << fn;
std::string s = ss.str();
return !s.empty() && s[0] == '\n';
#else
return fn==static_cast<std::ostream& (*)(std::ostream&)>(std::endl);
#endif
}

std::ostream* _out;
osgDB::OutputStream* _outputStream;
bool _supportBinaryBrackets;
Expand Down
2 changes: 1 addition & 1 deletion src/osg/dxtctool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// dxtctool.cpp: implementation of DXTC Tools functions.
//
// Copyright (C) 2002 Tanguy Fautré.
// Copyright (C) 2002 Tanguy Fautré.
// For conditions of distribution and use,
// see copyright notice in dxtctool.h
//
Expand Down
2 changes: 1 addition & 1 deletion src/osg/dxtctool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 Tanguy Fautr.
// Copyright (C) 2002 Tanguy Fautré.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down
1 change: 1 addition & 0 deletions src/osgDB/ClassInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PropertyOutputIterator : public osgDB::OutputIterator
virtual void writeString( const std::string& s ) { _str.insert(_str.end(), s.begin(), s.end()); }
virtual void writeStream( std::ostream& (*)(std::ostream&) ) {}
virtual void writeBase( std::ios_base& (*)(std::ios_base&) ) {}
virtual void writeEndl() {}
virtual void writeGLenum( const osgDB::ObjectGLenum& value ) { writeInt(value.get()); }
virtual void writeProperty( const osgDB::ObjectProperty& prop ) { _propertyName = prop._name; }
virtual void writeMark( const osgDB::ObjectMark& mark ) { _markName = mark._name; }
Expand Down
Loading

0 comments on commit 675feae

Please sign in to comment.