Kaydet (Commit) dd8e3a2d authored tarafından Daniel Vogelheim's avatar Daniel Vogelheim

#86004# reduced number of calls to MultiPropertySetHelper::hasProperties()

üst 9fcb172e
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: MultiPropertySetHelper.hxx,v $ * $RCSfile: MultiPropertySetHelper.hxx,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: dvo $ $Date: 2001-05-16 09:24:44 $ * last change: $Author: dvo $ $Date: 2001-05-17 16:13:53 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -86,7 +86,8 @@ namespace com { namespace sun { namespace star { ...@@ -86,7 +86,8 @@ namespace com { namespace sun { namespace star {
* *
* Given a list of property names (as sal_Char** or OUString*), it can * Given a list of property names (as sal_Char** or OUString*), it can
* query an XMultiPropertySet (or XPropertySet) which of these properties * query an XMultiPropertySet (or XPropertySet) which of these properties
* it supports (method hasProperties(...)). * it supports (method hasProperties(...)). The properties *MUST* be
* sorted alphabetically.
* *
* Then, the X(Multi)PropertySet can be queried for values, and only * Then, the X(Multi)PropertySet can be queried for values, and only
* the supported properties are queried. (method getValues(...)) The * the supported properties are queried. (method getValues(...)) The
...@@ -95,7 +96,7 @@ namespace com { namespace sun { namespace star { ...@@ -95,7 +96,7 @@ namespace com { namespace sun { namespace star {
* Finally, each property can be queried for existence * Finally, each property can be queried for existence
* (method hasProperty(...)) or its value (method (getValue(...))). * (method hasProperty(...)) or its value (method (getValue(...))).
* *
* After seom initial preparation (hasProperties, getValues) the * After some initial preparation (hasProperties, getValues) the
* MultiPropertySetHelper can be used similarly to an * MultiPropertySetHelper can be used similarly to an
* XPropertySet in that you can query the values in the places where you * XPropertySet in that you can query the values in the places where you
* need them. However, if an XMultiPropertySet is supplied, the queries * need them. However, if an XMultiPropertySet is supplied, the queries
...@@ -113,11 +114,6 @@ class MultiPropertySetHelper ...@@ -113,11 +114,6 @@ class MultiPropertySetHelper
/// property set implementation supports /// property set implementation supports
::com::sun::star::uno::Sequence< ::rtl::OUString > aPropertySequence; ::com::sun::star::uno::Sequence< ::rtl::OUString > aPropertySequence;
#ifndef PRODUCT
/// name of the implementation for which hasProperties() was called
::rtl::OUString sImplementationName;
#endif
/// an array of indices that maps from pPropertyNames indices to /// an array of indices that maps from pPropertyNames indices to
/// aPropertySequence indices /// aPropertySequence indices
sal_Int16* pSequenceIndex; sal_Int16* pSequenceIndex;
...@@ -147,19 +143,12 @@ public: ...@@ -147,19 +143,12 @@ public:
void hasProperties( const ::com::sun::star::uno::Reference< void hasProperties( const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertySetInfo> & ); ::com::sun::star::beans::XPropertySetInfo> & );
/**
* Call hasProperties for the XMultiPropertySet's info.
*/
void hasProperties( const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XMultiPropertySet> & );
/** /**
* Call hasProperties for the XPropertySet's info. * Return whether hasProperties was called
* (i.e. if we are ready to call getValues)
*/ */
void hasProperties( const ::com::sun::star::uno::Reference< sal_Bool checkedProperties();
::com::sun::star::beans::XPropertySet> & );
/** /**
* Get values from the XMultiPropertySet. * Get values from the XMultiPropertySet.
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: MultiPropertySetHelper.cxx,v $ * $RCSfile: MultiPropertySetHelper.cxx,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change: $Author: dvo $ $Date: 2001-05-14 13:04:53 $ * last change: $Author: dvo $ $Date: 2001-05-17 16:13:53 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -148,24 +148,6 @@ MultiPropertySetHelper::~MultiPropertySetHelper() ...@@ -148,24 +148,6 @@ MultiPropertySetHelper::~MultiPropertySetHelper()
} }
// STL-type comparison functor for sorting a number array accoring to
// String values in another array.
class IndexedStringLess
{
const OUString* pStringArray;
public:
IndexedStringLess(const OUString* pStrings) :
pStringArray( pStrings )
{
}
bool operator() (sal_Int16 x, sal_Int16 y) const
{
return ( pStringArray[x] < pStringArray[y] ) ? true : false;
}
};
void MultiPropertySetHelper::hasProperties( void MultiPropertySetHelper::hasProperties(
const Reference<XPropertySetInfo> & rInfo ) const Reference<XPropertySetInfo> & rInfo )
...@@ -176,25 +158,16 @@ void MultiPropertySetHelper::hasProperties( ...@@ -176,25 +158,16 @@ void MultiPropertySetHelper::hasProperties(
if ( NULL == pSequenceIndex ) if ( NULL == pSequenceIndex )
pSequenceIndex = new sal_Int16[nLength] ; pSequenceIndex = new sal_Int16[nLength] ;
// create a temporary index according to the property names
sal_Int16* pSortIndex = new sal_Int16[nLength];
for( sal_Int16 i = 0; i < nLength; i++ )
pSortIndex[i] = i;
// sort index array according to property names
IndexedStringLess aLess( pPropertyNames );
::std::sort( &pSortIndex[0], &pSortIndex[nLength], aLess );
// construct pSequenceIndex // construct pSequenceIndex
sal_Int16 nNumberOfProperties = 0; sal_Int16 nNumberOfProperties = 0;
for( i = 0; i < nLength; i++ ) for( sal_Int16 i = 0; i < nLength; i++ )
{ {
// ask for property // ask for property
sal_Bool bHasProperty = sal_Bool bHasProperty =
rInfo->hasPropertyByName( pPropertyNames[pSortIndex[i]] ); rInfo->hasPropertyByName( pPropertyNames[i] );
// set index and increment (if appropriate) // set index and increment (if appropriate)
pSequenceIndex[pSortIndex[i]]= bHasProperty ? nNumberOfProperties : -1; pSequenceIndex[i]= bHasProperty ? nNumberOfProperties : -1;
if ( bHasProperty ) if ( bHasProperty )
nNumberOfProperties++; nNumberOfProperties++;
} }
...@@ -209,46 +182,11 @@ void MultiPropertySetHelper::hasProperties( ...@@ -209,46 +182,11 @@ void MultiPropertySetHelper::hasProperties(
if ( nIndex != -1 ) if ( nIndex != -1 )
pPropertySequence[nIndex] = pPropertyNames[i]; pPropertySequence[nIndex] = pPropertyNames[i];
} }
// discard sort index
delete[] pSortIndex;
} }
sal_Bool MultiPropertySetHelper::checkedProperties()
void MultiPropertySetHelper::hasProperties(
const Reference<XMultiPropertySet> & rMultiPropertySet )
{ {
DBG_ASSERT( rMultiPropertySet.is(), "We need an XMultiPropertySet here." ); return (NULL != pSequenceIndex);
hasProperties( rMultiPropertySet->getPropertySetInfo() );
#ifndef PRODUCT
// save name of implementation, so we can later on check that
// getValues isn't called on other (wrong) implementations
Reference<XServiceInfo> xServiceInfo( rMultiPropertySet, UNO_QUERY );
if ( xServiceInfo.is() )
{
sImplementationName = xServiceInfo->getImplementationName();
}
#endif
}
void MultiPropertySetHelper::hasProperties(
const Reference<XPropertySet> & rPropertySet )
{
DBG_ASSERT( rPropertySet.is(), "We need an XPropertySet here." );
hasProperties( rPropertySet->getPropertySetInfo() );
#ifndef PRODUCT
// save name of implementation, so we can later on check that
// getValues isn't called on other (wrong) implementations
Reference<XServiceInfo> xServiceInfo( rPropertySet, UNO_QUERY );
if ( xServiceInfo.is() )
{
sImplementationName = xServiceInfo->getImplementationName();
}
#endif
} }
...@@ -258,18 +196,6 @@ void MultiPropertySetHelper::getValues( ...@@ -258,18 +196,6 @@ void MultiPropertySetHelper::getValues(
{ {
DBG_ASSERT( rMultiPropertySet.is(), "We need an XMultiPropertySet." ); DBG_ASSERT( rMultiPropertySet.is(), "We need an XMultiPropertySet." );
#ifndef PRODUCT
// check if we are called on the 'proper' implementation
Reference<XServiceInfo> xServiceInfo( rMultiPropertySet, UNO_QUERY );
if ( xServiceInfo.is() && ( sImplementationName.getLength() > 0 ) )
{
DBG_ASSERT(
sImplementationName.equals(xServiceInfo->getImplementationName()),
"getValues() called for different implementation than "
"hasProperties() was previously called for." );
}
#endif
aValues = rMultiPropertySet->getPropertyValues( aPropertySequence ); aValues = rMultiPropertySet->getPropertyValues( aPropertySequence );
pValues = aValues.getConstArray(); pValues = aValues.getConstArray();
} }
...@@ -279,18 +205,6 @@ void MultiPropertySetHelper::getValues( ...@@ -279,18 +205,6 @@ void MultiPropertySetHelper::getValues(
{ {
DBG_ASSERT( rPropertySet.is(), "We need an XPropertySet." ); DBG_ASSERT( rPropertySet.is(), "We need an XPropertySet." );
#ifndef PRODUCT
// check if we are called on the 'proper' implementation
Reference<XServiceInfo> xServiceInfo( rPropertySet, UNO_QUERY );
if ( xServiceInfo.is() && ( sImplementationName.getLength() > 0 ) )
{
DBG_ASSERT(
sImplementationName.equals(xServiceInfo->getImplementationName()),
"getValues() called for different implementation than "
"hasProperties() was previously called for." );
}
#endif
// re-alloc aValues (if necessary) and fill with values from XPropertySet // re-alloc aValues (if necessary) and fill with values from XPropertySet
sal_Int16 nSupportedPropertiesCount = sal_Int16 nSupportedPropertiesCount =
(sal_Int16)aPropertySequence.getLength(); (sal_Int16)aPropertySequence.getLength();
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: txtparae.cxx,v $ * $RCSfile: txtparae.cxx,v $
* *
* $Revision: 1.78 $ * $Revision: 1.79 $
* *
* last change: $Author: dvo $ $Date: 2001-05-14 13:05:28 $ * last change: $Author: dvo $ $Date: 2001-05-17 16:13:53 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -1195,6 +1195,23 @@ void XMLTextParagraphExport::exportText( ...@@ -1195,6 +1195,23 @@ void XMLTextParagraphExport::exportText(
bProgress, bExportParagraph ); bProgress, bExportParagraph );
} }
static const sal_Char* aParagraphPropertyNames[] =
{
"ParaChapterNumberingLevel",
"ParaConditionalStyleName",
"ParaStyleName",
"TextSection",
NULL
};
enum eParagraphPropertyNamesEnum
{
PARA_CHAPTER_NUMERBING_LEVEL = 0,
PARA_CONDITIONAL_STYLE_NAME = 1,
PARA_STYLE_NAME = 2,
TEXT_SECTION = 3
};
void XMLTextParagraphExport::exportTextContentEnumeration( void XMLTextParagraphExport::exportTextContentEnumeration(
const Reference < XEnumeration > & rContEnum, const Reference < XEnumeration > & rContEnum,
sal_Bool bAutoStyles, sal_Bool bAutoStyles,
...@@ -1209,6 +1226,8 @@ void XMLTextParagraphExport::exportTextContentEnumeration( ...@@ -1209,6 +1226,8 @@ void XMLTextParagraphExport::exportTextContentEnumeration(
sal_Bool bHasContent sal_False; sal_Bool bHasContent sal_False;
Reference<XTextSection> xCurrentTextSection = rBaseSection; Reference<XTextSection> xCurrentTextSection = rBaseSection;
MultiPropertySetHelper aPropSetHelper( aParagraphPropertyNames );
sal_Bool bHoldElement = sal_False; sal_Bool bHoldElement = sal_False;
Reference < XTextContent > xTxtCntnt; Reference < XTextContent > xTxtCntnt;
while( bHoldElement || rContEnum->hasMoreElements() ) while( bHoldElement || rContEnum->hasMoreElements() )
...@@ -1252,7 +1271,7 @@ void XMLTextParagraphExport::exportTextContentEnumeration( ...@@ -1252,7 +1271,7 @@ void XMLTextParagraphExport::exportTextContentEnumeration(
} }
else else
exportParagraph( xTxtCntnt, bAutoStyles, bProgress, exportParagraph( xTxtCntnt, bAutoStyles, bProgress,
bExportParagraph ); bExportParagraph, aPropSetHelper );
bHasContent = sal_True; bHasContent = sal_True;
} }
else if( xServiceInfo->supportsService( sTableService ) ) else if( xServiceInfo->supportsService( sTableService ) )
...@@ -1315,26 +1334,10 @@ void XMLTextParagraphExport::exportTextContentEnumeration( ...@@ -1315,26 +1334,10 @@ void XMLTextParagraphExport::exportTextContentEnumeration(
} }
} }
static const sal_Char* aParagraphPropertyNames[] =
{
"ParaStyleName",
"ParaConditionalStyleName",
"ParaChapterNumberingLevel",
"TextSection",
NULL
};
enum eParagraphPropertyNamesEnum
{
PARA_STYLE_NAME = 0,
PARA_CONDITIONAL_STYLE_NAME = 1,
PARA_CHAPTER_NUMERBING_LEVEL = 2,
TEXT_SECTION = 3
};
void XMLTextParagraphExport::exportParagraph( void XMLTextParagraphExport::exportParagraph(
const Reference < XTextContent > & rTextContent, const Reference < XTextContent > & rTextContent,
sal_Bool bAutoStyles, sal_Bool bProgress, sal_Bool bExportParagraph ) sal_Bool bAutoStyles, sal_Bool bProgress, sal_Bool bExportParagraph,
MultiPropertySetHelper& rPropSetHelper)
{ {
sal_Int8 nOutlineLevel = -1; sal_Int8 nOutlineLevel = -1;
...@@ -1345,21 +1348,22 @@ void XMLTextParagraphExport::exportParagraph( ...@@ -1345,21 +1348,22 @@ void XMLTextParagraphExport::exportParagraph(
} }
// get property set or multi property set and initialize helper // get property set or multi property set and initialize helper
MultiPropertySetHelper aPropSetHelper(aParagraphPropertyNames);
Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY ); Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY );
Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY ); Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY );
// check for supported properties // check for supported properties
// TODO: move into calling method if( !rPropSetHelper.checkedProperties() )
if( xMultiPropSet.is() ) {
aPropSetHelper.hasProperties( xMultiPropSet ); if( xMultiPropSet.is() )
else rPropSetHelper.hasProperties( xMultiPropSet->getPropertySetInfo());
aPropSetHelper.hasProperties( xPropSet ); else
rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
}
if( xMultiPropSet.is() ) if( xMultiPropSet.is() )
aPropSetHelper.getValues( xMultiPropSet ); rPropSetHelper.getValues( xMultiPropSet );
else else
aPropSetHelper.getValues( xPropSet ); rPropSetHelper.getValues( xPropSet );
Any aAny; Any aAny;
...@@ -1372,9 +1376,9 @@ void XMLTextParagraphExport::exportParagraph( ...@@ -1372,9 +1376,9 @@ void XMLTextParagraphExport::exportParagraph(
else else
{ {
OUString sStyle; OUString sStyle;
if( aPropSetHelper.hasProperty( PARA_STYLE_NAME ) ) if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) )
{ {
aAny = aPropSetHelper.getValue( PARA_STYLE_NAME ); aAny = rPropSetHelper.getValue( PARA_STYLE_NAME );
aAny >>= sStyle; aAny >>= sStyle;
} }
...@@ -1384,10 +1388,10 @@ void XMLTextParagraphExport::exportParagraph( ...@@ -1384,10 +1388,10 @@ void XMLTextParagraphExport::exportParagraph(
GetExport().AddAttribute( XML_NAMESPACE_TEXT, sXML_style_name, GetExport().AddAttribute( XML_NAMESPACE_TEXT, sXML_style_name,
sAutoStyle ); sAutoStyle );
if( aPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) ) if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
{ {
OUString sCondStyle; OUString sCondStyle;
aAny = aPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME ); aAny = rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME );
aAny >>= sCondStyle; aAny >>= sCondStyle;
if( sCondStyle != sStyle ) if( sCondStyle != sStyle )
{ {
...@@ -1400,9 +1404,9 @@ void XMLTextParagraphExport::exportParagraph( ...@@ -1400,9 +1404,9 @@ void XMLTextParagraphExport::exportParagraph(
} }
} }
if( aPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) ) if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
{ {
aAny = aPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME ); aAny = rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME );
aAny >>= nOutlineLevel; aAny >>= nOutlineLevel;
if( -1 != nOutlineLevel ) if( -1 != nOutlineLevel )
{ {
...@@ -1424,9 +1428,9 @@ void XMLTextParagraphExport::exportParagraph( ...@@ -1424,9 +1428,9 @@ void XMLTextParagraphExport::exportParagraph(
xContentEnum = xCEA->createContentEnumeration( sTextContentService ); xContentEnum = xCEA->createContentEnumeration( sTextContentService );
Reference < XTextSection > xSection; Reference < XTextSection > xSection;
if( aPropSetHelper.hasProperty( TEXT_SECTION ) ) if( rPropSetHelper.hasProperty( TEXT_SECTION ) )
{ {
aAny = aPropSetHelper.getValue( TEXT_SECTION ); aAny = rPropSetHelper.getValue( TEXT_SECTION );
aAny >>= xSection; aAny >>= xSection;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment