diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 9f33c862a..8e0024ad9 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -107,6 +107,10 @@ opencs_units_noqt (model/settings settingsitem ) +opencs_units_noqt (model/filter + node unarynode binarynode leafnode booleannode + ) + opencs_hdrs_noqt (model/filter filter ) diff --git a/apps/opencs/model/filter/binarynode.cpp b/apps/opencs/model/filter/binarynode.cpp new file mode 100644 index 000000000..0e86930db --- /dev/null +++ b/apps/opencs/model/filter/binarynode.cpp @@ -0,0 +1,58 @@ + +#include "binarynode.hpp" + +CSMFilter::BinaryNode::BinaryNode (std::auto_ptr left, std::auto_ptr 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 CSMFilter::BinaryNode::getReferencedFilters() const +{ + std::vector left = mLeft->getReferencedFilters(); + + std::vector right = mRight->getReferencedFilters(); + + left.insert (left.end(), right.begin(), right.end()); + + return left; +} + +std::vector CSMFilter::BinaryNode::getReferencedColumns() const +{ + std::vector left = mLeft->getReferencedColumns(); + + std::vector 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(); +} diff --git a/apps/opencs/model/filter/binarynode.hpp b/apps/opencs/model/filter/binarynode.hpp new file mode 100644 index 000000000..18cdad2a9 --- /dev/null +++ b/apps/opencs/model/filter/binarynode.hpp @@ -0,0 +1,42 @@ +#ifndef CSM_FILTER_BINARYNODE_H +#define CSM_FILTER_BINARYNODE_H + +#include + +#include "node.hpp" + +namespace CSMFilter +{ + class BinaryNode : public Node + { + std::auto_ptr mLeft; + std::auto_ptr mRight; + + public: + + BinaryNode (std::auto_ptr left, std::auto_ptr right); + + const Node& getLeft() const; + + Node& getLeft(); + + const Node& getRight() const; + + Node& getRight(); + + virtual std::vector 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 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 diff --git a/apps/opencs/model/filter/booleannode.cpp b/apps/opencs/model/filter/booleannode.cpp new file mode 100644 index 000000000..cea130d24 --- /dev/null +++ b/apps/opencs/model/filter/booleannode.cpp @@ -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& otherFilters, + const std::map& columns, + const std::string& userValue) const +{ + return mTrue; +} + +std::string CSMFilter::BooleanNode::toString (bool numericColumns) const +{ + return mTrue ? "true" : "false"; +} \ No newline at end of file diff --git a/apps/opencs/model/filter/booleannode.hpp b/apps/opencs/model/filter/booleannode.hpp new file mode 100644 index 000000000..3578c7f3f --- /dev/null +++ b/apps/opencs/model/filter/booleannode.hpp @@ -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& otherFilters, + const std::map& 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 \ No newline at end of file diff --git a/apps/opencs/model/filter/leafnode.cpp b/apps/opencs/model/filter/leafnode.cpp new file mode 100644 index 000000000..5c6d4b042 --- /dev/null +++ b/apps/opencs/model/filter/leafnode.cpp @@ -0,0 +1,22 @@ + +#include "leafnode.hpp" + +std::vector CSMFilter::LeafNode::getReferencedFilters() const +{ + return std::vector(); +} + +std::vector CSMFilter::LeafNode::getReferencedColumns() const +{ + return std::vector(); +} + +bool CSMFilter::LeafNode::isSimple() const +{ + return true; +} + +bool CSMFilter::LeafNode::hasUserValue() const +{ + return false; +} \ No newline at end of file diff --git a/apps/opencs/model/filter/leafnode.hpp b/apps/opencs/model/filter/leafnode.hpp new file mode 100644 index 000000000..663083ff9 --- /dev/null +++ b/apps/opencs/model/filter/leafnode.hpp @@ -0,0 +1,29 @@ +#ifndef CSM_FILTER_UNARIYNODE_H +#define CSM_FILTER_UNARIYNODE_H + +#include + +#include "node.hpp" + +namespace CSMFilter +{ + class LeafNode : public Node + { + public: + + virtual std::vector 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 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 diff --git a/apps/opencs/model/filter/node.cpp b/apps/opencs/model/filter/node.cpp new file mode 100644 index 000000000..276861cdc --- /dev/null +++ b/apps/opencs/model/filter/node.cpp @@ -0,0 +1,6 @@ + +#include "node.hpp" + +CSMFilter::Node::Node() {} + +CSMFilter::Node::~Node() {} \ No newline at end of file diff --git a/apps/opencs/model/filter/node.hpp b/apps/opencs/model/filter/node.hpp new file mode 100644 index 000000000..09bc3cd42 --- /dev/null +++ b/apps/opencs/model/filter/node.hpp @@ -0,0 +1,58 @@ +#ifndef CSM_FILTER_NODE_H +#define CSM_FILTER_NODE_H + +#include +#include +#include + +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& otherFilters, + const std::map& 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 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 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 diff --git a/apps/opencs/model/filter/unarynode.cpp b/apps/opencs/model/filter/unarynode.cpp new file mode 100644 index 000000000..f9cc3fdc8 --- /dev/null +++ b/apps/opencs/model/filter/unarynode.cpp @@ -0,0 +1,34 @@ + +#include "unarynode.hpp" + +CSMFilter::UnaryNode::UnaryNode (std::auto_ptr child) : mChild (child) {} + +const CSMFilter::Node& CSMFilter::UnaryNode::getChild() const +{ + return *mChild; +} + +CSMFilter::Node& CSMFilter::UnaryNode::getChild() +{ + return *mChild; +} + +std::vector CSMFilter::UnaryNode::getReferencedFilters() const +{ + return mChild->getReferencedFilters(); +} + +std::vector CSMFilter::UnaryNode::getReferencedColumns() const +{ + return mChild->getReferencedColumns(); +} + +bool CSMFilter::UnaryNode::isSimple() const +{ + return false; +} + +bool CSMFilter::UnaryNode::hasUserValue() const +{ + return mChild->hasUserValue(); +} diff --git a/apps/opencs/model/filter/unarynode.hpp b/apps/opencs/model/filter/unarynode.hpp new file mode 100644 index 000000000..6ecad1192 --- /dev/null +++ b/apps/opencs/model/filter/unarynode.hpp @@ -0,0 +1,37 @@ +#ifndef CSM_FILTER_UNARIYNODE_H +#define CSM_FILTER_UNARIYNODE_H + +#include + +#include "node.hpp" + +namespace CSMFilter +{ + class UnaryNode : public Node + { + std::auto_ptr mChild; + + public: + + UnaryNode (std::auto_ptr child); + + const Node& getChild() const; + + Node& getChild(); + + virtual std::vector 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 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