From d2e552576050aedc6bb8d0a1004cb89f08c2fb03 Mon Sep 17 00:00:00 2001 From: Daniel Aarno Date: Sat, 23 Dec 2017 16:54:34 +0100 Subject: [PATCH] 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/ --- include/tclap/Arg.h | 7 ++-- include/tclap/ValuesConstraint.h | 19 +++-------- include/tclap/ZshCompletionOutput.h | 8 ++++- include/tclap/sstream.h | 50 +++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 include/tclap/sstream.h diff --git a/include/tclap/Arg.h b/include/tclap/Arg.h index 3ea1f7e..79f005a 100644 --- a/include/tclap/Arg.h +++ b/include/tclap/Arg.h @@ -6,6 +6,7 @@ * * 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 @@ -27,8 +28,6 @@ #ifdef HAVE_CONFIG_H #include -#else -#define HAVE_SSTREAM #endif #include @@ -38,6 +37,8 @@ #include #include +#include + #if defined(HAVE_SSTREAM) #include typedef std::istringstream istringstream; @@ -415,7 +416,7 @@ template void ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) { static_cast(vl); // Avoid warning about unused vl - std::istringstream is(strVal); + istringstream is(strVal.c_str()); int valuesRead = 0; while ( is.good() ) { diff --git a/include/tclap/ValuesConstraint.h b/include/tclap/ValuesConstraint.h index 91db53c..d1c1df7 100644 --- a/include/tclap/ValuesConstraint.h +++ b/include/tclap/ValuesConstraint.h @@ -23,23 +23,14 @@ #ifndef TCLAP_VALUESCONSTRAINT_H #define TCLAP_VALUESCONSTRAINT_H +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include - -#ifdef HAVE_CONFIG_H -#include -#else -#define HAVE_SSTREAM -#endif - -#if defined(HAVE_SSTREAM) -#include -#elif defined(HAVE_STRSTREAM) -#include -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif +#include namespace TCLAP { diff --git a/include/tclap/ZshCompletionOutput.h b/include/tclap/ZshCompletionOutput.h index d2ce148..acf655b 100644 --- a/include/tclap/ZshCompletionOutput.h +++ b/include/tclap/ZshCompletionOutput.h @@ -5,6 +5,7 @@ * file: ZshCompletionOutput.h * * Copyright (c) 2006, Oliver Kiddle + * Copyright (c) 2017 Google Inc. * All rights reserved. * * See the file COPYING in the top directory of this distribution for @@ -23,6 +24,10 @@ #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H #define TCLAP_ZSHCOMPLETIONOUTPUT_H +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -33,6 +38,7 @@ #include #include #include +#include namespace TCLAP { @@ -284,7 +290,7 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar return "(-)"; } - std::ostringstream list; + ostringstream list; if ( a->acceptsMultipleValues() ) { list << '*'; diff --git a/include/tclap/sstream.h b/include/tclap/sstream.h new file mode 100644 index 0000000..0118b76 --- /dev/null +++ b/include/tclap/sstream.h @@ -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 +namespace TCLAP { + typedef std::istringstream istringstream; + typedef std::ostringstream ostringstream; +} +#elif defined(HAVE_STRSTREAM) +#include +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