#include <string_id_array.h>
Nevrax France
Definition at line 50 of file string_id_array.h.
Public Types | |
| typedef sint16 | TStringId |
Public Member Functions | |
| void | addString (const std::string &str) |
| Adds a string in the string at the end of the array. | |
| void | addString (const std::string &str, TStringId id) |
| Adds a string in the string in the array. | |
| void | clear () |
| Clears the string id array. | |
| CStringIdArray () | |
| void | display () |
| Displays all association of the array in a C style (useful to copy/paste in your C code). | |
| const std::set< std::string > & | getAskedStringArray () const |
| Returns all string in the _AskedStringArray. | |
| TStringId | getId (const std::string &str, bool IgnoreIfUnknown=false) |
| const std::set< std::string > & | getNeedToAskedStringArray () const |
| Returns all string in the _NeedToAskStringArray. | |
| std::string | getString (TStringId id) const |
| Returns the string associated to this id. | |
| void | ignoreAllUnknownId (bool b) |
| If set to true, when we ask a string with no id, we don't put it in the _NeedToAskStringArray array. | |
| void | moveNeedToAskToAskedStringArray () |
| Moves string from _NeedToAskStringArray to _AskedStringArray. | |
| void | resize (TStringId size) |
| Set the size of the _StringArray. | |
| TStringId | size () const |
| Returns the size of the _StringArray. | |
Private Attributes | |
| std::set< std::string > | _AskedStringArray |
| bool | _IgnoreAllUnknownId |
| std::set< std::string > | _NeedToAskStringArray |
| std::vector< std::string > | _StringArray |
|
|
|
Definition at line 56 of file string_id_array.h. References _IgnoreAllUnknownId.
00056 : _IgnoreAllUnknownId(false) { } |
|
|
Adds a string in the string at the end of the array.
Definition at line 77 of file string_id_array.h. References _StringArray, addString(), nlassert, and TStringId.
00078 {
00079 nlassert (_StringArray.size () < pow(2, sizeof (TStringId)*8));
00080 nlassert (!str.empty());
00081
00082 // add at the end
00083 addString (str, _StringArray.size ());
00084 }
|
|
||||||||||||
|
Adds a string in the string in the array.
Definition at line 59 of file string_id_array.h. References _AskedStringArray, _IgnoreAllUnknownId, _NeedToAskStringArray, _StringArray, nlassert, sint32, and TStringId. Referenced by NLNET::CCallbackNetBase::addCallbackArray(), addString(), NLNET::cbnbMessageRecvAssociations(), and NLNET::CCallbackNetBase::setOtherSideAssociations().
00060 {
00061 nlassert (id >= 0 && id < pow(2, sizeof (TStringId)*8));
00062 nlassert (!str.empty());
00063
00064 if (id >= (sint32) _StringArray.size())
00065 _StringArray.resize(id+1);
00066
00067 _StringArray[id] = str;
00068
00069 if (!_IgnoreAllUnknownId)
00070 {
00071 _AskedStringArray.erase (str);
00072 _NeedToAskStringArray.erase (str);
00073 }
00074 }
|
|
|
Clears the string id array.
Definition at line 179 of file string_id_array.h. References _AskedStringArray, _NeedToAskStringArray, and _StringArray.
00180 {
00181 _StringArray.clear ();
00182 _NeedToAskStringArray.clear ();
00183 _AskedStringArray.clear ();
00184 }
|
|
|
Displays all association of the array in a C style (useful to copy/paste in your C code).
Definition at line 187 of file string_id_array.h. References _StringArray, nlinfo, and uint. Referenced by NLNET::CCallbackNetBase::displayAllMyAssociations().
00188 {
00189 nlinfo ("static const char *OtherSideAssociations[] = {");
00190 for (uint i = 0; i < _StringArray.size(); i++)
00191 {
00192 nlinfo(" \"%s\",", _StringArray[i].c_str());
00193 }
00194 nlinfo ("};");
00195 }
|
|
|
Returns all string in the _AskedStringArray.
Definition at line 160 of file string_id_array.h. References _AskedStringArray. Referenced by NLNET::CCallbackNetBase::baseUpdate().
00161 {
00162 return _AskedStringArray;
00163 }
|
|
||||||||||||
|
Returns the id associated to string str. If the id is not found, the string will be added in _NeedToAskStringArray if ignoreAllUnknownId is false and IgnoreIfUnknown is false too. Definition at line 89 of file string_id_array.h. References _AskedStringArray, _IgnoreAllUnknownId, _NeedToAskStringArray, _StringArray, nlassert, and TStringId. Referenced by NLNET::cbnbMessageAskAssociations(), and NLNET::CMessage::toString().
00090 {
00091 nlassert (!str.empty());
00092
00093 // sorry for this bullshit but it's the simplest way ;)
00094 if (this == NULL) return -1;
00095
00096 for (TStringId i = 0; i < (TStringId) _StringArray.size(); i++)
00097 {
00098 if (_StringArray[i] == str)
00099 return i;
00100 }
00101
00102 if (!_IgnoreAllUnknownId && !IgnoreIfUnknown)
00103 {
00104 // the string is not found, add it to the _AskedStringArray if necessary
00105 if (_NeedToAskStringArray.find (str) == _NeedToAskStringArray.end ())
00106 {
00107 if (_AskedStringArray.find (str) == _AskedStringArray.end ())
00108 {
00109 //nldebug ("String '%s' not found, add it to _NeedToAskStringArray", str.c_str ());
00110 _NeedToAskStringArray.insert (str);
00111 }
00112 else
00113 {
00114 //nldebug ("Found '%s' in the _AskedStringArray", str.c_str ());
00115 }
00116 }
00117 else
00118 {
00119 //nldebug ("Found '%s' in the _NeedToAskStringArray", str.c_str ());
00120 }
00121 }
00122 else
00123 {
00124 //nldebug ("Ignoring unknown association ('%s')", str.c_str ());
00125 }
00126
00127 return -1;
00128 }
|
|
|
Returns all string in the _NeedToAskStringArray.
Definition at line 154 of file string_id_array.h. References _NeedToAskStringArray. Referenced by NLNET::CCallbackNetBase::baseUpdate().
00155 {
00156 return _NeedToAskStringArray;
00157 }
|
|
|
Returns the string associated to this id.
Definition at line 131 of file string_id_array.h. References _StringArray, nlassert, and TStringId. Referenced by NLNET::CCallbackServer::sendAllMyAssociations(), NLNET::CMessage::setType(), and NLNET::CMessage::toString().
00132 {
00133 // sorry for this bullshit but it's the simplest way ;)
00134 if (this == NULL) return "<NoSIDA>";
00135
00136 nlassert (id >= 0 && id < (TStringId)_StringArray.size());
00137
00138 return _StringArray[id];
00139 }
|
|
|
If set to true, when we ask a string with no id, we don't put it in the _NeedToAskStringArray array.
Definition at line 176 of file string_id_array.h. References _IgnoreAllUnknownId. Referenced by NLNET::cbcMessageRecvAllAssociations(), NLNET::CCallbackClient::CCallbackClient(), and NLNET::CCallbackNetBase::ignoreAllUnknownId().
00176 { _IgnoreAllUnknownId = b; }
|
|
|
Moves string from _NeedToAskStringArray to _AskedStringArray.
Definition at line 166 of file string_id_array.h. References _AskedStringArray, _IgnoreAllUnknownId, and _NeedToAskStringArray. Referenced by NLNET::CCallbackNetBase::baseUpdate().
00167 {
00168 if (!_IgnoreAllUnknownId)
00169 {
00170 _AskedStringArray.insert (_NeedToAskStringArray.begin(), _NeedToAskStringArray.end());
00171 _NeedToAskStringArray.clear ();
00172 }
00173 }
|
|
|
Set the size of the _StringArray.
Definition at line 142 of file string_id_array.h. References _StringArray, size, and TStringId. Referenced by NLNET::CCallbackNetBase::addCallbackArray().
00143 {
00144 _StringArray.resize (size);
00145 }
|
|
|
Returns the size of the _StringArray.
Definition at line 148 of file string_id_array.h. References _StringArray, and TStringId. Referenced by NLNET::CCallbackNetBase::addCallbackArray(), and NLNET::CCallbackServer::sendAllMyAssociations().
00149 {
00150 return _StringArray.size ();
00151 }
|
|
|
Definition at line 205 of file string_id_array.h. Referenced by addString(), clear(), getAskedStringArray(), getId(), and moveNeedToAskToAskedStringArray(). |
|
|
Definition at line 199 of file string_id_array.h. Referenced by addString(), CStringIdArray(), getId(), ignoreAllUnknownId(), and moveNeedToAskToAskedStringArray(). |
|
|
Definition at line 203 of file string_id_array.h. Referenced by addString(), clear(), getId(), getNeedToAskedStringArray(), and moveNeedToAskToAskedStringArray(). |
|
|
Definition at line 201 of file string_id_array.h. Referenced by addString(), clear(), display(), getId(), getString(), resize(), and size(). |
1.3.6