CLI: Add addContextFilter method

This commit is contained in:
Tomas Babej 2015-02-21 16:23:45 +01:00 committed by Paul Beckingham
parent 1abda3900b
commit 3a77a5f291
2 changed files with 45 additions and 0 deletions

View file

@ -374,6 +374,50 @@ void CLI::add (const std::string& arg)
analyze ();
}
////////////////////////////////////////////////////////////////////////////////
void CLI::addContextFilter ()
{
// Detect if any context is set, and bail out if not
std::string contextName = context.config.get ("context");
if (contextName == "")
{
context.debug("No context applied.");
return;
}
// Detect if UUID or ID is set, and bail out
if (_args.size ())
{
std::vector <A>::const_iterator a;
for (a = _args.begin (); a != _args.end (); ++a)
{
if (a->hasTag ("FILTER") &&
a->hasTag ("ATTRIBUTE") &&
! a->hasTag ("TERMINATED") &&
! a->hasTag ("WORD") &&
(a->attribute ("raw") == "id" || a->attribute ("raw") == "uuid"))
{
context.debug(format("UUID/ID lexeme found '{1}', not applying context.", a->attribute ("raw")));
return;
}
}
}
// Apply context
context.debug("Applying context: " + contextName);
std::string contextFilter = context.config.get ("context." + contextName);
if (contextFilter == "")
context.debug("Context '" + contextName + "' not defined!");
else
{
addRawFilter("( " + contextFilter + " )");
if (context.verbose ("context"))
context.footnote (format("Context '{1}' applied.", contextName));
}
}
////////////////////////////////////////////////////////////////////////////////
// Process raw string into parsed filter.
//

View file

@ -77,6 +77,7 @@ public:
void entity (const std::string&, const std::string&);
void initialize (int, const char**);
void add (const std::string&);
void addContextFilter ();
void addRawFilter (const std::string& arg);
void analyze (bool parse = true, bool strict = false);
void applyOverrides ();