mirror of https://github.com/OpenMW/openmw.git
basic filter tree structure
parent
a95715b61d
commit
f5b06d5d52
@ -0,0 +1,58 @@
|
||||
|
||||
#include "binarynode.hpp"
|
||||
|
||||
CSMFilter::BinaryNode::BinaryNode (std::auto_ptr<Node> left, std::auto_ptr<Node> right)
|
||||
: mLeft (left), mRight (right)
|
||||
{}
|
||||
|
||||
const CSMFilter::Node& CSMFilter::BinaryNode::getLeft() const
|
||||
{
|
||||
return *mLeft;
|
||||
}
|
||||
|
||||
CSMFilter::Node& CSMFilter::BinaryNode::getLeft()
|
||||
{
|
||||
return *mLeft;
|
||||
}
|
||||
|
||||
const CSMFilter::Node& CSMFilter::BinaryNode::getRight() const
|
||||
{
|
||||
return *mRight;
|
||||
}
|
||||
|
||||
CSMFilter::Node& CSMFilter::BinaryNode::getRight()
|
||||
{
|
||||
return *mRight;
|
||||
}
|
||||
|
||||
std::vector<std::string> CSMFilter::BinaryNode::getReferencedFilters() const
|
||||
{
|
||||
std::vector<std::string> left = mLeft->getReferencedFilters();
|
||||
|
||||
std::vector<std::string> right = mRight->getReferencedFilters();
|
||||
|
||||
left.insert (left.end(), right.begin(), right.end());
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
std::vector<int> CSMFilter::BinaryNode::getReferencedColumns() const
|
||||
{
|
||||
std::vector<int> left = mLeft->getReferencedColumns();
|
||||
|
||||
std::vector<int> right = mRight->getReferencedColumns();
|
||||
|
||||
left.insert (left.end(), right.begin(), right.end());
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
bool CSMFilter::BinaryNode::isSimple() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSMFilter::BinaryNode::hasUserValue() const
|
||||
{
|
||||
return mLeft->hasUserValue() || mRight->hasUserValue();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#ifndef CSM_FILTER_BINARYNODE_H
|
||||
#define CSM_FILTER_BINARYNODE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class BinaryNode : public Node
|
||||
{
|
||||
std::auto_ptr<Node> mLeft;
|
||||
std::auto_ptr<Node> mRight;
|
||||
|
||||
public:
|
||||
|
||||
BinaryNode (std::auto_ptr<Node> left, std::auto_ptr<Node> right);
|
||||
|
||||
const Node& getLeft() const;
|
||||
|
||||
Node& getLeft();
|
||||
|
||||
const Node& getRight() const;
|
||||
|
||||
Node& getRight();
|
||||
|
||||
virtual std::vector<std::string> getReferencedFilters() const;
|
||||
///< Return a list of filters that are used by this node (and must be passed as
|
||||
/// otherFilters when calling test).
|
||||
|
||||
virtual std::vector<int> getReferencedColumns() const;
|
||||
///< Return a list of the IDs of the columns referenced by this node. The column mapping
|
||||
/// passed into test as columns must contain all columns listed here.
|
||||
|
||||
virtual bool isSimple() const;
|
||||
///< \return Can this filter be displayed in simple mode.
|
||||
|
||||
virtual bool hasUserValue() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,17 @@
|
||||
|
||||
#include "booleannode.hpp"
|
||||
|
||||
CSMFilter::BooleanNode::BooleanNode (bool true_) : mTrue (true) {}
|
||||
|
||||
bool CSMFilter::BooleanNode::test (const CSMWorld::IdTable& table, int row,
|
||||
const std::map<std::string, const Node *>& otherFilters,
|
||||
const std::map<int, int>& columns,
|
||||
const std::string& userValue) const
|
||||
{
|
||||
return mTrue;
|
||||
}
|
||||
|
||||
std::string CSMFilter::BooleanNode::toString (bool numericColumns) const
|
||||
{
|
||||
return mTrue ? "true" : "false";
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef CSM_FILTER_BOOLEANNODE_H
|
||||
#define CSM_FILTER_BOOLEANNODE_H
|
||||
|
||||
#include "leafnode.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class BooleanNode : public LeafNode
|
||||
{
|
||||
bool mTrue;
|
||||
|
||||
public:
|
||||
|
||||
BooleanNode (bool true_);
|
||||
|
||||
virtual bool test (const CSMWorld::IdTable& table, int row,
|
||||
const std::map<std::string, const Node *>& otherFilters,
|
||||
const std::map<int, int>& columns,
|
||||
const std::string& userValue) const;
|
||||
///< \return Can the specified table row pass through to filter?
|
||||
/// \param columns column ID to column index mapping
|
||||
|
||||
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.
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,22 @@
|
||||
|
||||
#include "leafnode.hpp"
|
||||
|
||||
std::vector<std::string> CSMFilter::LeafNode::getReferencedFilters() const
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<int> CSMFilter::LeafNode::getReferencedColumns() const
|
||||
{
|
||||
return std::vector<int>();
|
||||
}
|
||||
|
||||
bool CSMFilter::LeafNode::isSimple() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSMFilter::LeafNode::hasUserValue() const
|
||||
{
|
||||
return false;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef CSM_FILTER_UNARIYNODE_H
|
||||
#define CSM_FILTER_UNARIYNODE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class LeafNode : public Node
|
||||
{
|
||||
public:
|
||||
|
||||
virtual std::vector<std::string> getReferencedFilters() const;
|
||||
///< Return a list of filters that are used by this node (and must be passed as
|
||||
/// otherFilters when calling test).
|
||||
|
||||
virtual std::vector<int> getReferencedColumns() const;
|
||||
///< Return a list of the IDs of the columns referenced by this node. The column mapping
|
||||
/// passed into test as columns must contain all columns listed here.
|
||||
|
||||
virtual bool isSimple() const;
|
||||
///< \return Can this filter be displayed in simple mode.
|
||||
|
||||
virtual bool hasUserValue() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,6 @@
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
CSMFilter::Node::Node() {}
|
||||
|
||||
CSMFilter::Node::~Node() {}
|
@ -0,0 +1,58 @@
|
||||
#ifndef CSM_FILTER_NODE_H
|
||||
#define CSM_FILTER_NODE_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTable;
|
||||
}
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
/// \brief Root class for the filter node hierarchy
|
||||
///
|
||||
/// \note When the function documentation for this class mentions "this node", this should be
|
||||
/// interpreted as "the node and all its children".
|
||||
class Node
|
||||
{
|
||||
// not implemented
|
||||
Node (const Node&);
|
||||
Node& operator= (const Node&);
|
||||
|
||||
public:
|
||||
|
||||
Node();
|
||||
|
||||
virtual ~Node();
|
||||
|
||||
virtual bool test (const CSMWorld::IdTable& table, int row,
|
||||
const std::map<std::string, const Node *>& otherFilters,
|
||||
const std::map<int, int>& columns,
|
||||
const std::string& userValue) const = 0;
|
||||
///< \return Can the specified table row pass through to filter?
|
||||
/// \param columns column ID to column index mapping
|
||||
|
||||
virtual std::vector<std::string> getReferencedFilters() const = 0;
|
||||
///< Return a list of filters that are used by this node (and must be passed as
|
||||
/// otherFilters when calling test).
|
||||
|
||||
virtual std::vector<int> getReferencedColumns() const = 0;
|
||||
///< Return a list of the IDs of the columns referenced by this node. The column mapping
|
||||
/// passed into test as columns must contain all columns listed here.
|
||||
|
||||
virtual bool isSimple() const = 0;
|
||||
///< \return Can this filter be displayed in simple mode.
|
||||
|
||||
virtual bool hasUserValue() const = 0;
|
||||
|
||||
virtual std::string toString (bool numericColumns) const = 0;
|
||||
///< Return a string that represents this node.
|
||||
///
|
||||
/// \param numericColumns Use numeric IDs instead of string to represent columns.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,34 @@
|
||||
|
||||
#include "unarynode.hpp"
|
||||
|
||||
CSMFilter::UnaryNode::UnaryNode (std::auto_ptr<Node> child) : mChild (child) {}
|
||||
|
||||
const CSMFilter::Node& CSMFilter::UnaryNode::getChild() const
|
||||
{
|
||||
return *mChild;
|
||||
}
|
||||
|
||||
CSMFilter::Node& CSMFilter::UnaryNode::getChild()
|
||||
{
|
||||
return *mChild;
|
||||
}
|
||||
|
||||
std::vector<std::string> CSMFilter::UnaryNode::getReferencedFilters() const
|
||||
{
|
||||
return mChild->getReferencedFilters();
|
||||
}
|
||||
|
||||
std::vector<int> CSMFilter::UnaryNode::getReferencedColumns() const
|
||||
{
|
||||
return mChild->getReferencedColumns();
|
||||
}
|
||||
|
||||
bool CSMFilter::UnaryNode::isSimple() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSMFilter::UnaryNode::hasUserValue() const
|
||||
{
|
||||
return mChild->hasUserValue();
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#ifndef CSM_FILTER_UNARIYNODE_H
|
||||
#define CSM_FILTER_UNARIYNODE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "node.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class UnaryNode : public Node
|
||||
{
|
||||
std::auto_ptr<Node> mChild;
|
||||
|
||||
public:
|
||||
|
||||
UnaryNode (std::auto_ptr<Node> child);
|
||||
|
||||
const Node& getChild() const;
|
||||
|
||||
Node& getChild();
|
||||
|
||||
virtual std::vector<std::string> getReferencedFilters() const;
|
||||
///< Return a list of filters that are used by this node (and must be passed as
|
||||
/// otherFilters when calling test).
|
||||
|
||||
virtual std::vector<int> getReferencedColumns() const;
|
||||
///< Return a list of the IDs of the columns referenced by this node. The column mapping
|
||||
/// passed into test as columns must contain all columns listed here.
|
||||
|
||||
virtual bool isSimple() const;
|
||||
///< \return Can this filter be displayed in simple mode.
|
||||
|
||||
virtual bool hasUserValue() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue