Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std::string with string #1301

Merged
merged 2 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/ObjectCatalog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/


#include <string>

#include <iostream>

#include "common/Logger.hpp"
Expand Down
12 changes: 6 additions & 6 deletions src/coreComponents/codingUtilities/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace stringutilities
/**
* String tokenizing function
**/
string_array Tokenize( const std::string & str, const std::string & delimiters )
string_array Tokenize( const string & str, const string & delimiters )
Copy link
Contributor

@sytuannguyen sytuannguyen Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to change also "const string" to "string const" as the rule said:

image

Copy link
Contributor

@TotoGaz TotoGaz Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Position of const is not restrained to string. It will probably be more efficient to deal with const position all at once, for all the argument types, in another PR, when we find/build an automated way to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes....we should do the const enforcement in a stand-alone PR.

{
string_array tokens;

Expand All @@ -41,7 +41,7 @@ string_array Tokenize( const std::string & str, const std::string & delimiters )
{

bool usesNonWhitespaceDelimiters = false;
std::string::size_type i =0;
string::size_type i =0;
while( delimiters[i] && !usesNonWhitespaceDelimiters )
{
usesNonWhitespaceDelimiters |= !isspace( int(delimiters[i]) );
Expand All @@ -54,7 +54,7 @@ string_array Tokenize( const std::string & str, const std::string & delimiters )
size_t lastPos = 0;

size_t newPos = lastPos;
while( (newPos=str.find_first_of( delimiters, lastPos )) != std::string::npos )
while( (newPos=str.find_first_of( delimiters, lastPos )) != string::npos )
{
tokens.emplace_back( str.substr( lastPos, newPos-lastPos ));
lastPos = newPos + 1;
Expand All @@ -66,15 +66,15 @@ string_array Tokenize( const std::string & str, const std::string & delimiters )
// whitespace delimiters
// skip multiple adjacent delimiters
size_t lastPos = str.find_first_not_of( delimiters, 0 );
lastPos = (lastPos == std::string::npos) ? 0 : lastPos;
lastPos = (lastPos == string::npos) ? 0 : lastPos;

size_t newPos = lastPos;
while( (newPos=str.find_first_of( delimiters, lastPos )) != std::string::npos )
while( (newPos=str.find_first_of( delimiters, lastPos )) != string::npos )
{
tokens.emplace_back( str.substr( lastPos, newPos-lastPos ));
lastPos = str.find_first_not_of( delimiters, newPos );
}
if( lastPos!= std::string::npos )
if( lastPos!= string::npos )
tokens.emplace_back( str.substr( lastPos, str.length()-lastPos ));

}
Expand Down
12 changes: 6 additions & 6 deletions src/coreComponents/codingUtilities/StringUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ namespace stringutilities

/// Overloaded function to check equality between strings and char arrays
/// Mainly used to avoid char*==char* mistakes
inline bool streq( std::string const & strA, std::string const & strB )
inline bool streq( string const & strA, string const & strB )
{ return strA == strB; }

inline bool streq( std::string const & strA, char const * const strB )
inline bool streq( string const & strA, char const * const strB )
{ return strA == strB; }

inline bool streq( char const * const strA, std::string const & strB )
inline bool streq( char const * const strA, string const & strB )
{ return strA == strB; }

inline bool streq( char const * const strA, char const * const strB )
{ return !strcmp( strA, strB ); }

/**
* @brief Join strings or other printable objects with a delimiter.
* @tparam S type of delimiter, usually char, char const * or std::string
* @tparam S type of delimiter, usually char, char const * or string
* @tparam IT type of iterator into the range of objects to join
* @param delim delimiter used to glue together strings
* @param first iterator to start of the range
* @param last iterator past-the-end of the range
* @return a new string containing input strings concatenated with a delimiter
*/
template< typename IT, typename S = char >
std::string strjoin( IT first, IT last, S const & delim = S() )
string strjoin( IT first, IT last, S const & delim = S() )
{
std::ostringstream oss;
if( first != last )
Expand All @@ -75,7 +75,7 @@ std::string strjoin( IT first, IT last, S const & delim = S() )
}

/// Subdivide string by delimiters
string_array Tokenize( std::string const & str, std::string const & delimiters );
string_array Tokenize( string const & str, string const & delimiters );

/**
* @brief Retuns a string containing a padded value
Expand Down
26 changes: 13 additions & 13 deletions src/coreComponents/codingUtilities/tests/testGeosxTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ IS_VALID_EXPRESSION( HasOperatorPlusEquals, T, std::declval< T & >() += T() );
TEST( testGeosxTraits, HasOperatorPlusEquals )
{
static_assert( HasOperatorPlusEquals< int >, "Should be true." );
static_assert( HasOperatorPlusEquals< std::string >, "Should be true." );
static_assert( HasOperatorPlusEquals< string >, "Should be true." );

static_assert( !HasOperatorPlusEquals< int const >, "Should be false." );
static_assert( !HasOperatorPlusEquals< std::vector< int > >, "Should be false." );
Expand All @@ -38,24 +38,24 @@ TEST( testGeosxTraits, HasOperatorPlusEquals2 )
{
static_assert( HasOperatorPlusEquals2< double, int >, "Should be true." );
static_assert( HasOperatorPlusEquals2< double, int const >, "Should be true." );
static_assert( HasOperatorPlusEquals2< std::string, std::string >, "Should be true." );
static_assert( HasOperatorPlusEquals2< string, string >, "Should be true." );

static_assert( !HasOperatorPlusEquals2< double const, int >, "Should be false." );
static_assert( !HasOperatorPlusEquals2< R1Tensor, std::string >, "Should be false." );
static_assert( !HasOperatorPlusEquals2< R1Tensor, string >, "Should be false." );
static_assert( !HasOperatorPlusEquals2< std::vector< int >, int >, "Should be false." );
}

HAS_MEMBER_FUNCTION_NO_RTYPE( at, 55 );
TEST( testGeosxTraits, HasMemberFunction_at )
{
static_assert( HasMemberFunction_at< std::string >, "Should be true." );
static_assert( HasMemberFunction_at< string >, "Should be true." );
static_assert( HasMemberFunction_at< std::vector< int > >, "Should be true." );
static_assert( HasMemberFunction_at< std::vector< double > >, "Should be true." );
static_assert( HasMemberFunction_at< std::map< int, std::string > >, "Should be true." );
static_assert( HasMemberFunction_at< std::unordered_map< int, std::string > >, "Should be true." );
static_assert( HasMemberFunction_at< std::map< int, string > >, "Should be true." );
static_assert( HasMemberFunction_at< std::unordered_map< int, string > >, "Should be true." );

static_assert( !HasMemberFunction_at< int >, "Should be false." );
static_assert( !HasMemberFunction_at< std::map< std::string, std::string > >, "Should be false." );
static_assert( !HasMemberFunction_at< std::map< string, string > >, "Should be false." );
static_assert( !HasMemberFunction_at< array1d< localIndex > >, "Should be false." );
}

Expand All @@ -65,7 +65,7 @@ HAS_MEMBER_FUNCTION_NO_RTYPE( insert,
TEST( testGeosxTraits, HasMemberFunction_insert )
{
static_assert( HasMemberFunction_insert< std::vector< int > >, "Should be true." );
static_assert( HasMemberFunction_insert< std::map< std::string, int > >, "Should be true." );
static_assert( HasMemberFunction_insert< std::map< string, int > >, "Should be true." );
static_assert( HasMemberFunction_insert< std::list< std::vector< int > > >, "Should be true." );

static_assert( !HasMemberFunction_insert< int >, "Should be false." );
Expand All @@ -90,15 +90,15 @@ TEST( testGeosxTraits, Pointer )
static_assert( std::is_same< Pointer< int >, int * >::value, "Should be true." );
static_assert( std::is_same< Pointer< R1Tensor >, R1Tensor * >::value, "Should be true." );
static_assert( std::is_same< Pointer< std::vector< double > >, double * >::value, "Should be true." );
static_assert( std::is_same< Pointer< std::string >, char const * >::value, "Should be true." );
static_assert( std::is_same< Pointer< array3d< std::string > >, std::string * >::value, "Should be true." );
static_assert( std::is_same< Pointer< string >, char const * >::value, "Should be true." );
static_assert( std::is_same< Pointer< array3d< string > >, string * >::value, "Should be true." );
static_assert( std::is_same< Pointer< SortedArray< float > >, float const * >::value, "Should be true." );

static_assert( std::is_same< ConstPointer< int >, int const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< R1Tensor >, R1Tensor const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< std::vector< double > >, double const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< std::string >, char const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< array3d< std::string > >, std::string const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< string >, char const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< array3d< string > >, string const * >::value, "Should be true." );
static_assert( std::is_same< ConstPointer< SortedArray< float > >, float const * >::value, "Should be true." );
}

Expand Down Expand Up @@ -145,7 +145,7 @@ TEST( testGeosxTraits, CanStreamInto )
{
static_assert( CanStreamInto< std::istringstream, int >, "Should be true." );
static_assert( CanStreamInto< std::istringstream, double >, "Should be true." );
static_assert( CanStreamInto< std::istringstream, std::string >, "Should be true." );
static_assert( CanStreamInto< std::istringstream, string >, "Should be true." );

static_assert( !CanStreamInto< std::istringstream, array1d< double > >, "Should be false." );
static_assert( !CanStreamInto< std::istringstream, std::vector< int > >, "Should be false." );
Expand Down
8 changes: 4 additions & 4 deletions src/coreComponents/codingUtilities/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static constexpr bool HasMemberFunction_move = LvArray::bufferManipulation::HasM

/**
* @brief Defines a static constexpr bool HasMemberFunction_setName< @p CLASS >
* that is true iff the method @p CLASS ::setName( std::string ) exists.
* that is true iff the method @p CLASS ::setName( string ) exists.
* @tparam CLASS The type to test.
*/
HAS_MEMBER_FUNCTION_NO_RTYPE( setName, std::string() );
HAS_MEMBER_FUNCTION_NO_RTYPE( setName, string() );

/**
* @brief Defines a static constexpr bool HasMemberFunction_size< @p CLASS >
Expand Down Expand Up @@ -142,9 +142,9 @@ using ViewType = LvArray::typeManipulation::ViewType< T >;
template< typename T >
using ViewTypeConst = LvArray::typeManipulation::ViewTypeConst< T >;

/// True if T is or inherits from std::string.
/// True if T is or inherits from string.
template< typename T >
constexpr bool is_string = std::is_base_of< std::string, T >::value;
constexpr bool is_string = std::is_base_of< string, T >::value;

/// True if T is an instantiation of LvArray::Array.
template< typename T >
Expand Down
20 changes: 10 additions & 10 deletions src/coreComponents/common/DataTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ class rtTypes
* @param key the std::type_index of the type
* @return a hard coded string that is related to the std::type_index
*/
static std::string typeNames( std::type_index const key )
static string typeNames( std::type_index const key )
{
const std::unordered_map< std::type_index, std::string > type_names =
const std::unordered_map< std::type_index, string > type_names =
{
{std::type_index( typeid(integer)), "integer"},
{std::type_index( typeid(real32)), "real32"},
Expand Down Expand Up @@ -650,7 +650,7 @@ class rtTypes
public:

/// The type of map used to store the map of type parsing regular expressions
using regexMapType = std::map< std::string, std::string >;
using regexMapType = std::map< string, string >;

/**
* @brief Get an iterator to the beginning of regex map.
Expand Down Expand Up @@ -689,14 +689,14 @@ class rtTypes
* axes are given as a comma-separated list enclosed in a curly brace.
* For example, a 2D string array would look like: {{"a", "b"}, {"c", "d"}}
*/
std::string constructArrayRegex( std::string subPattern, integer dimension )
string constructArrayRegex( string subPattern, integer dimension )
{
if( dimension > 1 )
{
subPattern = constructArrayRegex( subPattern, dimension-1 );
}

std::string arrayPattern;
string arrayPattern;
if( dimension == 1 )
{
// Allow the bottom-level to be empty
Expand All @@ -712,10 +712,10 @@ class rtTypes

// Define the component regexes:
// Regex to match an unsigned int (123, etc.)
std::string ru = "[\\d]+";
string ru = "[\\d]+";

// Regex to match an signed int (-123, 455, +789, etc.)
std::string ri = "[+-]?[\\d]+";
string ri = "[+-]?[\\d]+";

// Regex to match a float (1, +2.3, -.4, 5.6e7, 8E-9, etc.)
// Explanation of parts:
Expand All @@ -724,13 +724,13 @@ class rtTypes
// [\\d]* matches any number of numbers following the decimal
// ([eE][-+]?[\\d]+|\\s*) matches an optional scientific notation number
// Note: the xsd regex implementation does not allow an empty branch, so use allow whitespace at the end
std::string rr = "[+-]?[\\d]*([\\d]\\.?|\\.[\\d])[\\d]*([eE][-+]?[\\d]+|\\s*)";
string rr = "[+-]?[\\d]*([\\d]\\.?|\\.[\\d])[\\d]*([eE][-+]?[\\d]+|\\s*)";

// Regex to match a string that does not contain the characters ,{}
std::string rs = "[^,\\{\\}]*";
string rs = "[^,\\{\\}]*";

// Regex to match a R1Tensor
std::string r1 = "\\s*(" + rr + ",\\s*){2}" + rr;
string r1 = "\\s*(" + rr + ",\\s*){2}" + rr;

// Build master list of regexes
regexMapType regexMap =
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/common/EnumStrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct TypeRegex< ENUM, std::enable_if_t< internal::HasEnumStrings< ENUM > > >
/**
* @brief @return Regex for validating enumeration inputs for @p ENUM type.
*/
static std::string get()
static string get()
{
return EnumStrings< ENUM >::concat( "|" );
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/common/unitTests/testDataTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <gtest/gtest.h>

#include "common/DataTypes.hpp"
#include <string>

#include <typeindex>

using namespace geosx;
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/ConstitutiveBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace dataRepository;
namespace constitutive
{

ConstitutiveBase::ConstitutiveBase( std::string const & name,
ConstitutiveBase::ConstitutiveBase( string const & name,
Group * const parent ):
Group( name, parent ),
m_numQuadraturePoints( 1 ),
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/ConstitutiveBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ConstitutiveBase : public dataRepository::Group
///@{

/// @typedef An alias for the ConstitutiveBase catalog
using CatalogInterface = dataRepository::CatalogInterface< ConstitutiveBase, std::string const &, Group * const >;
using CatalogInterface = dataRepository::CatalogInterface< ConstitutiveBase, string const &, Group * const >;

/**
* @brief Singleton accessor for catalog
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/NullModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NullModel::NullModel( string const & name,
NullModel::~NullModel()
{}

REGISTER_CATALOG_ENTRY( ConstitutiveBase, NullModel, std::string const &, dataRepository::Group * const )
REGISTER_CATALOG_ENTRY( ConstitutiveBase, NullModel, string const &, dataRepository::Group * const )

} // constitutive
} /* namespace geosx */
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/NullModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class NullModel : public constitutive::ConstitutiveBase
/**
* @return A string that is used to register/lookup this class in the registry
*/
static std::string catalogName() { return m_catalogNameString; }
static string catalogName() { return m_catalogNameString; }

virtual string getCatalogName() const override { return catalogName(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace constitutive
{


BrooksCoreyCapillaryPressure::BrooksCoreyCapillaryPressure( std::string const & name,
BrooksCoreyCapillaryPressure::BrooksCoreyCapillaryPressure( string const & name,
Group * const parent )
: CapillaryPressureBase( name, parent )
{
Expand Down Expand Up @@ -121,7 +121,7 @@ BrooksCoreyCapillaryPressure::KernelWrapper BrooksCoreyCapillaryPressure::create
m_dPhaseCapPressure_dPhaseVolFrac );
}

REGISTER_CATALOG_ENTRY( ConstitutiveBase, BrooksCoreyCapillaryPressure, std::string const &, Group * const )
REGISTER_CATALOG_ENTRY( ConstitutiveBase, BrooksCoreyCapillaryPressure, string const &, Group * const )
} // namespace constitutive

} // namespace geosx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class BrooksCoreyCapillaryPressure : public CapillaryPressureBase
{
public:

BrooksCoreyCapillaryPressure( std::string const & name,
BrooksCoreyCapillaryPressure( string const & name,
dataRepository::Group * const parent );

virtual ~BrooksCoreyCapillaryPressure() override;

static std::string catalogName() { return "BrooksCoreyCapillaryPressure"; }
static string catalogName() { return "BrooksCoreyCapillaryPressure"; }

virtual string getCatalogName() const override { return catalogName(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::unordered_map< string, integer > const phaseDict =

}

CapillaryPressureBase::CapillaryPressureBase( std::string const & name,
CapillaryPressureBase::CapillaryPressureBase( string const & name,
Group * const parent )
: ConstitutiveBase( name, parent )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CapillaryPressureBase : public ConstitutiveBase
// choose the reference pressure to be the oil pressure for all models
static constexpr integer REFERENCE_PHASE = PhaseType::OIL;

CapillaryPressureBase( std::string const & name,
CapillaryPressureBase( string const & name,
dataRepository::Group * const parent );

virtual ~CapillaryPressureBase() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace dataRepository;
namespace constitutive
{

VanGenuchtenCapillaryPressure::VanGenuchtenCapillaryPressure( std::string const & name,
VanGenuchtenCapillaryPressure::VanGenuchtenCapillaryPressure( string const & name,
Group * const parent )
: CapillaryPressureBase( name, parent )
{
Expand Down Expand Up @@ -120,7 +120,7 @@ VanGenuchtenCapillaryPressure::KernelWrapper VanGenuchtenCapillaryPressure::crea
m_dPhaseCapPressure_dPhaseVolFrac );
}

REGISTER_CATALOG_ENTRY( ConstitutiveBase, VanGenuchtenCapillaryPressure, std::string const &, Group * const )
REGISTER_CATALOG_ENTRY( ConstitutiveBase, VanGenuchtenCapillaryPressure, string const &, Group * const )
} // namespace constitutive

} // namespace geosx
Loading