mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
replace const string& by string_view in Flags and SymbolTable
This commit is contained in:
parent
63986a4e5f
commit
20e0b3efa5
@ -16,6 +16,7 @@
|
||||
namespace ngcore
|
||||
{
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
using std::endl;
|
||||
Flags :: Flags () { ; }
|
||||
|
||||
@ -209,18 +210,18 @@ namespace ngcore
|
||||
}
|
||||
|
||||
|
||||
double Flags :: GetNumFlag (const string & name, double def) const
|
||||
double Flags :: GetNumFlag (string_view name, double def) const
|
||||
{
|
||||
if (numflags.Used (name))
|
||||
return numflags[name];
|
||||
return numflags[string(name)];
|
||||
else
|
||||
return def;
|
||||
}
|
||||
|
||||
const double * Flags :: GetNumFlagPtr (const string & name) const
|
||||
const double * Flags :: GetNumFlagPtr (string_view name) const
|
||||
{
|
||||
if (numflags.Used (name))
|
||||
return & ((SymbolTable<double>&)numflags)[name];
|
||||
return & ((SymbolTable<double>&)numflags)[string(name)];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -239,16 +240,16 @@ namespace ngcore
|
||||
return defflags.Used (name);
|
||||
}
|
||||
*/
|
||||
bool Flags :: GetDefineFlag (const string & name) const throw()
|
||||
bool Flags :: GetDefineFlag (string_view name) const throw()
|
||||
{
|
||||
if (!defflags.Used (name)) return false;
|
||||
return defflags[name];
|
||||
if (!defflags.Used (string(name))) return false;
|
||||
return defflags[string(name)];
|
||||
}
|
||||
|
||||
xbool Flags :: GetDefineFlagX (const string & name) const throw()
|
||||
xbool Flags :: GetDefineFlagX (string_view name) const throw()
|
||||
{
|
||||
if (!defflags.Used (name)) return maybe;
|
||||
return bool(defflags[name]);
|
||||
if (!defflags.Used (string(name))) return maybe;
|
||||
return bool(defflags[string(name)]);
|
||||
}
|
||||
|
||||
|
||||
@ -296,32 +297,32 @@ namespace ngcore
|
||||
return empty;
|
||||
}
|
||||
|
||||
bool Flags :: StringFlagDefined (const string & name) const
|
||||
bool Flags :: StringFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return strflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: NumFlagDefined (const string &name) const
|
||||
bool Flags :: NumFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return numflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: FlagsFlagDefined (const string &name) const
|
||||
bool Flags :: FlagsFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return flaglistflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: StringListFlagDefined (const string & name) const
|
||||
bool Flags :: StringListFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return strlistflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: NumListFlagDefined (const string & name) const
|
||||
bool Flags :: NumListFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return numlistflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: AnyFlagDefined (const string& name) const
|
||||
bool Flags :: AnyFlagDefined (string_view name) const noexcept
|
||||
{
|
||||
return anyflags.Used(name);
|
||||
}
|
||||
|
@ -125,15 +125,15 @@ namespace ngcore
|
||||
/// Returns std::string flag, default value if not exists
|
||||
std::string GetStringFlag (const std::string & name, std::string def = "") const;
|
||||
/// Returns numerical flag, default value if not exists
|
||||
double GetNumFlag (const std::string & name, double def) const;
|
||||
double GetNumFlag (std::string_view name, double def) const;
|
||||
/// Returns address of numerical flag, null if not exists
|
||||
const double * GetNumFlagPtr (const std::string & name) const;
|
||||
const double * GetNumFlagPtr (std::string_view name) const;
|
||||
/// Returns address of numerical flag, null if not exists
|
||||
double * GetNumFlagPtr (const std::string & name);
|
||||
/// Returns boolean flag
|
||||
// int GetDefineFlag (const char * name) const;
|
||||
bool GetDefineFlag (const std::string & name) const throw();
|
||||
xbool GetDefineFlagX (const std::string & name) const throw();
|
||||
bool GetDefineFlag (std::string_view name) const noexcept;
|
||||
xbool GetDefineFlagX (std::string_view name) const noexcept;
|
||||
/// Returns string list flag, empty array if not exist
|
||||
const Array<std::string> & GetStringListFlag (const std::string & name) const;
|
||||
/// Returns num list flag, empty array if not exist
|
||||
@ -144,16 +144,16 @@ namespace ngcore
|
||||
|
||||
|
||||
/// Test, if string flag is defined
|
||||
bool StringFlagDefined (const std::string & name) const;
|
||||
bool StringFlagDefined (std::string_view name) const noexcept;
|
||||
/// Test, if num flag is defined
|
||||
bool NumFlagDefined (const std::string & name) const;
|
||||
bool NumFlagDefined (std::string_view name) const noexcept;
|
||||
/// Test, if num flag is defined
|
||||
bool FlagsFlagDefined (const std::string & name) const;
|
||||
bool FlagsFlagDefined (std::string_view name) const noexcept;
|
||||
/// Test, if string list flag is defined
|
||||
bool StringListFlagDefined (const std::string & name) const;
|
||||
bool StringListFlagDefined (std::string_view name) const noexcept;
|
||||
/// Test, if num list flag is defined
|
||||
bool NumListFlagDefined (const std::string & name) const;
|
||||
bool AnyFlagDefined (const std::string& name) const;
|
||||
bool NumListFlagDefined (std::string_view name) const noexcept;
|
||||
bool AnyFlagDefined (std::string_view name) const noexcept;
|
||||
|
||||
/// number of string flags
|
||||
int GetNStringFlags () const { return strflags.Size(); }
|
||||
|
@ -45,7 +45,7 @@ namespace ngcore
|
||||
}
|
||||
|
||||
/// INDEX of symbol name, throws exception if unused
|
||||
size_t Index (const std::string & name) const
|
||||
size_t Index (std::string_view name) const
|
||||
{
|
||||
for (size_t i = 0; i < names.size(); i++)
|
||||
if (names[i] == name) return i;
|
||||
@ -53,7 +53,7 @@ namespace ngcore
|
||||
}
|
||||
|
||||
/// Index of symbol name, returns -1 if unused
|
||||
int CheckIndex (const std::string & name) const
|
||||
int CheckIndex (std::string_view name) const
|
||||
{
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
if (names[i] == name) return i;
|
||||
@ -67,12 +67,12 @@ namespace ngcore
|
||||
}
|
||||
|
||||
/// Returns reference to element. exception for unused identifier
|
||||
reference operator[] (const std::string & name)
|
||||
reference operator[] (std::string_view name)
|
||||
{
|
||||
return data[Index (name)];
|
||||
}
|
||||
|
||||
const_reference operator[] (const std::string & name) const
|
||||
const_reference operator[] (std::string_view name) const
|
||||
{
|
||||
return data[Index (name)];
|
||||
}
|
||||
@ -99,7 +99,7 @@ namespace ngcore
|
||||
}
|
||||
|
||||
/// Associates el to the string name, overrides if name is used
|
||||
void Set (const std::string & name, const T & el)
|
||||
void Set (std::string_view name, const T & el)
|
||||
{
|
||||
int i = CheckIndex (name);
|
||||
if (i >= 0)
|
||||
@ -107,15 +107,24 @@ namespace ngcore
|
||||
else
|
||||
{
|
||||
data.push_back(el);
|
||||
names.push_back(name);
|
||||
names.push_back(std::string(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bool Used (const std::string & name) const
|
||||
{
|
||||
return CheckIndex(name) >= 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
bool Used (std::string_view name) const
|
||||
{
|
||||
return CheckIndex(name) >= 0;
|
||||
}
|
||||
|
||||
/// Deletes symboltable
|
||||
inline void DeleteAll ()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user