mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:23:53 +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
3 changed files with 53 additions and 18 deletions
|
@ -437,22 +437,22 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||
// parse value
|
||||
double lower = 0;
|
||||
double upper = 0;
|
||||
bool min = false;
|
||||
bool max = false;
|
||||
ValueNode::Type lowerType = ValueNode::Type_Open;
|
||||
ValueNode::Type upperType = ValueNode::Type_Open;
|
||||
|
||||
token = getNextToken();
|
||||
|
||||
if (token.mType==Token::Type_Number)
|
||||
{
|
||||
// single value
|
||||
min = max = true;
|
||||
lower = upper = token.mNumber;
|
||||
lowerType = upperType = ValueNode::Type_Closed;
|
||||
}
|
||||
else
|
||||
{
|
||||
// interval
|
||||
if (token.mType==Token::Type_OpenSquare)
|
||||
min = true;
|
||||
lowerType = ValueNode::Type_Closed;
|
||||
else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open)
|
||||
{
|
||||
error();
|
||||
|
@ -490,7 +490,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||
token = getNextToken();
|
||||
|
||||
if (token.mType==Token::Type_CloseSquare)
|
||||
max = true;
|
||||
upperType = ValueNode::Type_Closed;
|
||||
else if (token.mType!=Token::Type_OpenSquare && token.mType!=Token::Type_Close)
|
||||
{
|
||||
error();
|
||||
|
@ -506,7 +506,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
|||
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()
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
#include "../world/columns.hpp"
|
||||
#include "../world/idtable.hpp"
|
||||
|
||||
CSMFilter::ValueNode::ValueNode (int columnId,
|
||||
double lower, double upper, bool min, bool max)
|
||||
: mColumnId (columnId), mLower (lower), mUpper (upper), mMin (min), mMax (max)
|
||||
{}
|
||||
CSMFilter::ValueNode::ValueNode (int columnId, Type lowerType, Type upperType,
|
||||
double lower, double upper)
|
||||
: mColumnId (columnId), mLowerType (lowerType), mUpperType (upperType), mLower (lower), mUpper (upper){}
|
||||
|
||||
bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row,
|
||||
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();
|
||||
|
||||
if (mLower==mUpper && mMin && mMax)
|
||||
return value==mLower;
|
||||
switch (mLowerType)
|
||||
{
|
||||
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
|
||||
|
@ -60,10 +70,26 @@ std::string CSMFilter::ValueNode::toString (bool numericColumns) const
|
|||
|
||||
stream << ", \"";
|
||||
|
||||
if (mLower==mUpper && mMin && mMax)
|
||||
if (mLower==mUpper && mLowerType!=Type_Infinite && mUpperType!=Type_Infinite)
|
||||
stream << mLower;
|
||||
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 << ")";
|
||||
|
||||
|
|
|
@ -7,16 +7,25 @@ namespace CSMFilter
|
|||
{
|
||||
class ValueNode : public LeafNode
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
Type_Closed, Type_Open, Type_Infinite
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
int mColumnId;
|
||||
std::string mText;
|
||||
double mLower;
|
||||
double mUpper;
|
||||
bool mMin;
|
||||
bool mMax;
|
||||
Type mLowerType;
|
||||
Type mUpperType;
|
||||
|
||||
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,
|
||||
const std::map<int, int>& columns) const;
|
||||
|
|
Loading…
Reference in a new issue