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