AngelScript

dictionary object

Path: /sdk/add_on/scriptdictionary/

The dictionary object maps string values to values or objects of other types.

Register with `RegisterScriptDictionary(asIScriptEngine*)`.

## Public C++ interface

    class CScriptDictionary
    {
    public:
      // Memory management
      CScriptDictionary(asIScriptEngine *engine);
      void AddRef() const;
      void Release() const;

      // Perform a shallow copy of the other dictionary
      CScriptDictionary &operator=(const CScriptDictionary &other);

      // Sets/Gets a variable type value for a key
      void Set(const std::string &key, void *value, int typeId);
      bool Get(const std::string &key, void *value, int typeId) const;

      // Sets/Gets an integer number value for a key
      void Set(const std::string &key, asINT64 &value);
      bool Get(const std::string &key, asINT64 &value) const;

      // Sets/Gets a real number value for a key
      void Set(const std::string &key, double &value);
      bool Get(const std::string &key, double &value) const;

      // Get an array of all keys
      CScriptArray *GetKeys() const;

      // Returns true if the key is set
      bool Exists(const std::string &key) const;

      // Deletes the key
      void Delete(const std::string &key);

      // Deletes all keys
      void DeleteAll();
    };

## Public script interface

      class dictionary
      {
        dictionary &opAssign(const dictionary &in other);

        void set(const string &in key, ? &in value);
        bool get(const string &in key, ? &out value) const;

        void set(const string &in key, int64 &in value);
        bool get(const string &in key, int64 &out value) const;

        void set(const string &in key, double &in value);
        bool get(const string &in key, double &out value) const;

        array<string> @getKeys() const;

        bool exists(const string &in key) const;
        void delete(const string &in key);
        void deleteAll();
      }

## Script example

      dictionary dict;
      obj object;
      obj @handle;

      dict.set("one", 1);
      dict.set("object", object);
      dict.set("handle", @handle);

      if( dict.exists("one") )
      {
        bool found = dict.get("handle", @handle);
        if( found )
        {
          dict.delete("object");
        }
      }

      dict.deleteAll();