⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertylist.cpp

📁 Open VXI. This is a open source.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#if defined(__GNUC__) && (__GNUC__ <= 2 || (__GNUC__ == 3 && __GNUC_MINOR__ == 0))  // The G++ implementation of basic_stringstream is faulty.    VXIchar * temp;    value = VXIint(wcstol(attr.c_str(), &temp, 10));#else    std::basic_stringstream<VXIchar> attrStream(attr);    attrStream >> value;#endif    if (value < 0) {      log.StartDiagnostic(0) << L"PropertyList::GetFetchobjCacheAttrs - "        L"Invalid value for " << propName << L" of " << attr << L".";      log.EndDiagnostic();      throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC,                                           L"invalid maxage value");    }    // (1.3) Add value to fetchobj    VXIInteger * val = VXIIntegerCreate(value);    if (val == NULL) throw VXIException::OutOfMemory();    VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(),                                         INET_CACHE_CONTROL_MAX_AGE,                                         reinterpret_cast<VXIValue*>(val));  }  // (2) Attribute: maxstale  // (2.1) Get the attribute - first locally, then from the defaults.  attr.erase();  elem.GetAttribute(ATTRIBUTE_MAXSTALE, attr);  if (attr.empty()) {    switch (type) {    case PropertyList::Audio:      propName = L"audiomaxstale";     break;    case PropertyList::Document:   propName = L"documentmaxstale";  break;    case PropertyList::Grammar:    propName = L"grammarmaxstale";   break;    case PropertyList::Object:     propName = L"objectmaxstale";    break;    case PropertyList::Script:     propName = L"scriptmaxstale";    break;    }    attr = toString(GetProperty(propName));  }  // (2.2) Process the value.  if (!attr.empty()) {    VXIint value = -1;#if defined(__GNUC__) && (__GNUC__ <= 2 || (__GNUC__ == 3 && __GNUC_MINOR__ == 0))  // The G++ implementation of basic_stringstream is faulty.    VXIchar * temp;    value = VXIint(wcstol(attr.c_str(), &temp, 10));#else    std::basic_stringstream<VXIchar> attrStream(attr);    attrStream >> value;#endif    if (value < 0) {      log.StartDiagnostic(0) << L"PropertyList::GetFetchobjCacheAttrs - "        L"Invalid value for " << propName << L" of " << attr << L".";      log.EndDiagnostic();      throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC,                                           L"invalid maxstale value");    }    // (2.3) Add value to fetchobj    VXIInteger * val = VXIIntegerCreate(value);    if (val == NULL) throw VXIException::OutOfMemory();    VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(),                                         INET_CACHE_CONTROL_MAX_AGE,                                         reinterpret_cast<VXIValue*>(val));  }  // (3) Attribute: fetchtimeout  // (3.1) Get the attribute - first locally, then from the defaults.  attr.erase();  elem.GetAttribute(ATTRIBUTE_FETCHTIMEOUT, attr);  if (attr.empty())    attr = toString(GetProperty(L"fetchtimeout"));  // (3.2) Process the value.  if (!attr.empty()) {    VXIint value;    if (!ConvertTimeToMilliseconds(log, attr, value)) {      log.StartDiagnostic(0) << L"PropertyList::GetFetchobjTimeout - "        L"Invalid value for fetchtimeout of " << attr << L".";      log.EndDiagnostic();      throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC,                                           L"invalid fetchtimeout value");    }    // (3.3) Add value to fetchobj    VXIInteger * str = VXIIntegerCreate(value);    if (str == NULL) throw VXIException::OutOfMemory();    VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(),INET_TIMEOUT_OPEN,                                         reinterpret_cast<VXIValue*>(str));    if (r == VXIvalue_RESULT_SUCCESS) {      str = VXIIntegerCreate(value);      r = VXIMapSetProperty(fetchobj.GetValue(), INET_TIMEOUT_IO,                            reinterpret_cast<VXIValue*>(str));    }  }  // TBD #pragma message ("PropertyList::GetFetchobjCacheAttrs - ignoring fetchhint")}bool PropertyList::GetFetchobjSubmitAttributes(const VXMLElement & elem,                                               VXIMapHolder & submitData,                                               VXIMapHolder & fetchobj) const{  // (1) Set submit method.  // (1.1) Get the attribute - first locally, then from the defaults.  vxistring attr;  elem.GetAttribute(ATTRIBUTE_METHOD, attr);  // (1.2) Process the value.  const VXIchar * value = NULL;  if (attr == L"get" || attr.empty())    value = INET_SUBMIT_METHOD_GET;  else if (attr == L"post")    value = INET_SUBMIT_METHOD_POST;  else {    log.StartDiagnostic(0) << L"PropertyList::GetFetchobjSubmitMethod - "      L"Bad value (" << ATTRIBUTE_METHOD << L" = \"" << attr << L"\"), "      L"defaulting to " << INET_SUBMIT_METHOD_DEFAULT << L".";    log.EndDiagnostic();    value = INET_SUBMIT_METHOD_DEFAULT;  }  // (1.3) Add value to fetchobj  VXIString * str = VXIStringCreate(value);  if (str == NULL) throw VXIException::OutOfMemory();  VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(), INET_SUBMIT_METHOD,                                       reinterpret_cast<VXIValue*>(str));  if (r != VXIvalue_RESULT_SUCCESS) return false;  // (2) Get encoding for the submit.  // (2.1) Get the attribute.  if (!elem.GetAttribute(ATTRIBUTE_ENCTYPE, attr))    attr = L"application/x-www-form-urlencoded";  // (2.2) Add value to fetchobj  str = VXIStringCreate(attr.c_str());  if (str == NULL) throw VXIException::OutOfMemory();  r = VXIMapSetProperty(fetchobj.GetValue(), INET_SUBMIT_MIME_TYPE,                        reinterpret_cast<VXIValue*>(str));  if (r != VXIvalue_RESULT_SUCCESS) return false;  // (3) Set the submit data.  r = VXIMapSetProperty(fetchobj.GetValue(), INET_URL_QUERY_ARGS,                        reinterpret_cast<VXIValue*>(submitData.Release()));  return r == VXIvalue_RESULT_SUCCESS;}bool PropertyList::GetFetchobjBase(VXIMapHolder & fetchobj) const{  const VXIchar * base = GetProperty(PropertyList::BaseURI);  if (base != NULL)    AddParamValue(fetchobj, INET_URL_BASE, base);  return true;}bool PropertyList::GetFetchobjURIs(const VXMLElement & elem,                                   VXIMapHolder & fetchobj,                                   vxistring & url,                                   vxistring & fragment) const{  fragment = L"";  // The URI may be decomposed into three elements - the base, a relative  // address, and a fragment corresponding to a dialog within that module.  // (1) First the base.  GetFetchobjBase(fetchobj);  // (2) Then determine if there is a fragment at all.  if (url.empty()) return false;  vxistring::size_type pos = url.find('#');  if (pos == vxistring::npos) return true;  // (3) There was a fragment.  if (pos + 1 < url.length())    fragment = url.substr(pos + 1, url.length() - pos - 1);  url.erase(pos);  return true;}//****************************************************************//* Recognition & Grammar property related.//****************************************************************bool PropertyList::PushProperties(const VXMLElement & doc){  // (1) Find the first empty level.  unsigned int i;  for (i = 0; i < LAST_PROP; ++i)    if (properties[i].empty()) break;  if (i == LAST_PROP) {    log.LogError(999, SimpleLogger::MESSAGE, L"property list size exceeded");    return false;  }  STRINGMAP & propmap = properties[i];  // (2) Add properties at that point.  bool foundSomething = false;  for (VXMLNodeIterator it(doc); it; ++it) {    VXMLNode child = *it;    if (child.GetType() != VXMLNode::Type_VXMLElement) continue;    const VXMLElement & elem = reinterpret_cast<const VXMLElement &>(child);    VXMLElementType nodeName = elem.GetName();    if (nodeName == NODE_PROPERTY) {      vxistring name;      vxistring value;      elem.GetAttribute(ATTRIBUTE_NAME, name);      elem.GetAttribute(ATTRIBUTE_VALUE, value);      // This added the name / value pair, converting to vxistrings.      propmap.insert(propmap.end(), STRINGMAP::value_type(name, value));      foundSomething = true;    }  }  return foundSomething;}void PropertyList::PopProperties(){  unsigned int i;  for (i = 0; i < LAST_PROP; ++i)    if (properties[i].empty()) break;  if (i == 0) return;  properties[i-1].clear();}// This starts at the lowest level, inserting entries into a newly created map.// Values at higher levels will overwrite keys with identical names.//void PropertyList::GetProperties(VXIMapHolder & m) const{  // (1) Collapse the values down into a single map.  STRINGMAP collapsed;  PROPERTIES::const_iterator i;  for (i = properties.begin(); i != properties.end(); ++i) {    for (STRINGMAP::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {      collapsed[(*j).first] = (*j).second;    }  }  // (2) Create a new map & copy the values over.  STRINGMAP::const_iterator j;  for (j = collapsed.begin(); j != collapsed.end(); ++j) {    VXIString * value = VXIStringCreate((*j).second.c_str());    if (value == NULL) throw VXIException::OutOfMemory();    // Set this key.    VXIMapSetProperty(m.GetValue(), (*j).first.c_str(),                      reinterpret_cast<VXIValue *>(value));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -