LibreOffice Module sw (master) 1
sortedarray.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SW_SOURCE_FILTER_WW8_SORTEDARRAY_HXX
21#define INCLUDED_SW_SOURCE_FILTER_WW8_SORTEDARRAY_HXX
22
23#include <osl/diagnose.h>
24#include <algorithm>
25
26//simple template that manages a static [] array by sorting at construction
27
28namespace ww
29{
34 template<class C> class SortedArray
35 {
36 private:
37 //The array e.g. of sprms.
39 size_t mnNoElems;
40
41 SortedArray(const SortedArray&) = delete;
43 public:
44 //Find an entry, return its address if found and 0 if not
45 const C *search(C aSrch) const
46 {
47 std::pair<C *, C *> aPair =
48 std::equal_range(mpWwSprmTab, mpWwSprmTab + mnNoElems, aSrch);
49 if (aPair.first != aPair.second)
50 return aPair.first;
51 else
52 return nullptr;
53 }
54
55 SortedArray(C *pWwSprmTab, size_t nNoElems)
56 : mpWwSprmTab(pWwSprmTab), mnNoElems(nNoElems)
57 {
58 OSL_ENSURE(mnNoElems && pWwSprmTab, "WW8: empty Array: Don't do that");
59 std::sort(mpWwSprmTab, mpWwSprmTab + mnNoElems);
60 }
61 };
62}
63#endif
64
65/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
simple template that manages a static array
Definition: sortedarray.hxx:35
SortedArray(C *pWwSprmTab, size_t nNoElems)
Definition: sortedarray.hxx:55
const C * search(C aSrch) const
Definition: sortedarray.hxx:45
SortedArray(const SortedArray &)=delete
SortedArray & operator=(const SortedArray &)=delete
@HTML
#define C