Skip to content

Commit

Permalink
Fix multiply definitions in the library. Should fix issue #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
igormironchik committed Jul 9, 2022
1 parent f6490d4 commit 2ecbf64
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

cmake_minimum_required( VERSION 3.19 )

set( ARGS_VERSION "6.3.1" )
set( ARGS_VERSION "6.3.2" )

option( BUILD_EXAMPLES "Build examples? Default ON." ON )
option( BUILD_TESTS "Build tests? Default ON." ON )
Expand Down
3 changes: 2 additions & 1 deletion args-parser/cmd_line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ static inline ContextInternal
//

//! \return Prepared for priniting string of correct names.
String formatCorrectNamesString( const StringList & names )
static inline String
formatCorrectNamesString( const StringList & names )
{
if( !names.empty() )
{
Expand Down
4 changes: 2 additions & 2 deletions args-parser/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Command
else if( !m_defaultValues.empty() )
return m_defaultValues.front();
else
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! \return All values for this argument.
Expand All @@ -185,7 +185,7 @@ class Command
if( !m_defaultValues.empty() )
return m_defaultValues.front();
else
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! Set default value. \note Value will be pushed back to the list
Expand Down
17 changes: 6 additions & 11 deletions args-parser/group_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "utils.hpp"
#include "exceptions.hpp"
#include "types.hpp"
#include "utils.hpp"

// C++ include.
#include <vector>
Expand All @@ -58,10 +59,6 @@ class Command;
class GroupIface
: public ArgIface
{
public:
//! Dummy empty string.
static const String m_dummyEmptyString;

public:
//! Smart pointer to the argument.
using ArgPtr = std::unique_ptr< ArgIface, details::Deleter< ArgIface > >;
Expand Down Expand Up @@ -143,31 +140,31 @@ class GroupIface
//! \return Flag.
const String & flag() const override
{
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! \return Argument name.
const String & argumentName() const override
{
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! \return Value specifier.
const String & valueSpecifier() const override
{
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! \return Description of the argument.
const String & description() const override
{
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! \return Long description of the argument.
const String & longDescription() const override
{
return m_dummyEmptyString;
return details::DummyString<>::c_string;
}

//! Clear state of the argument.
Expand Down Expand Up @@ -286,8 +283,6 @@ class GroupIface
bool m_required;
}; // class GroupIface

const String GroupIface::m_dummyEmptyString;

} /* namespace Args */

#endif // ARGS__GROUP_IFACE_HPP__INCLUDED
2 changes: 1 addition & 1 deletion args-parser/help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Args {
extern std::stringstream g_argsOutStream;
#endif
#else
OutStreamType & g_argsOutStream = outStream();
static OutStreamType & g_argsOutStream = outStream();
#endif // ARGS_TESTING


Expand Down
63 changes: 29 additions & 34 deletions args-parser/multi_arg.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@

/*!
\file
\author Igor Mironchik (igor.mironchik at gmail dot com).
Copyright (c) 2013-2020 Igor Mironchik
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.
/*!
\file
\author Igor Mironchik (igor.mironchik at gmail dot com).
Copyright (c) 2013-2020 Igor Mironchik
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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 ARGS__MULTI_ARG_HPP__INCLUDED
Expand Down Expand Up @@ -118,7 +118,7 @@ class MultiArg
if( !m_defaultValues.empty() )
return m_defaultValues.front();
else
return m_emptyString;
return details::DummyString<>::c_string;
}

//! Set default value. \note Value will be pushed back to the list
Expand Down Expand Up @@ -161,9 +161,6 @@ class MultiArg
private:
DISABLE_COPY( MultiArg )

//! Dummy empty string.
static const String m_emptyString;

//! Values of this argument.
StringList m_values;
//! Counter.
Expand All @@ -172,8 +169,6 @@ class MultiArg
StringList m_defaultValues;
}; // class MultiArg

const String MultiArg::m_emptyString;


//
// MultiArg
Expand Down Expand Up @@ -216,7 +211,7 @@ MultiArg::value() const
else if( !m_defaultValues.empty() )
return m_defaultValues.front();
else
return m_emptyString;
return details::DummyString<>::c_string;
}

inline void
Expand Down
11 changes: 10 additions & 1 deletion args-parser/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ isCorrectName( const String & name )
//

//! \return Is the given name a misspelling of correct name.
bool isMisspelledName( const String & misspelled,
static inline bool
isMisspelledName( const String & misspelled,
const String & correct )
{
if( !misspelled.empty() && !correct.empty() )
Expand All @@ -174,6 +175,14 @@ bool isMisspelledName( const String & misspelled,
return false;
}

template< typename T = void >
struct DummyString {
static const String c_string;
};

template< typename T >
const String DummyString< T >::c_string;

} /* namespace details */

} /* namespace Args */
Expand Down
1 change: 1 addition & 0 deletions tests/auto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ add_subdirectory( help )
add_subdirectory( api )
add_subdirectory( exceptions )
add_subdirectory( stuff )
add_subdirectory( build )
9 changes: 9 additions & 0 deletions tests/auto/build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

project( test.build )

set( SRC main.cpp setup.cpp setup.hpp )

include_directories( ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../.. )

add_executable( test.build ${SRC} )
42 changes: 42 additions & 0 deletions tests/auto/build/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

/*!
\file
\author Igor Mironchik (igor.mironchik at gmail dot com).
Copyright (c) 2022 Igor Mironchik
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.
*/

#include <args-parser/all.hpp>

#include "setup.hpp"

int main( int argc, char * argv[] )
{
Args::CmdLine cmd{ argc, argv };

SetupCMD( cmd );

return 0;
}
38 changes: 38 additions & 0 deletions tests/auto/build/setup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/*!
\file
\author Igor Mironchik (igor.mironchik at gmail dot com).
Copyright (c) 2022 Igor Mironchik
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.
*/

#include "setup.hpp"

void SetupCMD( Args::CmdLine & cmd )
{
cmd.addArgWithNameOnly( "foo", true, true, "bar" );

cmd.parse();
}
35 changes: 35 additions & 0 deletions tests/auto/build/setup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/*!
\file
\author Igor Mironchik (igor.mironchik at gmail dot com).
Copyright (c) 2022 Igor Mironchik
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.
*/

#pragma once

#include <args-parser/all.hpp>

void SetupCMD( Args::CmdLine & cmd );

0 comments on commit 2ecbf64

Please sign in to comment.