Changeset 849 for cpp/frams/vm/classes/collectionobj.cpp
- Timestamp:
- 01/31/19 03:47:07 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/collectionobj.cpp
r746 r849 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 50 50 ParamEntry dictionary_paramtab[] = 51 51 { 52 { "Dictionary", 1, 1 1, "Dictionary", "Dictionary associates stored values with string keys "52 { "Dictionary", 1, 12, "Dictionary", "Dictionary associates stored values with string keys " 53 53 "(\"key\" is the first argument in get/set/remove functions). Integer key can be " 54 54 "used to enumerate all elements (note that while iterating, the elements are returned in no particular order).\n" … … 70 70 { "size", 0, PARAM_NOSTATIC | PARAM_READONLY, "Element count", "d", GETONLY(size), }, 71 71 { "remove", 0, PARAM_NOSTATIC, "Remove", "p(x key)", PROCEDURE(p_remove), "Removes the named or indexed element (depending on the argument type: string or int)." }, 72 { "get", 0, PARAM_NOSTATIC, "Get element", "p x(x key)", PROCEDURE(p_get), "Retrieves the named or indexed element (depending on the argument type: string or int). null is returned for nonexistent keys.\nobject.get(key) can be shortened to 'object[key]'" },72 { "get", 0, PARAM_NOSTATIC, "Get element", "p x(x key)", PROCEDURE(p_get), "Retrieves the named or indexed element (depending on the argument type: string or int). Accessing nonexistent keys is an error (use hasKey() if necessary).\nobject.get(key) can be shortened to 'object[key]'" }, 73 73 { "getKey", 0, PARAM_NOSTATIC, "Get a key", "p s(d index)", PROCEDURE(p_getKey), "Returns the key of the indexed element (0 <= index < size)" }, 74 { "hasKey", 0, PARAM_NOSTATIC, "Check if key exists", "p d(s key)", PROCEDURE(p_hasKey), "Returns 1 (interpreted as true) if dictionary contains the supplied key, or 0 (false) otherwise.\nExample:\n if (obj.hasKey(\"a\"))\n x = obj->a;" }, 74 75 { "set", 0, PARAM_NOSTATIC, "Set element", "p x(x key,x value)", PROCEDURE(p_set), "Set element value for the specified key or index (depending on the argument type: string or int).\n" 75 76 "Returns the value previously associated with the given key (or index).\n" … … 106 107 for (int i = data.size() - 1; i >= 0; i--) 107 108 { 108 ExtValue *v = (ExtValue*)data.get(i);109 if (v) delete v;109 ExtValue *v = (ExtValue*)data.get(i); 110 if (v) delete v; 110 111 } 111 112 data.clear(); … … 221 222 { 222 223 double d = a - ((ExtValue*)data.get(i))->getDouble(); 223 s += d *d;224 s += d * d; 224 225 } 225 226 ret->setDouble(sqrt(s / max(1, data.size() - 1))); … … 391 392 ExtValue DictionaryObject::get(SString key) 392 393 { 393 ExtValue *val = (ExtValue*)hash.get(key); 394 if (val) 395 return *val; 396 return ExtValue::empty(); 394 int found = 0; 395 ExtValue *val = (ExtValue*)hash.get(key, &found); 396 if (found == 0) 397 { 398 logPrintf("Dictionary", "get", LOG_ERROR, "Key '%s' not found", key.c_str()); 399 return ExtValue::invalid(); 400 } 401 else 402 { 403 if (val) 404 return *val; 405 return ExtValue::empty(); 406 } 397 407 } 398 408 … … 422 432 } 423 433 *ret = ExtValue(); 434 } 435 436 void DictionaryObject::p_hasKey(PARAMPROCARGS) 437 { 438 int found = 0; 439 hash.get(args->getString(), &found); 440 ret->setInt(found); 424 441 } 425 442
Note: See TracChangeset
for help on using the changeset viewer.