SFS2X Objective-C API  1.7.13
iOS / macOS / tvOS
MatchExpression.h
1 //
2 // MatchExpression.h
3 // SFS2X
4 //
5 // Original development by Infosfer Game Technologies Ltd. | http://www.infosfer.com.
6 //
7 // Maintained and developed by A51 Integrated.
8 // Copyright 2012 A51 Integrated | http://a51integrated.com. All rights reserved.
9 //
10 
11 #import "IMatcher.h"
12 #import "ISFSArray.h"
13 
14 @class LogicOperator;
15 
16 /** Match Expressions are built like "if" conditions in any common programming language.
17 
18  They work like queries in a database and can be used to search for Rooms or Users using custom criteria.
19  These expressions are extremely easy to create and concatenate and they can be used for many different filtering operations within the SFS2X framework.
20 
21  This is a quick example:
22 \code
23  MatchExpression *exp = [MatchExpression expressionWithVarName:@"rank" condition:[NumberMatch numberMatchGreaterThan] value:[NSNumber numberWithInt:5]];
24  exp = [exp and:@"country" condition:[StringMatch stringMatchEquals] value:@"Italy"];
25  \endcode
26  Expressions are made of three elements:
27 
28  - Variable name
29  - Match operator
30  - Value
31 
32  Additionally any number of expressions can be linked together with a logical <b>AND</b> / <b>OR</b> operator, just like in regular code.
33  In the above example we have created an expression that will check for a rank value &gt; 5 and a country value == "Italy".
34 
35  The search options are not just limited to User/Room Variables name. In fact the Matching engine provides two extra classes, RoomProperties and UserProperties,
36  where you can access many specific attributes of the Room and User class.
37 
38  @see RoomProperties
39  @see UserProperties
40 
41  */
42 @interface MatchExpression : NSObject {
43 @private
44  NSString *_varName;
45  id <IMatcher> _condition;
46  id _value;
47 
48  LogicOperator *_logicOp;
49  MatchExpression *_parent;
50  MatchExpression *_next;
51 }
52 
53 /** Get the name of the variable or property that is being matched.
54 
55  This can be the name of a User/Room variable or a property from the classes listed below.
56 
57  @see RoomProperties
58  @see UserProperties
59  */
60 @property (nonatomic, strong) NSString *varName;
61 
62 /** Get the condition used for matching
63 
64  @see BoolMatch
65  @see NumberMatch
66  @see StringMatch
67  */
68 @property (nonatomic, strong) id <IMatcher> condition;
69 
70 /** The value used to test the condition in the expression
71  */
72 @property (nonatomic, strong) id value;
73 
74 /** Get the current logic operator, could be null if the expression has no other concatenated expressions
75  @see LogicOperator
76  */
77 @property (nonatomic, strong) LogicOperator *logicOp;
78 @property (nonatomic, strong) MatchExpression *parent;
79 
80 /** Get the next expression chained to the current one.
81  */
82 @property (nonatomic, strong) MatchExpression *next;
83 
84 -(id)initWithVarName:(NSString *)varName condition:(id <IMatcher>)condition value:(id)value;
85 
86 /**
87  @param varName name of the variable/property to match
88  @param condition the match condition
89  @param value the value to match against
90  */
91 +(id)expressionWithVarName:(NSString *)varName condition:(id <IMatcher>)condition value:(id)value;
92 
93 /** Concatenate the current expression with a new one using the logical AND operator
94 
95  @param varName name of the variable/property to match
96  @param condition the match condition
97  @param value the value to match against
98 
99  return a new MatchExpression
100  */
101 -(MatchExpression *)and:(NSString *)varName condition:(id <IMatcher>)condition value:(id)value;
102 
103 /** Concatenate the current expression with a new one using the logical OR operator
104 
105  @param varName name of the variable/property to match
106  @param condition the match condition
107  @param value the value to match against
108 
109  return a new MatchExpression
110  */
111 -(MatchExpression *)or:(NSString *)varName condition:(id <IMatcher>)condition value:(id)value;
112 
113 /** Check if the current expression is concatenated to another one via a logic operator
114 
115  @see LogicOperator
116  */
117 -(BOOL)hasNext;
118 
119 /** Rewinds the cursor to the first expression in the chain and return the MatchExpression at the top of the chain of expressions
120  */
121 -(MatchExpression *)rewind;
122 
123 -(NSString *)asString;
124 
125 
126 -(id <ISFSArray>)toSFSArray;
127 
128 -(id <ISFSArray>)expressionAsSFSArray;
129 
130 @end
MatchExpression
Definition: MatchExpression.h:42
LogicOperator
Definition: LogicOperator.h:17