We have a use-case for sending a dictionary back to C++. In order to then extract the values out of the CScriptDictionary, it's necessary to be able to access the type id of the values. Please consider something along these lines for inclusion in the dictionary add-on:
Index: scriptdictionary.cpp
===================================================================
--- scriptdictionary.cpp (revision 1855)
+++ scriptdictionary.cpp (working copy)
@@ -408,6 +408,32 @@
return array;
}
+// Get a map of keys to their value type id
+std::map<std::string, int> CScriptDictionary::GetKeyToValueTypeIdMap() const
+{
+ std::map<std::string, int> keyToTypeId;
+
+ for ( map<std::string, valueStruct>::const_iterator iter = dict.begin();
+ iter != dict.end();
+ ++iter )
+ {
+ keyToTypeId[iter->first] = iter->second.typeId;
+ }
+
+ return keyToTypeId;
+}
+
+// Get the type id of a key's value
+int CScriptDictionary::GetTypeIdForKey(const std::string &key) const
+{
+ map<std::string, valueStruct>::const_iterator it = dict.find(key);
+
+ if( it != dict.end() )
+ return it->second.typeId;
+ else
+ return 0;
+}
+
//--------------------------------------------------------------------------
// Generic wrappers
Index: scriptdictionary.h
===================================================================
--- scriptdictionary.h (revision 1855)
+++ scriptdictionary.h (working copy)
@@ -72,6 +72,12 @@
// Get an array of all keys
CScriptArray *GetKeys() const;
+ // Get a map of keys to their value type id
+ std::map<std::string, int> GetKeyToValueTypeIdMap() const;
+
+ // Get the type id of a key's value
+ int GetTypeIdForKey(const std::string &key) const;
+
// Garbage collections behaviours
int GetRefCount();
void SetGCFlag();
Thank you very much.