1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/misc/types_nl.h"
21 #include "nel/misc/debug.h"
22 #include "nel/misc/config_file.h"
23 #include "nel/misc/displayer.h"
24 #include "nel/misc/log.h"
26 #include "nel/net/varpath.h"
34 using namespace NLMISC
;
49 * VarPath ::= [bloc '.']* bloc
50 * bloc ::= '[' [VarPath ',']* VarPath ']' | name
51 * name ::= [ascii]* ['*']
55 /*bool CVarPath::getDest (uint level, vector<string> &dest)
60 string
CVarPath::getToken ()
64 if (TokenPos
>= RawVarPath
.size())
67 res
+= RawVarPath
[TokenPos
];
69 switch (RawVarPath
[TokenPos
++])
71 case '.': case '*': case '[': case ']': case ',': case '=': case ' ':
74 while (TokenPos
< RawVarPath
.size() && RawVarPath
[TokenPos
] != '.' && RawVarPath
[TokenPos
] != '[' && RawVarPath
[TokenPos
] != ']' && RawVarPath
[TokenPos
] != ',' && RawVarPath
[TokenPos
] != '=' && RawVarPath
[TokenPos
] != ' ')
76 res
+= RawVarPath
[TokenPos
++];
84 void CVarPath::decode ()
90 string val
= getToken ();
110 nlwarning ("VP: Bad VarPath '%s', suppose it s an empty varpath", RawVarPath
.c_str());
111 Destination
.clear ();
115 if (osbnb
== 0 && (val
== "," || val
== "]"))
128 else if (val
!= "." && val
!= "," && val
!= "]")
130 dest
.push_back (val
);
134 nlwarning ("VP: Malformated VarPath '%s' before position %d", RawVarPath
.c_str (), TokenPos
);
138 // must be a . or end of string
142 // special case, there s a space that means that everything after is not really part of the varpath.
143 Destination
.push_back (make_pair(RawVarPath
, string("")));
146 else if (val
!= "." && !val
.empty() && val
!= "=")
148 nlwarning ("VP: Malformated VarPath '%s' before position %d", RawVarPath
.c_str (), TokenPos
);
152 for (uint i
= 0; i
< dest
.size(); ++i
)
155 string::size_type pos
;
157 if ((pos
= dest
[i
].find ('.')) != string::npos
)
159 srv
= dest
[i
].substr(0, pos
);
160 var
= dest
[i
].substr(pos
+1);
161 if (TokenPos
< RawVarPath
.size())
162 var
+= val
+ RawVarPath
.substr (TokenPos
);
169 srv
+= val
+ RawVarPath
.substr (TokenPos
);
173 var
= RawVarPath
.substr (TokenPos
);
176 Destination
.push_back (make_pair(srv
, var
));
182 bool CVarPath::isFinal ()
184 if(Destination
.empty()) return true;
185 if(Destination
[0].second
.empty()) return true;
189 void CVarPath::display ()
191 nlinfo ("VP: VarPath dest = %d", Destination
.size ());
192 for (uint i
= 0; i
< Destination
.size (); i
++)
194 nlinfo ("VP: > '%s' '%s'", Destination
[i
].first
.c_str(), Destination
[i
].second
.c_str());
198 NLMISC_CATEGORISED_COMMAND(nel
, varPath
, "Test a varpath (for debug purpose)", "<rawvarpath>")
200 nlunreferenced(rawCommandString
);
201 nlunreferenced(quiet
);
202 nlunreferenced(human
);
204 if(args
.size() != 1) return false;
206 CVarPath
vp (args
[0]);
208 log
.displayNL ("VarPath contains %d destination", vp
.Destination
.size ());
209 for (uint i
= 0; i
< vp
.Destination
.size (); i
++)
211 log
.displayNL ("Dest '%s' value '%s'", vp
.Destination
[i
].first
.c_str(), vp
.Destination
[i
].second
.c_str());
213 log
.displayNL ("End of varpath");