blob: e04dc948bda686c71a17f7c71cd62917f4841cee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMsgKeyArray.h"
#include "nsMemory.h"
NS_IMPL_ISUPPORTS(nsMsgKeyArray, nsIMsgKeyArray)
nsMsgKeyArray::nsMsgKeyArray()
{
#ifdef DEBUG
m_sorted = false;
#endif
}
nsMsgKeyArray::~nsMsgKeyArray()
{
}
NS_IMETHODIMP nsMsgKeyArray::Sort()
{
#ifdef DEBUG
m_sorted = true;
#endif
m_keys.Sort();
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::GetKeyAt(int32_t aIndex, nsMsgKey *aKey)
{
NS_ENSURE_ARG_POINTER(aKey);
*aKey = m_keys[aIndex];
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::GetLength(uint32_t *aLength)
{
NS_ENSURE_ARG_POINTER(aLength);
*aLength = m_keys.Length();
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::SetCapacity(uint32_t aCapacity)
{
m_keys.SetCapacity(aCapacity);
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::AppendElement(nsMsgKey aKey)
{
#ifdef DEBUG
NS_ASSERTION(!m_sorted || m_keys.Length() == 0 ||
aKey > m_keys[m_keys.Length() - 1],
"Inserting a new key at wrong position in a sorted key list!");
#endif
m_keys.AppendElement(aKey);
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::InsertElementSorted(nsMsgKey aKey)
{
// Ths function should be removed after interfaces are not frozen for TB38.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgKeyArray::GetArray(uint32_t *aCount, nsMsgKey **aKeys)
{
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aKeys);
*aCount = m_keys.Length();
*aKeys =
(nsMsgKey *) nsMemory::Clone(m_keys.begin(),
m_keys.Length() * sizeof(nsMsgKey));
return (*aKeys) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
|