SmartFoxServer 2X C++ API
|
Match Expressions are built like "if" conditions in any common programming language. More...
#include <MatchExpression.h>
Inherits enable_shared_from_this< MatchExpression >.
Public Member Functions | |
MatchExpression (boost::shared_ptr< string > varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) | |
Constructor More... | |
MatchExpression (string varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) | |
Constructor More... | |
boost::shared_ptr< MatchExpression > | And (boost::shared_ptr< string > varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) |
Concatenate the current expression with a new one using the logical AND operator More... | |
boost::shared_ptr< MatchExpression > | And (string varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) |
Concatenate the current expression with a new one using the logical AND operator More... | |
boost::shared_ptr< MatchExpression > | Or (boost::shared_ptr< string > varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) |
Concatenate the current expression with a new one using the logical OR operator More... | |
boost::shared_ptr< MatchExpression > | Or (string varName, boost::shared_ptr< IMatcher > condition, boost::shared_ptr< unsigned char > varValue) |
Concatenate the current expression with a new one using the logical OR operator More... | |
boost::shared_ptr< string > | VarName () |
Get the name of the variable or property that is being matched. More... | |
boost::shared_ptr< IMatcher > | Condition () |
Get the condition used for matching More... | |
boost::shared_ptr< void > | VarValue () |
The value used to test the condition in the expression More... | |
boost::shared_ptr< LogicOperator > | LogicOp () |
Get the current logic operator, could be null if the expression has no other concatenated expressions More... | |
bool | HasNext () |
Check if the current expression is concatenated to another one via a logic operator More... | |
boost::shared_ptr< MatchExpression > | Next () |
Get the next expression chained to the current one. More... | |
boost::shared_ptr< MatchExpression > | Rewind () |
Rewinds the cursor to the first expression in the chain and return the MatchExpression at the top of the chain of expressions More... | |
Match Expressions are built like "if" conditions in any common programming language.
Match Expressions are built like "if" conditions in any common programming language. They work like queries in a database and can be used to search for Rooms or Users using custom criteria. These expressions are extremely easy to create and concatenate and they can be used for many different filtering operations within the SFS2X framework.
This is a quick example:
boost::shared_ptr<int> value(new int()); *value = 5; boost::shared_ptr<MatchExpression> exp(new MatchExpression("rank", NumberMatch::GREATER_THAN, value)); boost::shared_ptr<string> country(new string("Italy")); exp->And("country", StringMatch::EQUALS, country);
Expressions are made of three elements:
Additionally any number of expressions can be linked together with a logical AND / OR operator, just like in regular code. In the above example we have created an expression that will check for a rank value > 5 and a country value == "Italy".
The search options are not just limited to User/Room Variables name. In fact the Matching engine provides two extra classes, RoomProperties and UserProperties, where you can access many specific attributes of the Room and User class.
This is an example of matching specific Room properties and Variables:
// Prepare match expression boost::shared_ptr<bool> value(new bool()); *value = true; boost::shared_ptr<MatchExpression> exp(new MatchExpression(RoomProperties::IS_GAME, BoolMatch::EQUALS, value));
boost::shared_ptr<bool> value1(new bool()); *value1 = true; exp->And(RoomProperties::HAS_FREE_PLAYER_SLOTS, BoolMatch::EQUALS, value1);
// Search Rooms boost::shared_ptr<IRequest> requestFindRoomsRequest(new FindRoomsRequest(exp)); m_ptrSmartFox->Send(requestFindRoomsRequest);
the Match expression offer advanced capabilities of searching through nested data structures such as SFSObject and SFSArray. This is done via a very simple dot-syntax. Here's an example of how it works:
boost::shared_ptr<string> value(new string("Rome")); boost::shared_ptr<MatchExpression> exp(new MatchExpression("europe.italy.capital", StringMatch::EQUALS, value));
The above example goes down deep into an SFSObject called <em>europe</em>, taking the <em>italy</em> object (another SFSObject) and finally reading its String field <em>capital</em> and matching it with another String. Here is one more examples using SFSObject and SFSArray:
boost::shared_ptr<string> value(new string("Milan")); boost::shared_ptr<MatchExpression> exp(new MatchExpression("europe.italy.majorCities.3.name", StringMatch::EQUALS, value));
From the italy object we obtain a majorCities SFSArray and we grab the third item in it (the .3 expression means 'give me the element at index == 3'). The item is again an SFSObject whose name property we finally compare to a String.
The power of <b>Match Expression</b> doesn't end here. You can run multiple passes of matching if you need complex searches to be performed. For example you can run a first match and obtain a list of filtered Rooms and then use it to apply another expression to further refine your search, and so on and so forth. <para/>
The power of Match Expression doesn't end here. You can run multiple passes of matching if you need complex searches to be performed. For example you can run a first match and obtain a list of filtered Rooms and then use it to apply another expression to further refine your search, and so on and so forth.
Sfs2X::Entities::Match::MatchExpression::MatchExpression | ( | boost::shared_ptr< string > | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Constructor
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
Sfs2X::Entities::Match::MatchExpression::MatchExpression | ( | string | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Constructor
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::And | ( | boost::shared_ptr< string > | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Concatenate the current expression with a new one using the logical AND operator
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::And | ( | string | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Concatenate the current expression with a new one using the logical AND operator
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
boost::shared_ptr< IMatcher > Sfs2X::Entities::Match::MatchExpression::Condition | ( | ) |
Get the condition used for matching
bool Sfs2X::Entities::Match::MatchExpression::HasNext | ( | ) |
Check if the current expression is concatenated to another one via a logic operator
boost::shared_ptr< LogicOperator > Sfs2X::Entities::Match::MatchExpression::LogicOp | ( | ) |
Get the current logic operator, could be null if the expression has no other concatenated expressions
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::Next | ( | ) |
Get the next expression chained to the current one.
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::Or | ( | boost::shared_ptr< string > | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Concatenate the current expression with a new one using the logical OR operator
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::Or | ( | string | varName, |
boost::shared_ptr< IMatcher > | condition, | ||
boost::shared_ptr< unsigned char > | varValue | ||
) |
Concatenate the current expression with a new one using the logical OR operator
varName | name of the variable/property to match |
condition | the match condition |
varValue | the value to match against |
boost::shared_ptr< MatchExpression > Sfs2X::Entities::Match::MatchExpression::Rewind | ( | ) |
Rewinds the cursor to the first expression in the chain and return the MatchExpression at the top of the chain of expressions
boost::shared_ptr< string > Sfs2X::Entities::Match::MatchExpression::VarName | ( | ) |
Get the name of the variable or property that is being matched.
This can be the name of a User/Room variable or a property from the classes listed below.
boost::shared_ptr< void > Sfs2X::Entities::Match::MatchExpression::VarValue | ( | ) |
The value used to test the condition in the expression