GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / contnr / treelistentry.cxx
blob5a97b097819befa1c561d846d15325aa8064e2cb
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 "svtools/treelistentry.hxx"
21 #include "svtools/treelist.hxx"
23 #include <limits>
25 size_t SvTreeListEntry::ITEM_NOT_FOUND = std::numeric_limits<size_t>::max();
27 void SvTreeListEntry::ClearChildren()
29 maChildren.clear();
32 void SvTreeListEntry::SetListPositions()
34 SvTreeListEntries::iterator it = maChildren.begin(), itEnd = maChildren.end();
35 sal_uLong nCur = 0;
36 for (; it != itEnd; ++it)
38 SvTreeListEntry& rEntry = *it;
39 rEntry.nListPos &= 0x80000000;
40 rEntry.nListPos |= nCur;
41 ++nCur;
44 nListPos &= (~0x80000000); // remove the invalid bit.
47 void SvTreeListEntry::InvalidateChildrensListPositions()
49 nListPos |= 0x80000000;
52 SvTreeListEntry::SvTreeListEntry() :
53 pParent(NULL),
54 nAbsPos(0),
55 nListPos(0),
56 pUserData(NULL),
57 nEntryFlags(0)
61 SvTreeListEntry::SvTreeListEntry(const SvTreeListEntry& r) :
62 pParent(NULL),
63 nAbsPos(r.nAbsPos),
64 nListPos(r.nListPos & 0x7FFFFFFF)
66 SvTreeListEntries::const_iterator it = r.maChildren.begin(), itEnd = r.maChildren.end();
67 for (; it != itEnd; ++it)
68 maChildren.push_back(new SvTreeListEntry(*it));
71 SvTreeListEntry::~SvTreeListEntry()
73 #ifdef DBG_UTIL
74 pParent = 0;
75 #endif
77 maChildren.clear();
78 maItems.clear();
81 bool SvTreeListEntry::HasChildren() const
83 return !maChildren.empty();
86 bool SvTreeListEntry::HasChildListPos() const
88 if( pParent && !(pParent->nListPos & 0x80000000) )
89 return true;
90 else return false;
93 sal_uLong SvTreeListEntry::GetChildListPos() const
95 if( pParent && (pParent->nListPos & 0x80000000) )
96 pParent->SetListPositions();
97 return ( nListPos & 0x7fffffff );
100 SvTreeListEntries& SvTreeListEntry::GetChildEntries()
102 return maChildren;
105 const SvTreeListEntries& SvTreeListEntry::GetChildEntries() const
107 return maChildren;
110 void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
112 nListPos &= 0x80000000;
113 nListPos |= ( pSource->nListPos & 0x7fffffff);
114 nAbsPos = pSource->nAbsPos;
116 SvLBoxItem* pNewItem;
117 maItems.clear();
118 ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
119 for (; it != itEnd; ++it)
121 SvLBoxItem* pItem = &(*it);
122 pNewItem = pItem->Create();
123 pNewItem->Clone(pItem);
124 maItems.push_back(pNewItem);
127 pUserData = pSource->GetUserData();
128 nEntryFlags = pSource->nEntryFlags;
131 size_t SvTreeListEntry::ItemCount() const
133 return maItems.size();
136 void SvTreeListEntry::AddItem( SvLBoxItem* pItem )
138 maItems.push_back( pItem );
141 void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
143 if ( bEnable )
144 nEntryFlags |= SV_ENTRYFLAG_CHILDREN_ON_DEMAND;
145 else
146 nEntryFlags &= (~SV_ENTRYFLAG_CHILDREN_ON_DEMAND);
149 void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, size_t nPos )
151 DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
152 if (nPos >= maItems.size())
154 // Out of bound. Bail out.
155 delete pNewItem;
156 return;
159 maItems.erase(maItems.begin()+nPos);
160 maItems.insert(maItems.begin()+nPos, pNewItem);
163 const SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos ) const
165 return &maItems[nPos];
168 SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos )
170 return &maItems[nPos];
173 namespace {
175 class FindByType : std::unary_function<SvLBoxItem, void>
177 sal_uInt16 mnId;
178 public:
179 FindByType(sal_uInt16 nId) : mnId(nId) {}
180 bool operator() (const SvLBoxItem& rItem) const
182 return rItem.GetType() == mnId;
186 class FindByPointer : std::unary_function<SvLBoxItem, void>
188 const SvLBoxItem* mpItem;
189 public:
190 FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
191 bool operator() (const SvLBoxItem& rItem) const
193 return &rItem == mpItem;
199 const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
201 ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
202 return it == maItems.end() ? NULL : &(*it);
205 SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
207 ItemsType::iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
208 return it == maItems.end() ? NULL : &(*it);
211 size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
213 ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByPointer(pItem));
214 return it == maItems.end() ? ITEM_NOT_FOUND : std::distance(maItems.begin(), it);
217 void* SvTreeListEntry::GetUserData() const
219 return pUserData;
222 void SvTreeListEntry::SetUserData( void* pPtr )
224 pUserData = pPtr;
227 bool SvTreeListEntry::HasChildrenOnDemand() const
229 return (bool)((nEntryFlags & SV_ENTRYFLAG_CHILDREN_ON_DEMAND)!=0);
232 bool SvTreeListEntry::HasInUseEmphasis() const
234 return (bool)((nEntryFlags & SV_ENTRYFLAG_IN_USE)!=0);
237 sal_uInt16 SvTreeListEntry::GetFlags() const
239 return nEntryFlags;
242 void SvTreeListEntry::SetFlags( sal_uInt16 nFlags )
244 nEntryFlags = nFlags;
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */