~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/zmmf/array.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    array.h - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: array.h 1294 2007-05-13 16:28:24Z lww $
 
28
*/
 
29
 
 
30
/// \file array.h
 
31
 
 
32
#ifndef __ZMMF_ARRAY_H__
 
33
#define __ZMMF_ARRAY_H__
 
34
 
 
35
#include "zmm/zmm.h"
 
36
 
 
37
#define DEFAULT_ARRAY_CAPACITY 16
 
38
 
 
39
namespace zmm
 
40
{
 
41
 
 
42
class ArrayBase
 
43
{
 
44
public:
 
45
    ArrayBase();
 
46
    ~ArrayBase();
 
47
    void init(int capacity);
 
48
    void append(Object *el);
 
49
    void set(Object *el, int index);
 
50
    Object *get(int index);
 
51
    void remove(int index, int count);
 
52
    void removeUnordered(int index);
 
53
    void insert(int index, Object *el);
 
54
    inline int size() { return siz; }
 
55
    void optimize();
 
56
protected:
 
57
    void resize(int requiredSize);
 
58
public:
 
59
    Object **arr;
 
60
protected:
 
61
    int siz;
 
62
    int capacity;
 
63
};
 
64
 
 
65
 
 
66
template <class T>
 
67
class Array : public Object
 
68
{
 
69
protected:
 
70
    ArrayBase base;
 
71
 
 
72
public:
 
73
    inline Array() : Object()
 
74
    {
 
75
        base.init(DEFAULT_ARRAY_CAPACITY);
 
76
    }
 
77
    inline Array(int capacity) : Object()
 
78
    {
 
79
        base.init(capacity);
 
80
    }
 
81
 
 
82
    inline void append(Ref<T> el)
 
83
    {
 
84
        base.append(el.getPtr());
 
85
    }
 
86
    inline void set(Ref<T> el, int index)
 
87
    {
 
88
        base.set(el.getPtr(), index);
 
89
    }
 
90
    inline Ref<T> get(int index)
 
91
    {
 
92
        return Ref<T>( (T *)base.get(index) );
 
93
    }
 
94
    inline void remove(int index, int count=1)
 
95
    {
 
96
        base.remove(index, count);
 
97
    }
 
98
    inline void removeUnordered(int index)
 
99
    {
 
100
        base.removeUnordered(index);
 
101
    }
 
102
    inline void insert(int index, Ref<T> el)
 
103
    {
 
104
        base.insert(index, el.getPtr());
 
105
    }
 
106
    inline int size()
 
107
    {
 
108
        return base.size();
 
109
    }
 
110
    inline void optimize()
 
111
    {
 
112
        base.optimize();
 
113
    }
 
114
    
 
115
    inline Object **getObjectArray()
 
116
    {
 
117
        return base.arr;
 
118
    }
 
119
};
 
120
 
 
121
 
 
122
} // namespace
 
123
 
 
124
#endif // __ZMMF_ARRAY_H__