namespace GiNaC
{
-const symbol&
+symbol
find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
{
symtab::const_iterator p = syms.find(name);
- if (p != syms.end())
- return p->second.first;
+ if (p != syms.end()) {
+ if (is_a<symbol>(p->second))
+ return ex_to<symbol>(p->second);
+ else
+ throw std::invalid_argument(
+ std::string("find_or_insert_symbol: name \"")
+ + name + "\" does not correspond to a symbol");
+ }
+
if (strict)
throw std::invalid_argument(
std::string("find_or_insert_symbol: symbol \"")
+ name + "\" not found");
- // false means this symbol was created by parser
- const std::pair<symbol, bool> tmp = std::make_pair(symbol(name), false);
-
- symtab::iterator i = syms.insert(symtab::value_type(name, tmp)).first;
- return i->second.first;
+ const symbol sy(name);
+ syms[name] = sy;
+ return sy;
}
}
{
/**
- * Establishes correspondence between the strings and symbols.
+ * Establishes correspondence between the strings and expressions.
* The parser will create missing symbols (if not instructed otherwise,
* in which case it fails if the expression contains unknown symbols).
- * The .second element of pair helps to distinguish between the user
- * supplied symbols and parser generated ones. The .first is the symbol
- * itself
*/
-typedef std::map<std::string, std::pair<symbol, bool> > symtab;
+typedef std::map<std::string, ex> symtab;
/**
* Find the symbol with the @a name in the symbol table @a syms.
* If symbol is missing and @a strict = false, insert it, otherwise
* throw an exception.
*/
-extern const symbol&
+extern symbol
find_or_insert_symbol(const std::string& name, symtab& syms,
const bool strict);