bool HasPropertyType() const { for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) { if ((*it)->IsSubType<BASECLASS>()) { return true; } } return false; }
CellPropertyCollection GetPropertiesType() const { CellPropertyCollection result; for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) { if ((*it)->IsSubType<BASECLASS>()) { result.AddProperty(*it); } } return result; }
void RemoveProperty() { for (IteratorType it = mProperties.begin(); it != mProperties.end(); ++it) { if ((*it)->IsType<CLASS>()) { mProperties.erase(it); return; } } EXCEPTION("Collection does not contain the given property type."); }
Error writeCollectionToFile( const core::FilePath& filePath, const CollectionType& collection, boost::function<std::string( const typename CollectionType::value_type&)> stringifyFunction) { using namespace boost::system::errc ; // open the file stream boost::shared_ptr<std::ostream> pOfs; Error error = filePath.open_w(&pOfs, true); if (error) return error; try { // write each line for (typename CollectionType::const_iterator it = collection.begin(); it != collection.end(); ++it) { *pOfs << stringifyFunction(*it) << std::endl ; if (pOfs->fail()) return systemError(io_error, ERROR_LOCATION); } } catch(const std::exception& e) { Error error = systemError(boost::system::errc::io_error, ERROR_LOCATION); error.addProperty("what", e.what()); error.addProperty("path", filePath.absolutePath()); return error; } return Success() ; }
/** * @brief method to render sections with a given map * * @param tmplate template std::string to render * @param ctx map of values * * @return rendered std::string */ std::string template_t::render_sections(const std::string& tmplate, const Context& ctx) { // initialize data structures std::string ret = ""; std::string rest = ""; std::string::const_iterator start, end; boost::match_results<std::string::const_iterator> matches; start = tmplate.begin(); end = tmplate.end(); // return the whole template if no sections are found if (!boost::regex_search(start, end, matches, section, boost::match_default | boost::format_all)) { ret = tmplate; } // loop through sections and render while (boost::regex_search(start, end, matches, section, boost::match_default | boost::format_all)) { // std::string assignments std::string text(start, matches[0].second); std::string key(matches[2].first, matches[2].second); std::string modifier(matches[1]); // trimming boost::algorithm::trim(key); boost::algorithm::trim(modifier); std::string repl = ""; std::string show = "false"; CollectionType values; values = ctx.get(key); if (values.size() == 1) { // if we don't have a collection, we find the key and an // empty map bucket means false if (values[0].find(key) != values[0].end()) { show = values[0][key] != "" ? values[0][key] : "false"; } // if we have a collection, we want to show it if there is // something to show else { show = values[0].size() > 0 ? "true" : "false"; } } else if(values.size() > 1) { show = "true"; } // inverted section? if (modifier == "^" && show == "false") show = "true"; else if (modifier == "^" && show == "true") show = "false"; // assign replacement content if (show == "true") { if (boost::regex_search(matches[3].first, matches[3].second, section, boost::match_default | boost::format_all)) { repl.assign(template_t::render_sections(matches[3], ctx)); } else { for(CollectionType::iterator it = values.begin(); it != values.end(); ++it) { Context small_ctx; small_ctx = ctx; small_ctx.add(*it); repl += template_t::render_tags(matches[3], small_ctx); } } } else repl.assign(""); ret += boost::regex_replace(text, section, repl, boost::match_default | boost::format_all); rest.assign(matches[0].second, end); start = matches[0].second; } // append and return ret += rest; return ret; }
OleProperties::OleProperties(OleStorage& storage) : m_pStorage(storage), m_wCodePage(ENCODING_NONE) { USES_CONVERSION; IPropertySetStoragePtr spPropertySetStorage(storage.GetInternalObject()); IPropertyStorage* pPropertyStorage = 0; HRESULT hr = spPropertySetStorage->Open(FMTID_UserDefinedProperties, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropertyStorage); if(STG_E_FILENOTFOUND == hr) return; if(FAILED(hr)) { std::wostringstream os; os << L"Failed to open the user defined property set" << FMTID_UserDefinedProperties << std::ends; LOG_WS_INFO(os.str().c_str()); return; } IPropertyStoragePtr spPropertyStorage(pPropertyStorage, false); IEnumSTATPROPSTG* pEnumProp = 0; hr = spPropertyStorage->Enum(&pEnumProp); if(FAILED(hr)) // if fails, it is an Office bug { std::wostringstream os; os << _T("Failed to get an IEnumSTATPROPSTG enumerator from the property set. PropertySet ID:[") << FMTID_UserDefinedProperties << _T("]. Continue process as this is not critical.") << std::ends; LOG_WS_INFO(os.str().c_str()); return; } SetCodePageProperty(spPropertyStorage); CollectionType collection; try { IEnumSTATPROPSTGPtr spEnumProp(pEnumProp, false); STATPROPSTG propertyInfo; ZeroMemory(&propertyInfo, sizeof(STATPROPSTG)); hr = pEnumProp->Next(1, &propertyInfo, NULL); while(S_OK == hr) { PROPVARIANT propertyVariant; PropVariantInit(&propertyVariant); PROPSPEC propSpec; ZeroMemory(&propSpec, sizeof(PROPSPEC)); propSpec.ulKind = PRSPEC_PROPID; propSpec.propid = propertyInfo.propid; // Read this property. hr = spPropertyStorage->ReadMultiple(1, &propSpec, &propertyVariant); if(SUCCEEDED(hr)) { bool visibleInExplorer = false; switch(propertyVariant.vt) { case VT_LPSTR: case VT_FILETIME: case VT_I4: case VT_BOOL: visibleInExplorer = true; } std::wstring name; if(propertyInfo.lpwstrName != 0) name = W2T(propertyInfo.lpwstrName); std::wstring value; if(PIDSI_EDITTIME == propSpec.propid) value =FiletimeAsTimeSpan(propertyVariant); else { if (m_wCodePage == ENCODING_UTF8 && propertyVariant.vt == VT_LPSTR) value = ConvertPropertyFromUTF8(propertyVariant.pszVal); else value = (LPCTSTR)PropVariantToString(propertyVariant); } collection.push_back(new OleProperty(OlePropertySetGroupUserProperties, propSpec.propid, name, value, visibleInExplorer)); } hr = pEnumProp->Next(1, &propertyInfo, NULL); } m_collection = collection; } catch(...) { for(CollectionType::iterator i = collection.begin(); i != collection.end(); i++) delete *i; std::wostringstream os; os << _T("Failed to read a property. PropertySet ID:[") << FMTID_UserDefinedProperties << _T("]. Continue process as this is not critical.") << std::ends; LOG_WS_INFO(os.str().c_str()); } }