added not filter node

actorid
Marc Zinnschlag 12 years ago
parent 806e9a2888
commit ba6edc55d4

@ -108,7 +108,7 @@ opencs_units_noqt (model/settings
)
opencs_units_noqt (model/filter
node unarynode narynode leafnode booleannode parser andnode ornode
node unarynode narynode leafnode booleannode parser andnode ornode notnode
)
opencs_hdrs_noqt (model/filter

@ -0,0 +1,10 @@
#include "notnode.hpp"
CSMFilter::NotNode::NotNode (boost::shared_ptr<Node> child) : UnaryNode (child, "not") {}
bool CSMFilter::NotNode::test (const CSMWorld::IdTable& table, int row,
const std::map<int, int>& columns) const
{
return !getChild().test (table, row, columns);
}

@ -0,0 +1,21 @@
#ifndef CSM_FILTER_NOTNODE_H
#define CSM_FILTER_NOTNODE_H
#include "unarynode.hpp"
namespace CSMFilter
{
class NotNode : public UnaryNode
{
public:
NotNode (boost::shared_ptr<Node> child);
virtual bool test (const CSMWorld::IdTable& table, int row,
const std::map<int, int>& columns) const;
///< \return Can the specified table row pass through to filter?
/// \param columns column ID to column index mapping
};
}
#endif

@ -10,6 +10,7 @@
#include "booleannode.hpp"
#include "ornode.hpp"
#include "andnode.hpp"
#include "notnode.hpp"
namespace CSMFilter
{
@ -209,7 +210,7 @@ CSMFilter::Token CSMFilter::Parser::getNextToken()
return Token (Token::Type_None);
}
boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseImp()
boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseImp (bool allowEmpty)
{
if (Token token = getNextToken())
{
@ -228,8 +229,21 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseImp()
return parseNAry (token);
case Token::Type_Keyword_Not:
{
boost::shared_ptr<CSMFilter::Node> node = parseImp();
if (mError)
return boost::shared_ptr<Node>();
return boost::shared_ptr<CSMFilter::Node> (new NotNode (node));
}
case Token::Type_EOS:
if (!allowEmpty)
error();
return boost::shared_ptr<Node>();
default:
@ -260,12 +274,6 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseNAry (const Token& ke
if (mError)
return boost::shared_ptr<Node>();
if (!node.get())
{
error();
return boost::shared_ptr<Node>();
}
nodes.push_back (node);
Token token = getNextToken();
@ -309,7 +317,7 @@ bool CSMFilter::Parser::parse (const std::string& filter)
mInput = filter;
mIndex = 0;
boost::shared_ptr<Node> node = parseImp();
boost::shared_ptr<Node> node = parseImp (true);
if (mError)
return false;

@ -25,7 +25,7 @@ namespace CSMFilter
Token checkKeywords (const Token& token);
///< Turn string token into keyword token, if possible.
boost::shared_ptr<Node> parseImp();
boost::shared_ptr<Node> parseImp (bool allowEmpty = false);
///< Will return a null-pointer, if there is nothing more to parse.
boost::shared_ptr<Node> parseNAry (const Token& keyword);

@ -1,7 +1,9 @@
#include "unarynode.hpp"
CSMFilter::UnaryNode::UnaryNode (boost::shared_ptr<Node> child) : mChild (child) {}
CSMFilter::UnaryNode::UnaryNode (boost::shared_ptr<Node> child, const std::string& name)
: mChild (child), mName (name)
{}
const CSMFilter::Node& CSMFilter::UnaryNode::getChild() const
{
@ -23,3 +25,7 @@ bool CSMFilter::UnaryNode::isSimple() const
return false;
}
std::string CSMFilter::UnaryNode::toString (bool numericColumns) const
{
return mName + " " + mChild->toString (numericColumns);
}

@ -1,5 +1,5 @@
#ifndef CSM_FILTER_UNARIYNODE_H
#define CSM_FILTER_UNARIYNODE_H
#ifndef CSM_FILTER_UNARYNODE_H
#define CSM_FILTER_UNARYNODE_H
#include <boost/shared_ptr.hpp>
@ -10,10 +10,11 @@ namespace CSMFilter
class UnaryNode : public Node
{
boost::shared_ptr<Node> mChild;
std::string mName;
public:
UnaryNode (boost::shared_ptr<Node> child);
UnaryNode (boost::shared_ptr<Node> child, const std::string& name);
const Node& getChild() const;
@ -26,6 +27,10 @@ namespace CSMFilter
virtual bool isSimple() const;
///< \return Can this filter be displayed in simple mode.
virtual std::string toString (bool numericColumns) const;
///< Return a string that represents this node.
///
/// \param numericColumns Use numeric IDs instead of string to represent columns.
};
}

Loading…
Cancel
Save