/src/libreoffice/editeng/inc/EditLineList.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include "EditLine.hxx" |
23 | | |
24 | | #include <memory> |
25 | | #include <vector> |
26 | | #include <sal/types.h> |
27 | | #include <tools/debug.hxx> |
28 | | |
29 | | class EditLineList |
30 | | { |
31 | | typedef std::vector<std::unique_ptr<EditLine>> LinesType; |
32 | | LinesType maLines; |
33 | | |
34 | | public: |
35 | 13.4M | EditLineList() = default; |
36 | | |
37 | 2.51M | void Reset() { maLines.clear(); } |
38 | | |
39 | | void DeleteFromLine(sal_Int32 nDelFrom) |
40 | 1 | { |
41 | 1 | assert(nDelFrom <= (static_cast<sal_Int32>(maLines.size()) - 1)); |
42 | 1 | LinesType::iterator it = maLines.begin(); |
43 | 1 | std::advance(it, nDelFrom); |
44 | 1 | maLines.erase(it, maLines.end()); |
45 | 1 | } |
46 | | |
47 | | sal_Int32 FindLine(sal_Int32 nChar, bool bInclEnd) |
48 | 0 | { |
49 | 0 | sal_Int32 n = maLines.size(); |
50 | 0 | for (sal_Int32 i = 0; i < n; ++i) |
51 | 0 | { |
52 | 0 | const EditLine& rLine = *maLines[i]; |
53 | 0 | if ((bInclEnd && (rLine.GetEnd() >= nChar)) || (rLine.GetEnd() > nChar)) |
54 | 0 | { |
55 | 0 | return i; |
56 | 0 | } |
57 | 0 | } |
58 | | |
59 | 0 | DBG_ASSERT(!bInclEnd, "Line not found: FindLine"); |
60 | 0 | return n - 1; |
61 | 0 | } |
62 | | |
63 | 42.5M | sal_Int32 Count() const { return maLines.size(); } |
64 | 4.64M | const EditLine& operator[](sal_Int32 nPos) const { return *maLines[nPos]; } |
65 | 32.5M | EditLine& operator[](sal_Int32 nPos) { return *maLines[nPos]; } |
66 | | |
67 | 6.52M | void Append(std::unique_ptr<EditLine> pEditLine) { maLines.push_back(std::move(pEditLine)); } |
68 | | |
69 | | void Insert(sal_Int32 nPos, std::unique_ptr<EditLine> pEditLine) |
70 | 1.27M | { |
71 | 1.27M | maLines.insert(maLines.begin() + nPos, std::move(pEditLine)); |
72 | 1.27M | } |
73 | | }; |
74 | | |
75 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |