basctl/source/basicide/sbxitem.cxx         |    7 +++++
 basctl/source/inc/sbxitem.hxx              |   12 +++++++++
 include/item/base/ItemAdministrator.hxx    |    2 -
 include/item/base/ItemBase.hxx             |   18 +++++++++++---
 include/item/base/ItemBaseStaticHelper.hxx |   35 ++++-------------------------
 include/item/base/ItemSet.hxx              |    1 
 include/item/base/SlotSet.hxx              |    3 +-
 include/item/simple/CntInt16.hxx           |   14 ++++++++++-
 include/item/simple/CntOUString.hxx        |   14 ++++++++++-
 item/source/base/ItemAdministrator.cxx     |   10 ++++----
 item/source/simple/CntInt16.cxx            |    7 +++++
 item/source/simple/CntOUString.cxx         |    7 +++++
 12 files changed, 85 insertions(+), 45 deletions(-)

New commits:
commit 75fb94c28243f1925a0e258ac26f673991f8303d
Author:     Armin Le Grand <armin.le.gr...@me.com>
AuthorDate: Fri Mar 29 20:33:12 2019 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Fri Mar 29 20:33:12 2019 +0100

    changed back to derivations of ItemBase
    
    Instead of deriving ItemBaseStaticHelper from
    ItemBase already, changed back (had this at the
    beginning) to derive from ItemBaseStaticHelper
    and ItemBase individually. This is necessary when
    an Item is derived from an already implemented one,
    else ItemBase would be derived multiple times. This
    comes at the cost of having to define some stuff
    in each implementation - not too much, though.
    Also made ItemAdministrator being the friend of
    ItemBase narrower (one access function, not whole
    class)
    
    Change-Id: I2edb3ffda0936d392b63ce477dbf02338155c5b0

diff --git a/basctl/source/basicide/sbxitem.cxx 
b/basctl/source/basicide/sbxitem.cxx
index aba31041228e..cc51573f5faf 100644
--- a/basctl/source/basicide/sbxitem.cxx
+++ b/basctl/source/basicide/sbxitem.cxx
@@ -25,8 +25,15 @@ namespace basctl
 // I2TM
 namespace Item
 {
+    // need internal access to ItemAdministrator
+    ::Item::ItemAdministrator* Sbx::GetIAdministrator() const
+    {
+        return &GetStaticAdmin();
+    }
+
     Sbx::Sbx(const ScriptDocument* pDocument, const OUString& aLibName, const 
OUString& aName, const OUString& aMethodName, ItemType eType)
     :   SbxStaticHelper(),
+        ::Item::ItemBase(),
         m_aDocument(nullptr != pDocument ? *pDocument : 
ScriptDocument::getApplicationScriptDocument()),
         m_aLibName(aLibName),
         m_aName(aName),
diff --git a/basctl/source/inc/sbxitem.hxx b/basctl/source/inc/sbxitem.hxx
index 1c89b30e2865..89ee646a35ae 100644
--- a/basctl/source/inc/sbxitem.hxx
+++ b/basctl/source/inc/sbxitem.hxx
@@ -45,8 +45,17 @@ namespace Item
     class Sbx;
     typedef ::Item::ItemBaseStaticHelper<Sbx, ::Item::IAdministrator_vector> 
SbxStaticHelper;
 
-    class Sbx final : public SbxStaticHelper
+    class Sbx final : public SbxStaticHelper, public ::Item::ItemBase
     {
+    public:
+        // SharedPtr typedef to be used handling instances of given type
+        typedef std::shared_ptr<const Sbx> SharedPtr;
+
+    private:
+        // need to offer internal access to ItemAdministrator
+        // in each derivation - just calls GetStaticAdmin internally
+        virtual ::Item::ItemAdministrator* GetIAdministrator() const override;
+
     private:
         const ScriptDocument    m_aDocument;
         const OUString          m_aLibName;
@@ -67,6 +76,7 @@ namespace Item
     public:
         virtual ~Sbx();
 
+        // SharedPtr-construtcor
         static std::shared_ptr<const Sbx> Create(
             const ScriptDocument& rDocument,
             const OUString& aLibName = OUString(),
diff --git a/include/item/base/ItemBase.hxx b/include/item/base/ItemBase.hxx
index 675af691fa1f..7511dee4a485 100644
--- a/include/item/base/ItemBase.hxx
+++ b/include/item/base/ItemBase.hxx
@@ -36,10 +36,12 @@ namespace Item
     // Base class for ItemBase and thus for all new implementation of
     // Items. Items are in general read-only instances. The constructor
     // is protected now so that no one is able to create own instances.
-    // The reason for that is that for all Items only a single value-
+    // The reason for this is that for all Items only a single value-
     // specific instance shall exist at any time, guaranteed by being
     // administrated by an instance of ItemAdministrator associated with
     // each implemented type of ItemBase Item.
+    // To create and/or implement constructors (SharedPtr-constructor's)
+    // use/implement public ::Create.* methods.
     // To construct, use the ::Create methods. These are in general
     // static member functions. These have to use the protected
     // constructor(s) from which also any number may be defined to
@@ -58,7 +60,7 @@ namespace Item
     // thus making runtime existance of Items safe. It also uses typed
     // derivations and templates to ensure throghout usage of typed
     // Items.
-    // That Items are in general read-only instances also means that there
+    // That Items are read-only instances also means that there
     // will no longer be set-methods like ::SetAny(Any& aAny) or similar.
     // Instead, implement a ::Create method for this that creates an instance
     // using a/the protected constructor, set all members from the Any (in
@@ -81,6 +83,8 @@ namespace Item
     // any Item-implementation. To support this and full typed accesses
     // to implemented Items, check out the implementation helper template
     // class 'ItemBaseStaticHelper' which should be used to implement Items.
+    // Usually Items will be derived from a definition of that helper
+    // template 'ItemBaseStaticHelper' and ::ItemBase (see examples).
     // This Base-Class ItemBase exists as minimal achor point, it sometimes
     // is useful, see e.g. helper classes ImplInvalidateItem and
     // ImplDisableItem used in ::Iset to represent ItemStates in ItemSet's.
@@ -113,6 +117,9 @@ namespace Item
     protected:
         // constructor - protected BY DEFAULT - do NOT CHANGE (!)
         // Use ::Create(...) methods in derived classes instead
+        // Note: Every derivation *needs* an empty constructor to
+        // allow unified created static methods like CreateFromAny
+        // to create instances
         ItemBase();
 
         // basic RTTI TypeCheck to secure e.g. operator== and similar
diff --git a/include/item/base/ItemBaseStaticHelper.hxx 
b/include/item/base/ItemBaseStaticHelper.hxx
index 3bcd556f9b59..35224204ad70 100644
--- a/include/item/base/ItemBaseStaticHelper.hxx
+++ b/include/item/base/ItemBaseStaticHelper.hxx
@@ -28,8 +28,7 @@
 namespace Item
 {
     // Template class which supports Item implementations using ItemBase.
-    // It allows automatic creation of default static methods. To keep
-    // things simple, it directly derives from ::ItemBase already.
+    // It allows automatic creation of default static methods.
     // It provides implementation of all static typed stuff needed to
     // implement and make available the single global static ItemAdministrator
     // which will be used for the implementation of that new Item-type.
@@ -39,14 +38,8 @@ namespace Item
     // - IAdministrator_unordered_set
     // - IAdministrator_vector
     // and the explanations/preconditions for their usage.
-    // It also defines a convenient SharedPtr type for access for each derived 
type
-    // of Item.
-    template< class TargetType, typename AdminType > class 
ItemBaseStaticHelper : public ItemBase
+    template< class TargetType, typename AdminType > class 
ItemBaseStaticHelper //: public ItemBase
     {
-    public:
-        // SharedPtr typedef to be used handling instances of given type
-        typedef std::shared_ptr<const TargetType> SharedPtr;
-
     protected:
         static ItemAdministrator& GetStaticAdmin()
         {
@@ -54,27 +47,8 @@ namespace Item
             return aAdmin;
         }
 
-        virtual ItemAdministrator* GetIAdministrator() const override
-        {
-            return &GetStaticAdmin();
-        }
-
     public:
-        // we *could* have a method like below that is able to return
-        // a non-static_pointer_cast value, thus allowing to return
-        // it as const& to the SharedPtr and to avoid constructing the
-        // TargetType::SharedPtr (less overhead). This could be used e.g.
-        // in Set::SetItem calls.
-        // Disadvantage is that the User/Programmer using it would have
-        // to be very aware what he is doing - to avoid confusion, I
-        // decided to *not* offer this currently.
-        //
-        // static const ItemBase::SharedPtr& getStaticDefault()
-        // {
-        //     return std::static_pointer_cast<const 
TargetType>(GetStaticAdmin().GetDefault());
-        // }
-
-        static std::shared_ptr<const TargetType> GetDefault()
+        static std::shared_ptr<const TargetType> GetStaticDefault()
         {
             return std::static_pointer_cast<const 
TargetType>(GetStaticAdmin().GetDefault());
         }
@@ -84,7 +58,8 @@ namespace Item
             return rCandidate && GetStaticAdmin().IsDefault(rCandidate.get());
         }
 
-        static std::shared_ptr<const TargetType> CreateFromAny(const 
AnyIDArgs& rArgs)
+        // SharedPtr-constructor
+        static std::shared_ptr<const TargetType> CreateFromAny(const 
ItemBase::AnyIDArgs& rArgs)
         {
             TargetType* pNewInstance(new TargetType());
             pNewInstance->PutValues(rArgs);
diff --git a/include/item/base/ItemSet.hxx b/include/item/base/ItemSet.hxx
index f4aad2d720e6..ed4e03176963 100644
--- a/include/item/base/ItemSet.hxx
+++ b/include/item/base/ItemSet.hxx
@@ -211,6 +211,7 @@ namespace Item
         void SetParent(const SharedPtr& rNewParent);
         const SharedPtr& GetParent() const;
 
+        // SharedPtr-construtcor
         static SharedPtr Create(const ModelSpecificItemValues::SharedPtr& 
rModelSpecificIValues);
 
         const ModelSpecificItemValues::SharedPtr& GetModelSpecificIValues() 
const;
diff --git a/include/item/base/SlotSet.hxx b/include/item/base/SlotSet.hxx
index 11789892385a..73c9fe053298 100755
--- a/include/item/base/SlotSet.hxx
+++ b/include/item/base/SlotSet.hxx
@@ -55,6 +55,7 @@ namespace Item
         SlotSet(const SlotSet&) = delete;
         SlotSet& operator=(const SlotSet&) = delete;
 
+        // SharedPtr-construtcor
         static SharedPtr Create();
 
         void SetSlot(SlotID aSlotID, const ItemBase::SharedPtr& rItem);
@@ -72,7 +73,7 @@ namespace Item
                 return std::static_pointer_cast<TargetType>(aRetval->second);
             }
 
-            return TargetType::GetDefault();
+            return TargetType::GetStaticDefault();
         }
 
         bool ClearSlot(SlotID aSlotID);
diff --git a/include/item/simple/CntInt16.hxx b/include/item/simple/CntInt16.hxx
index f55970596d2c..a0d52940d9a4 100644
--- a/include/item/simple/CntInt16.hxx
+++ b/include/item/simple/CntInt16.hxx
@@ -23,14 +23,26 @@ namespace Item
     class CntInt16;
     typedef ItemBaseStaticHelper<CntInt16, IAdministrator_set> 
CntInt16StaticHelper;
 
-    class ITEM_DLLPUBLIC CntInt16 : public CntInt16StaticHelper
+    class ITEM_DLLPUBLIC CntInt16 : public CntInt16StaticHelper, public 
ItemBase
     {
+    public:
+        // SharedPtr typedef to be used handling instances of given type
+        typedef std::shared_ptr<const CntInt16> SharedPtr;
+
+    private:
+        // need to offer internal access to ItemAdministrator
+        // in each derivation - just calls GetStaticAdmin internally
+        virtual ItemAdministrator* GetIAdministrator() const override;
+
     private:
+        // local variavbles
         sal_Int16 m_nValue;
 
     protected:
+        // allow local ItemAdministrator access to protected constructor
         friend CntInt16StaticHelper;
 
+        // SharedPtr-constructor - protected BY DEFAULT - do NOT CHANGE (!)
         CntInt16(sal_Int16 nValue = 0);
 
     public:
diff --git a/include/item/simple/CntOUString.hxx 
b/include/item/simple/CntOUString.hxx
index d11ee3d8a804..4f52ec33942e 100644
--- a/include/item/simple/CntOUString.hxx
+++ b/include/item/simple/CntOUString.hxx
@@ -24,14 +24,26 @@ namespace Item
     class CntOUString;
     typedef ItemBaseStaticHelper<CntOUString, IAdministrator_unordered_set> 
CntOUStringStaticHelper;
 
-    class ITEM_DLLPUBLIC CntOUString : public CntOUStringStaticHelper
+    class ITEM_DLLPUBLIC CntOUString : public CntOUStringStaticHelper, public 
ItemBase
     {
+    public:
+        // SharedPtr typedef to be used handling instances of given type
+        typedef std::shared_ptr<const CntOUString> SharedPtr;
+
+    private:
+        // need to offer internal access to ItemAdministrator
+        // in each derivation - just calls GetStaticAdmin internally
+        virtual ItemAdministrator* GetIAdministrator() const override;
+
     private:
+        // local variavbles
         rtl::OUString m_aValue;
 
     protected:
+        // allow local ItemAdministrator access to protected constructor
         friend CntOUStringStaticHelper;
 
+        // SharedPtr-constructor - protected BY DEFAULT - do NOT CHANGE (!)
         CntOUString(const rtl::OUString& rValue = rtl::OUString());
 
     public:
diff --git a/item/source/simple/CntInt16.cxx b/item/source/simple/CntInt16.cxx
index ae4684a2d1c5..1be28617940a 100644
--- a/item/source/simple/CntInt16.cxx
+++ b/item/source/simple/CntInt16.cxx
@@ -14,8 +14,15 @@
 
 namespace Item
 {
+    // need internal access to ItemAdministrator
+    ItemAdministrator* CntInt16::GetIAdministrator() const
+    {
+        return &GetStaticAdmin();
+    }
+
     CntInt16::CntInt16(sal_Int16 nValue)
     :   CntInt16StaticHelper(),
+        ItemBase(),
         m_nValue(nValue)
     {
     }
diff --git a/item/source/simple/CntOUString.cxx 
b/item/source/simple/CntOUString.cxx
index b1028afdcaa7..9bdd59c808f9 100644
--- a/item/source/simple/CntOUString.cxx
+++ b/item/source/simple/CntOUString.cxx
@@ -14,8 +14,15 @@
 
 namespace Item
 {
+    // need internal access to ItemAdministrator
+    ItemAdministrator* CntOUString::GetIAdministrator() const
+    {
+        return &GetStaticAdmin();
+    }
+
     CntOUString::CntOUString(const rtl::OUString& rValue)
     :   CntOUStringStaticHelper(),
+        ItemBase(),
         m_aValue(rValue)
     {
     }
commit 834dbd0a1039a6298a057bd9802452ed4450ffc7
Author:     Armin Le Grand <armin.le.gr...@me.com>
AuthorDate: Fri Mar 29 18:14:01 2019 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Fri Mar 29 18:14:01 2019 +0100

    Minimized friend access ItemAdministrator->ItemBase
    
    Change-Id: I3ecf99eeaf76da654ff164ab16a2a3cedb10d9ce

diff --git a/include/item/base/ItemAdministrator.hxx 
b/include/item/base/ItemAdministrator.hxx
index 25830152ca8f..81e90a45b308 100644
--- a/include/item/base/ItemAdministrator.hxx
+++ b/include/item/base/ItemAdministrator.hxx
@@ -68,8 +68,6 @@ namespace Item
         // instance of global default value
         ItemBase::SharedPtr m_aDefault;
 
-        void SetAdministrated(const ItemBase& rIBase) const;
-
     public:
         // constructor/destructor
         ItemAdministrator(const ItemBase* pDefault);
diff --git a/include/item/base/ItemBase.hxx b/include/item/base/ItemBase.hxx
index d7146d17a91f..675af691fa1f 100644
--- a/include/item/base/ItemBase.hxx
+++ b/include/item/base/ItemBase.hxx
@@ -98,15 +98,18 @@ namespace Item
     private:
         // flag to mark this instance being administared by an
         // ItemAdministrator. Not urgently needed due to also being
-        // able to check being administarted in the HintExpired
+        // able to check being administrated in the HintExpired
         // calls. But that is the point - when using this flag
         // at adding the instance and thus making it being actively
         // administrated it is not necessary to do that check
         // if it is administrated which means a 'find' access
         // to a kind of list which may have varying costs...
-        friend class ItemAdministrator;
         bool        m_bAdministrated;
 
+        // needed to allow access for ItemAdministrator to m_bAdministrated,
+        // but limited to a single local method in the implementation there
+        friend void SetAdministratedFromItemAdministrator(ItemBase& rIBase);
+
     protected:
         // constructor - protected BY DEFAULT - do NOT CHANGE (!)
         // Use ::Create(...) methods in derived classes instead
diff --git a/item/source/base/ItemAdministrator.cxx 
b/item/source/base/ItemAdministrator.cxx
index 796a4b844aa0..c3aa8a0b8aa2 100644
--- a/item/source/base/ItemAdministrator.cxx
+++ b/item/source/base/ItemAdministrator.cxx
@@ -13,9 +13,9 @@
 
 namespace Item
 {
-    void ItemAdministrator::SetAdministrated(const ItemBase& rIBase) const
+    void SetAdministratedFromItemAdministrator(ItemBase& rIBase)
     {
-        const_cast<ItemBase&>(rIBase).m_bAdministrated = true;
+        rIBase.m_bAdministrated = true;
     }
 
     ItemAdministrator::ItemAdministrator(const ItemBase* pDefault)
@@ -83,7 +83,7 @@ namespace Item
         else
         {
             // start using offered instance and administrate it from now
-            SetAdministrated(*pIBase);
+            
SetAdministratedFromItemAdministrator(*const_cast<ItemBase*>(pIBase));
             m_aEntries.insert(pIBase);
             return ItemBase::SharedPtr(pIBase);
         }
@@ -138,7 +138,7 @@ namespace Item
         else
         {
             // start using offered instance and administrate it from now
-            SetAdministrated(*pIBase);
+            
SetAdministratedFromItemAdministrator(*const_cast<ItemBase*>(pIBase));
             m_aEntries.insert(pIBase);
             return ItemBase::SharedPtr(pIBase);
         }
@@ -266,7 +266,7 @@ namespace Item
         else
         {
             // start using offered instance and administrate it from now
-            SetAdministrated(*pIBase);
+            
SetAdministratedFromItemAdministrator(*const_cast<ItemBase*>(pIBase));
             insert(pIBase);
             return ItemBase::SharedPtr(pIBase);
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to