mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
rewrote value node to support half-sided intervals (meaning infinity or -infinity for the missing half)
This commit is contained in:
parent
9332684335
commit
f3ce9c22a1
@ -437,22 +437,22 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||||||
// parse value
|
// parse value
|
||||||
double lower = 0;
|
double lower = 0;
|
||||||
double upper = 0;
|
double upper = 0;
|
||||||
bool min = false;
|
ValueNode::Type lowerType = ValueNode::Type_Open;
|
||||||
bool max = false;
|
ValueNode::Type upperType = ValueNode::Type_Open;
|
||||||
|
|
||||||
token = getNextToken();
|
token = getNextToken();
|
||||||
|
|
||||||
if (token.mType==Token::Type_Number)
|
if (token.mType==Token::Type_Number)
|
||||||
{
|
{
|
||||||
// single value
|
// single value
|
||||||
min = max = true;
|
|
||||||
lower = upper = token.mNumber;
|
lower = upper = token.mNumber;
|
||||||
|
lowerType = upperType = ValueNode::Type_Closed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// interval
|
// interval
|
||||||
if (token.mType==Token::Type_OpenSquare)
|
if (token.mType==Token::Type_OpenSquare)
|
||||||
min = true;
|
lowerType = ValueNode::Type_Closed;
|
||||||
else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open)
|
else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open)
|
||||||
{
|
{
|
||||||
error();
|
error();
|
||||||
@ -490,7 +490,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||||||
token = getNextToken();
|
token = getNextToken();
|
||||||
|
|
||||||
if (token.mType==Token::Type_CloseSquare)
|
if (token.mType==Token::Type_CloseSquare)
|
||||||
max = true;
|
upperType = ValueNode::Type_Closed;
|
||||||
else if (token.mType!=Token::Type_OpenSquare && token.mType!=Token::Type_Close)
|
else if (token.mType!=Token::Type_OpenSquare && token.mType!=Token::Type_Close)
|
||||||
{
|
{
|
||||||
error();
|
error();
|
||||||
@ -506,7 +506,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||||||
return boost::shared_ptr<Node>();
|
return boost::shared_ptr<Node>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::shared_ptr<Node> (new ValueNode (columnId, lower, upper, min, max));
|
return boost::shared_ptr<Node> (new ValueNode (columnId, lowerType, upperType, lower, upper));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMFilter::Parser::error()
|
void CSMFilter::Parser::error()
|
||||||
|
@ -7,10 +7,9 @@
|
|||||||
#include "../world/columns.hpp"
|
#include "../world/columns.hpp"
|
||||||
#include "../world/idtable.hpp"
|
#include "../world/idtable.hpp"
|
||||||
|
|
||||||
CSMFilter::ValueNode::ValueNode (int columnId,
|
CSMFilter::ValueNode::ValueNode (int columnId, Type lowerType, Type upperType,
|
||||||
double lower, double upper, bool min, bool max)
|
double lower, double upper)
|
||||||
: mColumnId (columnId), mLower (lower), mUpper (upper), mMin (min), mMax (max)
|
: mColumnId (columnId), mLowerType (lowerType), mUpperType (upperType), mLower (lower), mUpper (upper){}
|
||||||
{}
|
|
||||||
|
|
||||||
bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row,
|
bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row,
|
||||||
const std::map<int, int>& columns) const
|
const std::map<int, int>& columns) const
|
||||||
@ -33,10 +32,21 @@ bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row,
|
|||||||
|
|
||||||
double value = data.toDouble();
|
double value = data.toDouble();
|
||||||
|
|
||||||
if (mLower==mUpper && mMin && mMax)
|
switch (mLowerType)
|
||||||
return value==mLower;
|
{
|
||||||
|
case Type_Closed: if (value<mLower) return false; break;
|
||||||
|
case Type_Open: if (value<=mLower) return false; break;
|
||||||
|
case Type_Infinite: break;
|
||||||
|
}
|
||||||
|
|
||||||
return (mMin ? value>=mLower : value>mLower) && (mMax ? value<=mUpper : value<mUpper);
|
switch (mUpperType)
|
||||||
|
{
|
||||||
|
case Type_Closed: if (value>mUpper) return false; break;
|
||||||
|
case Type_Open: if (value>=mUpper) return false; break;
|
||||||
|
case Type_Infinite: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> CSMFilter::ValueNode::getReferencedColumns() const
|
std::vector<int> CSMFilter::ValueNode::getReferencedColumns() const
|
||||||
@ -60,10 +70,26 @@ std::string CSMFilter::ValueNode::toString (bool numericColumns) const
|
|||||||
|
|
||||||
stream << ", \"";
|
stream << ", \"";
|
||||||
|
|
||||||
if (mLower==mUpper && mMin && mMax)
|
if (mLower==mUpper && mLowerType!=Type_Infinite && mUpperType!=Type_Infinite)
|
||||||
stream << mLower;
|
stream << mLower;
|
||||||
else
|
else
|
||||||
stream << (mMin ? "[" : "(") << mLower << ", " << mUpper << (mMax ? "]" : ")");
|
{
|
||||||
|
switch (mLowerType)
|
||||||
|
{
|
||||||
|
case Type_Closed: stream << "[" << mLower; break;
|
||||||
|
case Type_Open: stream << "(" << mLower; break;
|
||||||
|
case Type_Infinite: stream << "("; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << ", ";
|
||||||
|
|
||||||
|
switch (mUpperType)
|
||||||
|
{
|
||||||
|
case Type_Closed: stream << mUpper << "]"; break;
|
||||||
|
case Type_Open: stream << mUpper << ")"; break;
|
||||||
|
case Type_Infinite: stream << ")"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stream << ")";
|
stream << ")";
|
||||||
|
|
||||||
|
@ -7,16 +7,25 @@ namespace CSMFilter
|
|||||||
{
|
{
|
||||||
class ValueNode : public LeafNode
|
class ValueNode : public LeafNode
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
Type_Closed, Type_Open, Type_Infinite
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
int mColumnId;
|
int mColumnId;
|
||||||
std::string mText;
|
std::string mText;
|
||||||
double mLower;
|
double mLower;
|
||||||
double mUpper;
|
double mUpper;
|
||||||
bool mMin;
|
Type mLowerType;
|
||||||
bool mMax;
|
Type mUpperType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ValueNode (int columnId, double lower, double upper, bool min, bool max);
|
ValueNode (int columnId, Type lowerType, Type upperType, double lower, double upper);
|
||||||
|
|
||||||
virtual bool test (const CSMWorld::IdTable& table, int row,
|
virtual bool test (const CSMWorld::IdTable& table, int row,
|
||||||
const std::map<int, int>& columns) const;
|
const std::map<int, int>& columns) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user