LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / explorer / nochaos.cxx
blobad4bd234389a35f86a0d939e3a4f692499346de6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <svl/itempool.hxx>
23 #include <svl/poolitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <nochaos.hxx>
26 #include <memory>
29 #define WID_CHAOS_START 500
32 namespace {
34 class CntItemPool;
36 class CntStaticPoolDefaults_Impl
38 static const sal_uInt32 m_nItems = 1;
39 std::vector<SfxPoolItem*> mvDefaults;
40 std::unique_ptr<SfxItemInfo[]> m_pItemInfos;
42 private:
43 inline void Insert( SfxPoolItem* pItem );
45 public:
46 explicit CntStaticPoolDefaults_Impl();
47 ~CntStaticPoolDefaults_Impl();
48 CntStaticPoolDefaults_Impl(const CntStaticPoolDefaults_Impl&) = delete;
49 CntStaticPoolDefaults_Impl& operator=(const CntStaticPoolDefaults_Impl&) = delete;
51 std::vector<SfxPoolItem*>* GetDefaults() { return &mvDefaults; }
52 const SfxItemInfo* GetItemInfos() const { return m_pItemInfos.get(); }
56 class CntItemPool: public SfxItemPool
58 static CntItemPool* _pThePool;
59 sal_uInt16 _nRefs;
61 protected:
62 CntItemPool();
63 virtual ~CntItemPool() override;
65 public:
66 static CntItemPool* Acquire();
67 static sal_uInt16 Release();
72 // static
73 SfxItemPool* NoChaos::GetItemPool()
75 // Get and hold CHAOS item pool.
76 return CntItemPool::Acquire();
80 // static
81 sal_uInt16 NoChaos::ReleaseItemPool()
83 // Release CHAOS item pool.
84 return CntItemPool::Release();
88 // CntItemPool implementation
91 static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = nullptr;
93 // static member!
94 CntItemPool* CntItemPool::_pThePool = nullptr;
97 CntItemPool::CntItemPool()
98 : SfxItemPool( "chaos", WID_CHAOS_START, WID_CHAOS_START, nullptr ),
99 _nRefs( 0 )
101 FreezeIdRanges();
103 // Create static defaults.
104 pPoolDefs_Impl = new CntStaticPoolDefaults_Impl;
106 // Set item infos.
107 SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
109 // Set static pool default items.
110 SetDefaults( pPoolDefs_Impl->GetDefaults() );
114 //virtual
115 CntItemPool::~CntItemPool()
117 // Release static pool default items.
118 ReleaseDefaults();
122 // static
123 CntItemPool* CntItemPool::Acquire()
125 if ( !_pThePool )
126 _pThePool = new CntItemPool;
128 _pThePool->_nRefs++;
130 return _pThePool;
134 // static
135 sal_uInt16 CntItemPool::Release()
137 if ( !_pThePool )
138 return 0;
140 sal_uInt16& nRefs = _pThePool->_nRefs;
142 if ( nRefs )
143 --nRefs;
145 if ( !nRefs )
147 delete _pThePool;
148 _pThePool = nullptr;
149 delete pPoolDefs_Impl;
150 pPoolDefs_Impl = nullptr;
151 return 0;
154 return nRefs;
158 // CntStaticPoolDefaults_Impl implementation.
161 inline void CntStaticPoolDefaults_Impl::Insert(
162 SfxPoolItem* pItem /* Static Pool Default Item */ )
164 sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
166 mvDefaults[ nPos ] = pItem;
167 m_pItemInfos[ nPos ]._nSID = 0;
168 m_pItemInfos[ nPos ]._bPoolable = true;
172 CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
174 for ( sal_uInt32 n = 0; n < m_nItems; ++n )
175 delete mvDefaults[ n ];
179 CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl()
180 : mvDefaults( m_nItems, nullptr ),
181 m_pItemInfos( new SfxItemInfo [ m_nItems ] )
183 memset( m_pItemInfos.get(), 0, sizeof( SfxItemInfo ) * m_nItems );
184 Insert( new SfxStringItem( WID_CHAOS_START, OUString() ) );
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */