Fix sstream/strstream (and config.h) compiler issues.

Code would not compile with HAVE_STRSTREAM defined.

Code would not compile without HAVE_CONFIG_H defined (unless
-DHAVE_STRSTREAM or -DHAVE_SSTREAM was specified).

Code would not compile with HAVE_CONFIG_H defined if config.h did not
also define HAVE_SSTREAM.

This patch moves annoying logic for sstream/strstream logic to it's
own file and fixes the above mentioned issues.

https://sourceforge.net/p/tclap/bugs/23/
This commit is contained in:
Daniel Aarno 2017-12-23 16:54:34 +01:00
parent d3ae484f7f
commit d2e5525760
4 changed files with 66 additions and 18 deletions

View File

@ -6,6 +6,7 @@
* *
* Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2003, Michael E. Smoot .
* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno .
* Copyright (c) 2017 Google Inc.
* All rights reserved. * All rights reserved.
* *
* See the file COPYING in the top directory of this distribution for * See the file COPYING in the top directory of this distribution for
@ -27,8 +28,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#else
#define HAVE_SSTREAM
#endif #endif
#include <string> #include <string>
@ -38,6 +37,8 @@
#include <iomanip> #include <iomanip>
#include <cstdio> #include <cstdio>
#include <tclap/sstream.h>
#if defined(HAVE_SSTREAM) #if defined(HAVE_SSTREAM)
#include <sstream> #include <sstream>
typedef std::istringstream istringstream; typedef std::istringstream istringstream;
@ -415,7 +416,7 @@ template<typename T> void
ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) ExtractValue(T &destVal, const std::string& strVal, ValueLike vl)
{ {
static_cast<void>(vl); // Avoid warning about unused vl static_cast<void>(vl); // Avoid warning about unused vl
std::istringstream is(strVal); istringstream is(strVal.c_str());
int valuesRead = 0; int valuesRead = 0;
while ( is.good() ) { while ( is.good() ) {

View File

@ -23,23 +23,14 @@
#ifndef TCLAP_VALUESCONSTRAINT_H #ifndef TCLAP_VALUESCONSTRAINT_H
#define TCLAP_VALUESCONSTRAINT_H #define TCLAP_VALUESCONSTRAINT_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string> #include <string>
#include <vector> #include <vector>
#include <tclap/Constraint.h> #include <tclap/Constraint.h>
#include <tclap/sstream.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#else
#define HAVE_SSTREAM
#endif
#if defined(HAVE_SSTREAM)
#include <sstream>
#elif defined(HAVE_STRSTREAM)
#include <strstream>
#else
#error "Need a stringstream (sstream or strstream) to compile!"
#endif
namespace TCLAP { namespace TCLAP {

View File

@ -5,6 +5,7 @@
* file: ZshCompletionOutput.h * file: ZshCompletionOutput.h
* *
* Copyright (c) 2006, Oliver Kiddle * Copyright (c) 2006, Oliver Kiddle
* Copyright (c) 2017 Google Inc.
* All rights reserved. * All rights reserved.
* *
* See the file COPYING in the top directory of this distribution for * See the file COPYING in the top directory of this distribution for
@ -23,6 +24,10 @@
#ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H
#define TCLAP_ZSHCOMPLETIONOUTPUT_H #define TCLAP_ZSHCOMPLETIONOUTPUT_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string> #include <string>
#include <vector> #include <vector>
#include <list> #include <list>
@ -33,6 +38,7 @@
#include <tclap/CmdLineOutput.h> #include <tclap/CmdLineOutput.h>
#include <tclap/XorHandler.h> #include <tclap/XorHandler.h>
#include <tclap/Arg.h> #include <tclap/Arg.h>
#include <tclap/sstream.h>
namespace TCLAP { namespace TCLAP {
@ -284,7 +290,7 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar
return "(-)"; return "(-)";
} }
std::ostringstream list; ostringstream list;
if ( a->acceptsMultipleValues() ) if ( a->acceptsMultipleValues() )
{ {
list << '*'; list << '*';

50
include/tclap/sstream.h Normal file
View File

@ -0,0 +1,50 @@
// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
/******************************************************************************
*
* file: sstream.h
*
* Copyright (c) 2003, Michael E. Smoot .
* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno .
* Copyright (c) 2017 Google Inc.
* All rights reserved.
*
* See the file COPYING in the top directory of this distribution for
* more information.
*
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef TCLAP_SSTREAM_H
#define TCLAP_SSTREAM_H
#if !defined(HAVE_STRSTREAM)
// Assume sstream is available if strstream is not specified
// (https://sourceforge.net/p/tclap/bugs/23/)
#define HAVE_SSTREAM
#endif
#if defined(HAVE_SSTREAM)
#include <sstream>
namespace TCLAP {
typedef std::istringstream istringstream;
typedef std::ostringstream ostringstream;
}
#elif defined(HAVE_STRSTREAM)
#include <strstream>
namespace TCLAP {
typedef std::istrstream istringstream;
typedef std::ostrstream ostringstream;
}
#else
#error "Need a stringstream (sstream or strstream) to compile!"
#endif
#endif // TCLAP_SSTREAM_H