10-06-2016, 08:41 AM
(This post was last modified: 10-07-2016, 06:15 AM by Rick Johnson.)
Thanks a ton, Garrett. Things are now falling into place. Here's a sample of what I've done in my POST success CB:
This worked, although the float value parsed as a string (easily handled, though). It was interesting (or puzzling) that dynamic_cast and ->clone() was the only combination that seemed to work. I had no success with any variation I tried with auto_ptr.get. Alternately, I tried this simpler code:
This worked, too, as did a hybrid of the two approaches, although I'm sure there's a much better way to code it.
It helps to understand that DictionaryPref functions look only at the top level, which solves the (remote) possibility of duplicate key names.
The reason I'm using an iterator here is that this is where I happen to be as I get more involved in PrefData structures, part of an overall learning process. I can envision situations where its iterator can be very helpful, as well as another way to become familiar with its structure and interface as PrefData and dictionaries will certainly become an important part of my plugins. Thank you so very much for your help, Garrett!
Code:
std::string postStr = this->iPOST->content();
std::string errStr = this->iPOST->error(); // no error
std::auto_ptr<hdi::core::PrefData> returnedData = hdi::core::PrefData::parse(postStr);
std::string tempStr("");
std::string valStr("");
hdi::core::StringPref strPrf;
hdi::core::StringPref* strPtr;
hdi::core::NumberPref* numPtr;
std::auto_ptr<hdi::core::PrefData> prfPtr;
bool success(false);
hdi::core::PrefData::Type typ = returnedData->dataType(); // returns DictionaryType
hdi::core::DictionaryPref* dict = dynamic_cast<hdi::core::DictionaryPref*>(returnedData->clone());
for(hdi::core::DictionaryPref::Iterator iter = dict->begin(); !iter.atEnd(); ++iter) {
tempStr = iter.key();
typ = iter.value()->dataType();
switch (typ) {
case hdi::core::PrefData::StringType:
strPtr = dynamic_cast<hdi::core::StringPref*>(iter.value()->clone());
valStr = strPtr->stringValue();
break;
case hdi::core::PrefData::NumberType:
numPtr = dynamic_cast<hdi::core::NumberPref*>(iter.value().clone());
valNum = numPtr->floatValue();
break;
default:
break;
}
free (this->iPOST);
this->iPOST = NULL;
This worked, although the float value parsed as a string (easily handled, though). It was interesting (or puzzling) that dynamic_cast and ->clone() was the only combination that seemed to work. I had no success with any variation I tried with auto_ptr.get. Alternately, I tried this simpler code:
Code:
hdi::core::DictionaryPref* dict = dynamic_cast<hdi::core::DictionaryPref*>(returnedData->clone());
success = dict->member("number", prfPtr);
typ = prfPtr->dataType();
success = (dict->getStringMember("number", strPrf));
valStr = strPrf.stringValue();
This worked, too, as did a hybrid of the two approaches, although I'm sure there's a much better way to code it.
It helps to understand that DictionaryPref functions look only at the top level, which solves the (remote) possibility of duplicate key names.
The reason I'm using an iterator here is that this is where I happen to be as I get more involved in PrefData structures, part of an overall learning process. I can envision situations where its iterator can be very helpful, as well as another way to become familiar with its structure and interface as PrefData and dictionaries will certainly become an important part of my plugins. Thank you so very much for your help, Garrett!