~vanvugt/mir/testfix-1665802

« back to all changes in this revision

Viewing changes to 3rd_party/android-deps/std/Vector.h

Remove android-input

This now also removes the separate thread created for every client window. .

Approved by mir-ci-bot, Daniel van Vugt, Cemil Azizoglu, Brandon Schaefer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License version 3,
6
 
 * as published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
 
 */
18
 
 
19
 
 
20
 
#ifndef MIR_ANDROID_UBUNTU_VECTOR_H_
21
 
#define MIR_ANDROID_UBUNTU_VECTOR_H_
22
 
 
23
 
#include <vector>
24
 
 
25
 
namespace mir_input
26
 
{
27
 
template <typename ValueType>
28
 
class Vector : std::vector<ValueType> // NB private inheritance of implementation
29
 
{
30
 
    typedef std::vector<ValueType> Impl;
31
 
public:
32
 
 
33
 
    using typename Impl::value_type;
34
 
    using typename Impl::iterator;
35
 
    using typename Impl::const_iterator;
36
 
 
37
 
    using Impl::clear;
38
 
    using Impl::size;
39
 
    using Impl::capacity;
40
 
    using Impl::begin;
41
 
    using Impl::end;
42
 
    using Impl::reserve;
43
 
    using Impl::empty;
44
 
    using Impl::push_back;
45
 
    using Impl::erase;
46
 
    using Impl::insert;
47
 
    using Impl::at;
48
 
    using Impl::operator[];
49
 
 
50
 
    /*
51
 
    * the following inlines add some level of compatibility with android utils.
52
 
    * Stuff that is commented out isn't used in the input stack
53
 
    */
54
 
 
55
 
    /*!
56
 
    * Constructors and destructors
57
 
    */
58
 
    Vector() = default;
59
 
    Vector(const Vector<ValueType>& /* rhs */) = default;
60
 
//  explicit Vector(const SortedVector<ValueType>& rhs);
61
 
    virtual ~Vector() {}
62
 
 
63
 
    /*! copy operator */
64
 
//  const Vector<ValueType>& operator = (const Vector<ValueType>& rhs) const;
65
 
    Vector<ValueType>& operator=(const Vector<ValueType>& /* rhs */) = default;
66
 
 
67
 
//  const Vector<ValueType>& operator = (const SortedVector<ValueType>& rhs) const;
68
 
//  Vector<ValueType>& operator = (const SortedVector<ValueType>& rhs);
69
 
 
70
 
 
71
 
    /*!
72
 
    * vector stats
73
 
    */
74
 
 
75
 
    //! returns wether or not the vector is empty
76
 
    inline bool isEmpty() const { return empty(); }
77
 
    //! setst the capacity. capacity can never be reduced less than size()
78
 
    inline ssize_t setCapacity(size_t size) { reserve(size); return size; }
79
 
 
80
 
    /*!
81
 
    * C-style array access
82
 
    */
83
 
 
84
 
    //! read-only C-style access
85
 
    inline const ValueType* array() const { return Impl::data(); }
86
 
    //! read-write C-style access
87
 
    ValueType* editArray() { return Impl::data(); }
88
 
 
89
 
    /*!
90
 
    * accessors
91
 
    */
92
 
 
93
 
    //! alternate name for operator []
94
 
    inline const ValueType& itemAt(size_t index) const { return at(index); }
95
 
    //! stack-usage of the vector. returns the top of the stack (last element)
96
 
    const ValueType& top() const { return Impl::back(); }
97
 
//  //! same as operator [], but allows to access the vector backward (from the end) with a negative index
98
 
//  const ValueType& mirrorItemAt(ssize_t index) const { return at((index >= 0) ? index : size()+index); }
99
 
 
100
 
    /*!
101
 
    * modifing the array
102
 
    */
103
 
 
104
 
    //! copy-on write support, grants write access to an item
105
 
    ValueType& editItemAt(size_t index) { return Impl::operator[](index); }
106
 
    //! grants right acces to the top of the stack (last element)
107
 
    ValueType& editTop() { return Impl::back(); }
108
 
 
109
 
    /*!
110
 
    * append/insert another vector
111
 
    */
112
 
 
113
 
//  //! insert another vector at a given index
114
 
//  ssize_t insertVectorAt(const Vector<ValueType>& vector, size_t index);
115
 
 
116
 
    //! append another vector at the end of this one
117
 
    ssize_t appendVector(const Vector<ValueType>& vector)
118
 
    {
119
 
        auto result = size();
120
 
        insert(end(), vector.begin(), vector.end());
121
 
        return result;
122
 
    }
123
 
 
124
 
 
125
 
//  //! insert an array at a given index
126
 
//  ssize_t insertArrayAt(const ValueType* array, size_t index, size_t length);
127
 
 
128
 
    //! append an array at the end of this vector
129
 
    ssize_t appendArray(const ValueType* array, size_t length)
130
 
    {
131
 
        auto result = size();
132
 
        insert(end(), array, array + length);
133
 
        return result;
134
 
    }
135
 
 
136
 
    /*!
137
 
    * add/insert/replace items
138
 
    */
139
 
 
140
 
    //! insert one or several items initialized with their default constructor
141
 
    inline ssize_t insertAt(size_t index, size_t numItems = 1) { return insertAt(ValueType(), index, numItems); }
142
 
    //! insert one or several items initialized from a prototype item
143
 
    ssize_t insertAt(const ValueType& prototype_item, size_t index, size_t numItems = 1)
144
 
    { insert(begin()+index, numItems, prototype_item); return index; }
145
 
    //! pop the top of the stack (removes the last element). No-op if the stack's empty
146
 
    inline void pop() { if (!empty()) erase(--end()); }
147
 
    //! pushes an item initialized with its default constructor
148
 
    inline void push() { push_back(ValueType()); }
149
 
    //! pushes an item on the top of the stack
150
 
    void push(const ValueType& item) { push_back(item); }
151
 
    //! same as push() but returns the index the item was added at (or an error)
152
 
    inline ssize_t add() { auto result = size(); push(); return result; }
153
 
 
154
 
    //! same as push() but returns the index the item was added at (or an error)
155
 
    ssize_t add(const ValueType& item) { auto result = size(); push(item); return result; }
156
 
//  //! replace an item with a new one initialized with its default constructor
157
 
//  inline ssize_t replaceAt(size_t index);
158
 
//  //! replace an item with a new one
159
 
//  ssize_t replaceAt(const ValueType& item, size_t index);
160
 
 
161
 
    /*!
162
 
    * remove items
163
 
    */
164
 
 
165
 
//! remove several items
166
 
    inline ssize_t removeItemsAt(size_t index, size_t count = 1)
167
 
    { auto i = begin() + index; erase(i, i+count); return index; }
168
 
//! remove one item
169
 
    inline ssize_t removeAt(size_t index)
170
 
    { auto i = begin() + index; erase(i); return index; }
171
 
 
172
 
//  /*!
173
 
//  * sort (stable) the array
174
 
//  */
175
 
//
176
 
//  typedef int (*compar_t)(const ValueType* lhs, const ValueType* rhs);
177
 
//  typedef int (*compar_r_t)(const ValueType* lhs, const ValueType* rhs, void* state);
178
 
//
179
 
//  inline status_t sort(compar_t cmp);
180
 
//  inline status_t sort(compar_r_t cmp, void* state);
181
 
//
182
 
//  // for debugging only
183
 
//  inline size_t getItemSize() const { return itemSize(); }
184
 
};
185
 
}
186
 
namespace android
187
 
{
188
 
using ::mir_input::Vector;
189
 
}
190
 
 
191
 
#endif /* MIR_ANDROID_UBUNTU_VECTOR_H_ */