1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements the Container class for atrributes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <osn/osnnew.h> |
|
20 #include <osn/alfptrvector.h> |
|
21 #include <alf/alfdataexception.h> |
|
22 #include "alf/alfattribute.h" |
|
23 #include "alf/alfattributecontainer.h" |
|
24 #include <libc/string.h> |
|
25 #include <stdexcept> |
|
26 #include <assert.h> // from libc |
|
27 |
|
28 namespace Alf |
|
29 { |
|
30 |
|
31 |
|
32 /** |
|
33 * Attribute container implementation. |
|
34 */ |
|
35 class AlfAttributeContainerImpl |
|
36 { |
|
37 public: |
|
38 osncore::AlfPtrVector<AlfAttribute> mAttributes; |
|
39 AlfAttributeContainer::Type mType; |
|
40 uint mTime; |
|
41 }; |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Constructor. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 |
|
50 OSN_EXPORT AlfAttributeContainer::AlfAttributeContainer(Type aType) : |
|
51 mData(new (EMM) AlfAttributeContainerImpl()) |
|
52 { |
|
53 mData->mType = aType; |
|
54 mData->mTime = 0; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Destructor. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 OSN_EXPORT AlfAttributeContainer::~AlfAttributeContainer() |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Gets the type of the container. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 OSN_EXPORT AlfAttributeContainer::Type AlfAttributeContainer::type() const |
|
71 { |
|
72 return mData->mType; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Adds a new attribute to the container. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 OSN_EXPORT void AlfAttributeContainer::addAttribute(AlfAttribute* aAttribute) |
|
80 { |
|
81 mData->mAttributes.resize(mData->mAttributes.count() +1 ); |
|
82 mData->mAttributes.insert(mData->mAttributes.count(), aAttribute); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Returns the attribute count. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 OSN_EXPORT unsigned int AlfAttributeContainer::attributeCount()const |
|
90 { |
|
91 return mData->mAttributes.count(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Returns the attribute. |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 OSN_EXPORT AlfAttribute& AlfAttributeContainer::getAttribute( |
|
99 unsigned int aIndex) const |
|
100 { |
|
101 // invariant |
|
102 assert(aIndex < mData->mAttributes.count()); |
|
103 if (aIndex >= mData->mAttributes.count()) |
|
104 { |
|
105 ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") |
|
106 } |
|
107 |
|
108 return *(mData->mAttributes[aIndex]); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Returns the attribute. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 OSN_EXPORT AlfAttribute& AlfAttributeContainer::getAttributeByName( |
|
116 const char * aName) const |
|
117 { |
|
118 for (TInt i=0; i < mData->mAttributes.count(); i++) |
|
119 { |
|
120 if (!strcmp(mData->mAttributes[i]->name(), aName)) |
|
121 { |
|
122 return *(mData->mAttributes[i]); |
|
123 } |
|
124 } |
|
125 ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // Removes the attribute. |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 OSN_EXPORT void AlfAttributeContainer::removeAttribute(unsigned int aIndex) |
|
133 { |
|
134 assert(aIndex < mData->mAttributes.count()); |
|
135 if (aIndex >= mData->mAttributes.count()) |
|
136 { |
|
137 ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") |
|
138 } |
|
139 |
|
140 mData->mAttributes.remove(aIndex); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Sets the animation time of the attribute container. |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 OSN_EXPORT void AlfAttributeContainer::setTime(unsigned int aTime) |
|
148 { |
|
149 mData->mTime = aTime; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // Returns the animation time of the attribute container. |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 OSN_EXPORT unsigned int AlfAttributeContainer::getTime()const |
|
157 { |
|
158 return mData->mTime; |
|
159 } |
|
160 |
|
161 } // Alf |
|
162 |
|