/** @descr Base class for the templated property wrappers. Havingacommonbaseclassallowstosetavariabletothe property'svaluewithoutexplicitknowledgeofitstype.
*/ class PropertyWrapperBase
{ public: /** @descr Create a class instance and store the given name. @paramrNameThenameoftheproperty.
*/ explicit PropertyWrapperBase (OUString aName)
: msName (std::move(aName))
{} virtual ~PropertyWrapperBase()
{}
/** @descr Abstract interface of a method for setting a variables valuetothatoftheproperty.
*/ virtualvoid SetValue (const css::uno::Any & rValue) = 0;
const OUString msName;
};
/** @descr For every property type there will be one instantiation of this templateclasswithitsownandtypespecificversionofSetValue.
*/ template<class T> class PropertyWrapper : public PropertyWrapperBase
{ public: /** @descr Create a wrapper for a property of type T.
*/
PropertyWrapper (const OUString & rName, T & rValue)
: PropertyWrapperBase (rName),
mrValue (rValue)
{}
/** descr Set the given value inside an Any to the variable referenced bythedatamember.
*/ virtualvoid SetValue (const css::uno::Any & rValue) override
{
rValue >>= mrValue;
}
private: /// Reference to a variable. Its value can be modified by a call to SetValue.
T & mrValue;
};
/** @descr Function object for comparing two OUStrings.
*/ class OUStringComparison
{ public: /// Compare two strings. Returns true if the first is before the second. booloperator() (std::u16string_view a, std::u16string_view b) const
{ return (a.compare (b) < 0);
}
};
/** @descr This class lets you get the values from an object that either supportstheinterfaceXPropertySetorXMultiPropertySet.Ifit supportsbothinterfacesthenXMultiPropertySetispreferred.
Usingitworksinthreesteps. 1.Createaninstanceandpassareferencetotheobjectfromwhichto getthepropertyvalues. 2.Makeallpropertieswhosevaluesyouwanttogetknowntotheobject byusingtheAddmethod.Thiscreatesinstancesofatemplateclass thatstoresthepropertiesnameandareferencetothevariablein whichtostoreitsvalue. 3.FinallycallGetPropertiestostorethepropertiesvaluesintothe variablesspecifiedinstep2.ThisuseseithertheXPropertySetor (preferred)theXMultiPropertySetinterface.
*/ class MultiPropertySetHandler
{ public: /** @descr Create a handler of the property set of the given object. @paramxObjectAreferencetoanyoftheobject'sinterfaces. notnecessarilyXPropertySetorXMultiPropertySet.It iscastedlatertooneofthetwoofthem.
*/ explicit MultiPropertySetHandler (css::uno::Reference<
css::uno::XInterface> xObject); /** @descr Add a property to handle. The type given implicitly by the referencetoavariableisusedtocreateaninstanceof thePropertyWrappertemplateclass. @paramsNameNameoftheproperty. @paramrValueReferencetoavariablewhosevalueissetbythe calltoGetPropertiestotheproperty'svalue.
*/ template<class T> void Add (const OUString & sName, T& rValue)
{
aPropertyList[sName] = std::make_unique<PropertyWrapper<T>>(sName, rValue);
}
/** @descr Try to get the values for all properties added with the Add method.IfpossibleitusestheXMultiPropertySet.Ifthatfails (i.e.foranUnknownPropertyExcption)oriftheinterfaceisnot supporteditusestheXPropertySetinterface. @returnIfnoneofthetwointerfacesissupportedorusingthemboth failsthensal_Falseisreturned.ElseTrueisreturned.
*/ inlinebool GetProperties();
private: /** @descr Try to use the XMultiPropertySet interface to get the property values. @paramrNameListAprecomputedandsortedsequenceofOUStrings containingthepropertiesnames. @returnTrueifvaluescouldbederived.
*/ inlinebool MultiGet (const css::uno::Sequence<
OUString> & rNameList);
/** @descr Try to use the XPropertySet interface to get the property values. @paramrNameListAprecomputedandsortedsequenceofOUStrings containingthepropertiesnames. @returnTrueifvaluescouldbederived.
*/ inlinebool SingleGet (const css::uno::Sequence<
OUString> & rNameList);
/** @descr STL map that maps from property names to polymorphic instances of PropertyWrapper.ItusesOUStringComparisonforsorting thepropertynames.
*/
::std::map< OUString, std::unique_ptr<PropertyWrapperBase>, OUStringComparison> aPropertyList;
/// The object from which to get the property values.
css::uno::Reference< css::uno::XInterface> mxObject;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.