mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
Merge branch 'any_flags' into 'master'
add std::any symboltable to Flags to store arbitrary objects See merge request jschoeberl/netgen!368
This commit is contained in:
commit
2919ceb7cd
@ -51,6 +51,10 @@ namespace ngcore
|
||||
auto lflags = flags.GetFlagsFlag (i, name);
|
||||
SetFlag (name, lflags);
|
||||
}
|
||||
for(auto i : Range(flags.anyflags.Size()))
|
||||
{
|
||||
SetFlag(flags.anyflags.GetName(i), flags.anyflags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Flags :: Flags (Flags && flags)
|
||||
@ -178,7 +182,11 @@ namespace ngcore
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Flags & Flags :: SetFlag (const string & name, const std::any & val)
|
||||
{
|
||||
anyflags.Set(name, val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string Flags :: GetStringFlag (const string & name, const char * def) const
|
||||
{
|
||||
@ -279,6 +287,14 @@ namespace ngcore
|
||||
}
|
||||
}
|
||||
|
||||
const std::any& Flags:: GetAnyFlag(const std::string& name) const
|
||||
{
|
||||
if(anyflags.Used(name))
|
||||
return anyflags[name];
|
||||
static std::any empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
bool Flags :: StringFlagDefined (const string & name) const
|
||||
{
|
||||
return strflags.Used (name);
|
||||
@ -304,6 +320,11 @@ namespace ngcore
|
||||
return numlistflags.Used (name);
|
||||
}
|
||||
|
||||
bool Flags :: AnyFlagDefined (const string& name) const
|
||||
{
|
||||
return anyflags.Used(name);
|
||||
}
|
||||
|
||||
void Flags :: SaveFlags (ostream & str) const
|
||||
{
|
||||
for (int i = 0; i < strflags.Size(); i++)
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <any>
|
||||
|
||||
#include "array.hpp"
|
||||
#include "symboltable.hpp"
|
||||
@ -38,6 +39,8 @@ namespace ngcore
|
||||
SymbolTable<std::shared_ptr<Array<double>>> numlistflags;
|
||||
/// flags list flags
|
||||
SymbolTable<Flags> flaglistflags;
|
||||
/// any object can be stored as a flag
|
||||
SymbolTable<std::any> anyflags;
|
||||
public:
|
||||
/// no flags
|
||||
Flags ();
|
||||
@ -94,6 +97,8 @@ namespace ngcore
|
||||
Flags & SetFlag (const std::string & name, const Array<std::string> & val);
|
||||
/// Sets double array flag
|
||||
Flags & SetFlag (const std::string & name, const Array<double> & val);
|
||||
/// Sets any flag
|
||||
Flags & SetFlag(const std::string& name, const std::any& val);
|
||||
|
||||
|
||||
Flags SetFlag (const char * name, bool b = true) &&;
|
||||
@ -135,6 +140,7 @@ namespace ngcore
|
||||
const Array<double> & GetNumListFlag (const std::string & name) const;
|
||||
/// Returns flag list flag, empty flag if not exist
|
||||
const Flags & GetFlagsFlag (const std::string & name) const;
|
||||
const std::any& GetAnyFlag (const std::string& name) const;
|
||||
|
||||
|
||||
/// Test, if string flag is defined
|
||||
@ -147,6 +153,7 @@ namespace ngcore
|
||||
bool StringListFlagDefined (const std::string & name) const;
|
||||
/// Test, if num list flag is defined
|
||||
bool NumListFlagDefined (const std::string & name) const;
|
||||
bool AnyFlagDefined (const std::string& name) const;
|
||||
|
||||
/// number of string flags
|
||||
int GetNStringFlags () const { return strflags.Size(); }
|
||||
|
Loading…
Reference in New Issue
Block a user