From 85d289d4e5c4de17cf5dd7ce611f395227e6a071 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 10 Jul 2009 01:27:33 -0400 Subject: More work on members and member, added shared string code to handle property names. --- cmake/CMakeLists.txt | 1 + inc/dpdimension.hxx | 5 ++- inc/dpdimensions.hxx | 5 ++- inc/dphierarchies.hxx | 6 ++- inc/dphierarchy.hxx | 4 +- inc/dplevel.hxx | 60 +++++++++++++++++++++++++++-- inc/dplevels.hxx | 6 ++- inc/dpmember.hxx | 54 +++++++++++++++++++++++++- inc/dpsource.hxx | 6 +++ inc/global.hxx | 44 +++++++++++++++++++++ source/dpdimension.cxx | 9 +++-- source/dpdimensions.cxx | 6 ++- source/dphierarchies.cxx | 6 ++- source/dphierarchy.cxx | 6 ++- source/dplevel.cxx | 99 +++++++++++++++++++++++++++++++++++++++++++++++- source/dplevels.cxx | 6 ++- source/dpmember.cxx | 89 +++++++++++++++++++++++++++++++++++++++++++ source/dpmembers.cxx | 12 ++++++ source/dpsource.cxx | 7 +++- source/global.cxx | 94 +++++++++++++++++++++++++++++++++++++++++++++ 20 files changed, 499 insertions(+), 26 deletions(-) create mode 100644 source/global.cxx diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 24be023..1fd5c27 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -35,6 +35,7 @@ set(SRC_FILES ../source/dplevel.cxx ../source/dpmembers.cxx ../source/dpmember.cxx + ../source/global.cxx ) add_library(${TARGET_NAME} SHARED ${SRC_FILES}) diff --git a/inc/dpdimension.hxx b/inc/dpdimension.hxx index de699f6..a641437 100644 --- a/inc/dpdimension.hxx +++ b/inc/dpdimension.hxx @@ -9,13 +9,15 @@ namespace dpsource { +class SourceProvider; + class DPDimension : public cppu::WeakImplHelper3< ::com::sun::star::beans::XPropertySet, ::com::sun::star::sheet::XHierarchiesSupplier, ::com::sun::star::container::XNamed > { public: - DPDimension(); + DPDimension(SourceProvider* pSrc); ~DPDimension(); // XNamed @@ -82,6 +84,7 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxHierarchies; ::rtl::OUString maName; + SourceProvider* mpSource; }; } diff --git a/inc/dpdimensions.hxx b/inc/dpdimensions.hxx index dfb45d8..721c00c 100644 --- a/inc/dpdimensions.hxx +++ b/inc/dpdimensions.hxx @@ -16,12 +16,14 @@ namespace com { namespace sun { namespace star { namespace dpsource { +class SourceProvider; + class DPDimensions : public cppu::WeakImplHelper2< ::com::sun::star::container::XNameAccess, ::com::sun::star::lang::XServiceInfo > { public: - DPDimensions(); + DPDimensions(SourceProvider* pSrc); ~DPDimensions(); // XNameAccess @@ -59,6 +61,7 @@ private: private: NamedObjMapType maDimensions; + SourceProvider* mpSource; }; } diff --git a/inc/dphierarchies.hxx b/inc/dphierarchies.hxx index 25eda92..d304ce6 100644 --- a/inc/dphierarchies.hxx +++ b/inc/dphierarchies.hxx @@ -10,6 +10,7 @@ namespace dpsource { +class SourceProvider; class DPDimension; class DPHierarchies : public ::cppu::WeakImplHelper2< @@ -17,7 +18,7 @@ class DPHierarchies : public ::cppu::WeakImplHelper2< ::com::sun::star::container::XIndexAccess > { public: - explicit DPHierarchies(DPDimension* pDim); + explicit DPHierarchies(SourceProvider* pSrc, DPDimension* pDim); ~DPHierarchies(); // XNameAccess @@ -54,7 +55,8 @@ private: private: NamedObjMapType maHierarchies; - DPDimension* mpDim; + SourceProvider* mpSource; + DPDimension* mpDim; }; diff --git a/inc/dphierarchy.hxx b/inc/dphierarchy.hxx index 901bca2..ec87f9e 100644 --- a/inc/dphierarchy.hxx +++ b/inc/dphierarchy.hxx @@ -14,6 +14,7 @@ namespace com { namespace sun { namespace star { namespace dpsource { +class SourceProvider; class DPDimension; class DPHierarchy : public ::cppu::WeakImplHelper2< @@ -21,7 +22,7 @@ class DPHierarchy : public ::cppu::WeakImplHelper2< ::com::sun::star::sheet::XLevelsSupplier > { public: - explicit DPHierarchy(DPDimension* pDim); + explicit DPHierarchy(SourceProvider* pSrc, DPDimension* pDim); ~DPHierarchy(); // XNamed @@ -40,6 +41,7 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxLevels; ::rtl::OUString maName; + SourceProvider* mpSource; DPDimension* mpDim; }; diff --git a/inc/dplevel.hxx b/inc/dplevel.hxx index a661a53..69a40c1 100644 --- a/inc/dplevel.hxx +++ b/inc/dplevel.hxx @@ -1,8 +1,9 @@ #ifndef __DPLEVEL_HXX__ #define __DPLEVEL_HXX__ -#include +#include +#include #include #include @@ -14,12 +15,15 @@ namespace com { namespace sun { namespace star { namespace dpsource { -class DPLevel : public ::cppu::WeakImplHelper2< +class SourceProvider; + +class DPLevel : public ::cppu::WeakImplHelper3< + ::com::sun::star::beans::XPropertySet, ::com::sun::star::container::XNamed, ::com::sun::star::sheet::XMembersSupplier > { public: - DPLevel(); + DPLevel(SourceProvider* pSrc); ~DPLevel(); // XNamed @@ -34,8 +38,58 @@ public: virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getMembers() throw (::com::sun::star::uno::RuntimeException); + // XPropertySet + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > + SAL_CALL getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL setPropertyValue( + const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Any SAL_CALL + getPropertyValue(const ::rtl::OUString& aPropertyName) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + private: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + mxMembers; ::rtl::OUString maName; + SourceProvider* mpSource; }; } diff --git a/inc/dplevels.hxx b/inc/dplevels.hxx index dccd2f4..7edaab4 100644 --- a/inc/dplevels.hxx +++ b/inc/dplevels.hxx @@ -9,12 +9,13 @@ namespace dpsource { +class SourceProvider; class DPDimension; class DPLevels : public ::cppu::WeakImplHelper1< ::com::sun::star::container::XNameAccess > { public: - DPLevels(DPDimension* pDim); + DPLevels(SourceProvider* pSrc, DPDimension* pDim); ~DPLevels(); // XNameAccess @@ -41,7 +42,8 @@ private: private: NamedObjMapType maLevels; - DPDimension* mpDim; + SourceProvider* mpSource; + DPDimension* mpDim; }; } diff --git a/inc/dpmember.hxx b/inc/dpmember.hxx index 75d3805..b85bf02 100644 --- a/inc/dpmember.hxx +++ b/inc/dpmember.hxx @@ -1,13 +1,16 @@ #ifndef __DPMEMBER_HXX__ #define __DPMEMBER_HXX__ -#include +#include +#include #include namespace dpsource { -class DPMember : public ::cppu::WeakImplHelper1< ::com::sun::star::container::XNamed > +class DPMember : public ::cppu::WeakImplHelper2< + ::com::sun::star::beans::XPropertySet, + ::com::sun::star::container::XNamed > { public: DPMember(); @@ -20,6 +23,53 @@ public: void SAL_CALL setName(const ::rtl::OUString& aName) throw (::com::sun::star::uno::RuntimeException); + // XPropertySet + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > + SAL_CALL getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL setPropertyValue( + const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Any SAL_CALL + getPropertyValue(const ::rtl::OUString& aPropertyName) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener) + throw (::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + private: ::rtl::OUString maName; }; diff --git a/inc/dpsource.hxx b/inc/dpsource.hxx index 776c0e0..d274504 100644 --- a/inc/dpsource.hxx +++ b/inc/dpsource.hxx @@ -11,6 +11,8 @@ #include #include +#include "global.hxx" + namespace com { namespace sun { namespace star { namespace container { class XNameAccess; @@ -123,6 +125,8 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw (::com::sun::star::uno::RuntimeException); + SimpleSharedString& getSharedStrings(); + private: SourceProvider(); SourceProvider(const SourceProvider&); @@ -130,6 +134,8 @@ private: private: ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> mxDimensions; + + SimpleSharedString maSharedStrings; }; } diff --git a/inc/global.hxx b/inc/global.hxx index a2b6fff..00a91db 100644 --- a/inc/global.hxx +++ b/inc/global.hxx @@ -12,6 +12,50 @@ typedef ::__gnu_cxx::hash_map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed >, ::rtl::OUStringHash > NamedObjMapType; +// ============================================================================ + +typedef sal_Int32 StrID; + +class SimpleSharedString +{ +public: + static const StrID EMPTY = 0; + + SimpleSharedString(); + SimpleSharedString(const SimpleSharedString& r); + ~SimpleSharedString(); + + const ::rtl::OUString* getString(StrID nId); + StrID getStringId(const ::rtl::OUString& aStr); + StrID insertString(const ::rtl::OUString& aStr); + +private: + + /** internal shared string table implementation */ + class StringTable + { + public: + StrID insertString(const ::rtl::OUString& aStr); + StrID getStringId(const ::rtl::OUString& aStr); + const ::rtl::OUString* getString(StrID nId) const; + + StringTable(); + StringTable(const StringTable& r); + ~StringTable(); + + private: + typedef ::__gnu_cxx::hash_map< ::rtl::OUString, StrID, ::rtl::OUStringHash > SharedStrMap; + + ::std::vector< ::rtl::OUString > maSharedStrings; + SharedStrMap maSharedStringIds; + StrID mnStrCount; + }; + + StringTable maStringTable; +}; + +// ============================================================================ + } #endif diff --git a/source/dpdimension.cxx b/source/dpdimension.cxx index 66db901..f9a6cec 100644 --- a/source/dpdimension.cxx +++ b/source/dpdimension.cxx @@ -1,6 +1,7 @@ #include "dpdimension.hxx" #include "dphierarchies.hxx" +#include "dpsource.hxx" using ::com::sun::star::beans::XPropertyChangeListener; using ::com::sun::star::beans::XVetoableChangeListener; @@ -55,7 +56,8 @@ private: namespace dpsource { -DPDimension::DPDimension() +DPDimension::DPDimension(SourceProvider* pSrc) : + mpSource(pSrc) { } @@ -80,7 +82,7 @@ void DPDimension::setName(const OUString& aName) throw (RuntimeException) Reference DPDimension::getHierarchies() throw (RuntimeException) { if (!mxHierarchies.is()) - mxHierarchies.set(new DPHierarchies(this)); + mxHierarchies.set(new DPHierarchies(mpSource, this)); return mxHierarchies; } @@ -88,14 +90,15 @@ Reference DPDimension::getHierarchies() throw (RuntimeException) Reference DPDimension::getPropertySetInfo() throw (RuntimeException) { + StackPrinter __stack_printer__("dpsource/DPDimension::getPropertySetInfo"); return Reference(); } void DPDimension::setPropertyValue(const OUString& aPropertyName, const Any& aValue) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) { - StackPrinter __stack_printer__("dpsource/DPDimension::setPropertyValue"); fprintf(stdout, "DPDimension::setPropertyValue: prop name = '%s'\n", rtl::OUStringToOString(aPropertyName, RTL_TEXTENCODING_UTF8).getStr()); + StrID nPropName = mpSource->getSharedStrings().getStringId(aPropertyName); } Any DPDimension::getPropertyValue(const OUString& aPropertyName) diff --git a/source/dpdimensions.cxx b/source/dpdimensions.cxx index a4c2010..c98c975 100644 --- a/source/dpdimensions.cxx +++ b/source/dpdimensions.cxx @@ -1,6 +1,7 @@ #include "dpdimensions.hxx" #include "dpdimension.hxx" +#include "dpsource.hxx" #include @@ -57,7 +58,8 @@ private: namespace dpsource { -DPDimensions::DPDimensions() +DPDimensions::DPDimensions(SourceProvider* pSrc) : + mpSource(pSrc) { init(); } @@ -77,7 +79,7 @@ void DPDimensions::init() for (int i = 0; ppNames[i]; ++i) { OUString aDimName = OUString::createFromAscii(ppNames[i]); - Reference xRef(new DPDimension); + Reference xRef(new DPDimension(mpSource)); xRef->setName(aDimName); maDimensions.insert(NamedObjMapType::value_type(aDimName, xRef)); } diff --git a/source/dphierarchies.cxx b/source/dphierarchies.cxx index 206a7a7..7dcf0a7 100644 --- a/source/dphierarchies.cxx +++ b/source/dphierarchies.cxx @@ -1,6 +1,7 @@ #include "dphierarchies.hxx" #include "dphierarchy.hxx" +#include "global.hxx" #include @@ -55,7 +56,8 @@ private: namespace dpsource { -DPHierarchies::DPHierarchies(DPDimension* pDim) : +DPHierarchies::DPHierarchies(SourceProvider* pSrc, DPDimension* pDim) : + mpSource(pSrc), mpDim(pDim) { init(); @@ -71,7 +73,7 @@ void DPHierarchies::init() // For now, only create a 'flat' hierarchy. OUString aName = OUString::createFromAscii("flat"); - Reference xFlatHier(new DPHierarchy(mpDim)); + Reference xFlatHier(new DPHierarchy(mpSource, mpDim)); xFlatHier->setName(aName); maHierarchies.insert( NamedObjMapType::value_type(aName, xFlatHier)); diff --git a/source/dphierarchy.cxx b/source/dphierarchy.cxx index 216da9e..ba6e30b 100644 --- a/source/dphierarchy.cxx +++ b/source/dphierarchy.cxx @@ -1,6 +1,7 @@ #include "dphierarchy.hxx" #include "dplevels.hxx" +#include "dpsource.hxx" #include @@ -11,7 +12,8 @@ using ::rtl::OUString; namespace dpsource { -DPHierarchy::DPHierarchy(DPDimension* pDim) : +DPHierarchy::DPHierarchy(SourceProvider* pSrc, DPDimension* pDim) : + mpSource(pSrc), mpDim(pDim) { } @@ -35,7 +37,7 @@ void DPHierarchy::setName(const OUString& aName) throw (RuntimeException) Reference DPHierarchy::getLevels() throw (RuntimeException) { if (!mxLevels.is()) - mxLevels.set(new DPLevels(mpDim)); + mxLevels.set(new DPLevels(mpSource, mpDim)); return mxLevels; } diff --git a/source/dplevel.cxx b/source/dplevel.cxx index 0439234..57b3dce 100644 --- a/source/dplevel.cxx +++ b/source/dplevel.cxx @@ -1,16 +1,64 @@ #include "dplevel.hxx" +#include "dpmembers.hxx" +#include "dpsource.hxx" #include +using ::com::sun::star::beans::XPropertySetInfo; +using ::com::sun::star::beans::PropertyVetoException; +using ::com::sun::star::beans::UnknownPropertyException; +using ::com::sun::star::beans::XPropertyChangeListener; +using ::com::sun::star::beans::XVetoableChangeListener; using ::com::sun::star::container::XNameAccess; +using ::com::sun::star::lang::IllegalArgumentException; +using ::com::sun::star::lang::WrappedTargetException; using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; using ::com::sun::star::uno::RuntimeException; using ::rtl::OUString; + +#include +#include +#include + +namespace { + +class StackPrinter +{ +public: + explicit StackPrinter(const char* msg) : + msMsg(msg) + { + fprintf(stdout, "%s: --begin\n", msMsg.c_str()); + mfStartTime = getTime(); + } + + ~StackPrinter() + { + double fEndTime = getTime(); + fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime)); + } + +private: + double getTime() const + { + timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1000000.0; + } + + ::std::string msMsg; + double mfStartTime; +}; + +} + namespace dpsource { -DPLevel::DPLevel() +DPLevel::DPLevel(SourceProvider* pSrc) : + mpSource(pSrc) { } @@ -34,7 +82,54 @@ void DPLevel::setName(const OUString& aName) throw (RuntimeException) Reference DPLevel::getMembers() throw (RuntimeException) { - return Reference(); + if (!mxMembers.is()) + mxMembers.set(new DPMembers); + + return mxMembers; +} + +// XPropertySet + +Reference DPLevel::getPropertySetInfo() throw (RuntimeException) +{ + return Reference(); +} + +void DPLevel::setPropertyValue(const OUString& aPropertyName, const Any& aValue) + throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) +{ + fprintf(stdout, "DPLevel::setPropertyValue: prop name = '%s'\n", rtl::OUStringToOString(aPropertyName, RTL_TEXTENCODING_UTF8).getStr()); +} + +Any DPLevel::getPropertyValue(const OUString& aPropertyName) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ + fprintf(stdout, "DPLevel::getPropertyValue: prop name = '%s'\n", rtl::OUStringToOString(aPropertyName, RTL_TEXTENCODING_UTF8).getStr()); + return Any(); +} + +void DPLevel::addPropertyChangeListener( + const OUString& aPropertyName, const Reference& xListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPLevel::removePropertyChangeListener( + const OUString& aPropertyName, const Reference& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPLevel::addVetoableChangeListener( + const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPLevel::removeVetoableChangeListener( + const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ } } diff --git a/source/dplevels.cxx b/source/dplevels.cxx index 7311b00..db6e90d 100644 --- a/source/dplevels.cxx +++ b/source/dplevels.cxx @@ -2,6 +2,7 @@ #include "dplevels.hxx" #include "dplevel.hxx" #include "dpdimension.hxx" +#include "dpsource.hxx" #include @@ -55,7 +56,8 @@ private: namespace dpsource { -DPLevels::DPLevels(DPDimension* pDim) : +DPLevels::DPLevels(SourceProvider* pSrc, DPDimension* pDim) : + mpSource(pSrc), mpDim(pDim) { init(); @@ -72,7 +74,7 @@ void DPLevels::init() // A flat hierarchy only has one level, and its name equals the name of // the dimension. OUString aName = mpDim->getName(); - Reference xRef(new DPLevel); + Reference xRef(new DPLevel(mpSource)); xRef->setName(aName); maLevels.insert(NamedObjMapType::value_type(aName, xRef)); } diff --git a/source/dpmember.cxx b/source/dpmember.cxx index 541b21a..6d2096b 100644 --- a/source/dpmember.cxx +++ b/source/dpmember.cxx @@ -1,9 +1,54 @@ #include "dpmember.hxx" +using ::com::sun::star::beans::PropertyVetoException; +using ::com::sun::star::beans::UnknownPropertyException; +using ::com::sun::star::beans::XPropertyChangeListener; +using ::com::sun::star::beans::XPropertySetInfo; +using ::com::sun::star::beans::XVetoableChangeListener; +using ::com::sun::star::lang::IllegalArgumentException; +using ::com::sun::star::lang::WrappedTargetException; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::RuntimeException; using ::rtl::OUString; +#include +#include +#include + +namespace { + +class StackPrinter +{ +public: + explicit StackPrinter(const char* msg) : + msMsg(msg) + { + fprintf(stdout, "%s: --begin\n", msMsg.c_str()); + mfStartTime = getTime(); + } + + ~StackPrinter() + { + double fEndTime = getTime(); + fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime)); + } + +private: + double getTime() const + { + timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1000000.0; + } + + ::std::string msMsg; + double mfStartTime; +}; + +} + namespace dpsource { DPMember::DPMember() @@ -25,4 +70,48 @@ void DPMember::setName(const OUString& aName) throw (RuntimeException) maName = aName; } +// XPropertySet + +Reference DPMember::getPropertySetInfo() throw (RuntimeException) +{ + return Reference(); +} + +void DPMember::setPropertyValue(const OUString& aPropertyName, const Any& aValue) + throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) +{ + fprintf(stdout, "DPMember::setPropertyValue: prop name = '%s'\n", rtl::OUStringToOString(aPropertyName, RTL_TEXTENCODING_UTF8).getStr()); +} + +Any DPMember::getPropertyValue(const OUString& aPropertyName) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ + fprintf(stdout, "DPMember::getPropertyValue: prop name = '%s'\n", rtl::OUStringToOString(aPropertyName, RTL_TEXTENCODING_UTF8).getStr()); + return Any(); +} + +void DPMember::addPropertyChangeListener( + const OUString& aPropertyName, const Reference& xListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPMember::removePropertyChangeListener( + const OUString& aPropertyName, const Reference& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPMember::addVetoableChangeListener( + const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + +void DPMember::removeVetoableChangeListener( + const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener) + throw (UnknownPropertyException, WrappedTargetException, RuntimeException) +{ +} + } diff --git a/source/dpmembers.cxx b/source/dpmembers.cxx index ed34bc5..b04134a 100644 --- a/source/dpmembers.cxx +++ b/source/dpmembers.cxx @@ -1,5 +1,6 @@ #include "dpmembers.hxx" +#include "dpmember.hxx" #include @@ -63,6 +64,17 @@ DPMembers::~DPMembers() void DPMembers::init() { + static const char* names[] = { + "A", "B", "C", 0 + }; + + for (int i = 0; names[i]; ++i) + { + OUString aName = OUString::createFromAscii(names[i]); + Reference xRef(new DPMember); + xRef->setName(aName); + maMembers.insert(NamedObjMapType::value_type(aName, xRef)); + } } // XNameAccess diff --git a/source/dpsource.cxx b/source/dpsource.cxx index 7f239c4..a4d9f26 100644 --- a/source/dpsource.cxx +++ b/source/dpsource.cxx @@ -155,7 +155,7 @@ Reference SourceProvider::getDimensions() throw (RuntimeException) { StackPrinter __stack_printer__("dpsource/SourceProvider::getDimensions"); if (!mxDimensions.is()) - mxDimensions.set(new DPDimensions); + mxDimensions.set(new DPDimensions(this)); return mxDimensions; } @@ -181,6 +181,11 @@ void SourceProvider::removeRefreshListener(const Reference< XRefreshListener >& { } +SimpleSharedString& SourceProvider::getSharedStrings() +{ + return maSharedStrings; +} + // ============================================================================ static Sequence getSupportedServiceNames() diff --git a/source/global.cxx b/source/global.cxx new file mode 100644 index 0000000..92ecc85 --- /dev/null +++ b/source/global.cxx @@ -0,0 +1,94 @@ + +#include "global.hxx" + +using ::rtl::OUString; + +namespace dpsource { + +SimpleSharedString::StringTable::StringTable() : + mnStrCount(0) +{ + // empty string (ID = 0) + maSharedStrings.push_back(OUString()); + maSharedStringIds.insert( SharedStrMap::value_type(OUString(), mnStrCount++) ); +} + +SimpleSharedString::StringTable::StringTable(const SimpleSharedString::StringTable& r) : + maSharedStrings(r.maSharedStrings), + maSharedStringIds(r.maSharedStringIds), + mnStrCount(r.mnStrCount) +{ +} + +SimpleSharedString::StringTable::~StringTable() +{ +} + +StrID SimpleSharedString::StringTable::insertString(const OUString& aStr) +{ + SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr), + itrEnd = maSharedStringIds.end(); + + if (itr == itrEnd) + { + // new string. + maSharedStrings.push_back(aStr); + maSharedStringIds.insert( SharedStrMap::value_type(aStr, mnStrCount) ); + return mnStrCount++; + } + + // existing string. + return itr->second; +} + +StrID SimpleSharedString::StringTable::getStringId(const OUString& aStr) +{ + SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr), + itrEnd = maSharedStringIds.end(); + if (itr == itrEnd) + { + // string not found. + return insertString(aStr); + } + return itr->second; +} + +const OUString* SimpleSharedString::StringTable::getString(StrID nId) const +{ + if (nId >= mnStrCount) + return NULL; + + return &maSharedStrings[nId]; +} + +// ---------------------------------------------------------------------------- + +SimpleSharedString::SimpleSharedString() +{ +} + +SimpleSharedString::SimpleSharedString(const SimpleSharedString& r) : + maStringTable(r.maStringTable) +{ +} + +SimpleSharedString::~SimpleSharedString() +{ +} + +StrID SimpleSharedString::insertString(const OUString& aStr) +{ + return maStringTable.insertString(aStr); +} + +const OUString* SimpleSharedString::getString(StrID nId) +{ + return maStringTable.getString(nId); +} + +StrID SimpleSharedString::getStringId(const OUString& aStr) +{ + return maStringTable.getStringId(aStr); +} + +} -- cgit v1.2.3