Line data Source code
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 : */
10 :
11 : #include "oox/helper/grabbagstack.hxx"
12 : #include <com/sun/star/uno/Sequence.hxx>
13 :
14 : namespace oox
15 : {
16 :
17 : using namespace css::beans;
18 : using namespace css::uno;
19 :
20 235 : GrabBagStack::GrabBagStack(const OUString& aName)
21 : {
22 235 : mCurrentElement.maName = aName;
23 235 : }
24 :
25 470 : GrabBagStack::~GrabBagStack()
26 470 : {}
27 :
28 2485 : OUString GrabBagStack::getCurrentName()
29 : {
30 2485 : return mCurrentElement.maName;
31 : }
32 :
33 126 : bool GrabBagStack::isStackEmpty()
34 : {
35 126 : return mStack.empty();
36 : }
37 :
38 235 : PropertyValue GrabBagStack::getRootProperty()
39 : {
40 525 : while(!mStack.empty())
41 55 : pop();
42 :
43 235 : PropertyValue aProperty;
44 235 : aProperty.Name = mCurrentElement.maName;
45 :
46 470 : Sequence<PropertyValue> aSequence(mCurrentElement.maPropertyList.size());
47 235 : PropertyValue* pSequence = aSequence.getArray();
48 235 : std::vector<PropertyValue>::iterator i;
49 631 : for (i = mCurrentElement.maPropertyList.begin(); i != mCurrentElement.maPropertyList.end(); ++i)
50 396 : *pSequence++ = *i;
51 :
52 235 : aProperty.Value = makeAny(aSequence);
53 :
54 470 : return aProperty;
55 : }
56 :
57 2927 : void GrabBagStack::appendElement(const OUString& aName, Any aAny)
58 : {
59 2927 : PropertyValue aValue;
60 2927 : aValue.Name = aName;
61 2927 : aValue.Value = aAny;
62 2927 : mCurrentElement.maPropertyList.push_back(aValue);
63 2927 : }
64 :
65 1583 : void GrabBagStack::push(const OUString& aKey)
66 : {
67 1583 : mStack.push(mCurrentElement);
68 1583 : mCurrentElement.maName = aKey;
69 1583 : mCurrentElement.maPropertyList.clear();
70 1583 : }
71 :
72 1583 : void GrabBagStack::pop()
73 : {
74 1583 : OUString aName = mCurrentElement.maName;
75 3166 : Sequence<PropertyValue> aSequence(mCurrentElement.maPropertyList.size());
76 1583 : PropertyValue* pSequence = aSequence.getArray();
77 1583 : std::vector<PropertyValue>::iterator i;
78 4114 : for (i = mCurrentElement.maPropertyList.begin(); i != mCurrentElement.maPropertyList.end(); ++i)
79 2531 : *pSequence++ = *i;
80 :
81 1583 : mCurrentElement = mStack.top();
82 1583 : mStack.pop();
83 3166 : appendElement(aName, makeAny(aSequence));
84 1583 : }
85 :
86 769 : void GrabBagStack::addInt32(const OUString& aElementName, sal_Int32 aIntValue)
87 : {
88 769 : appendElement(aElementName, makeAny(aIntValue));
89 769 : }
90 :
91 320 : void GrabBagStack::addString(const OUString& aElementName, const OUString& aStringValue)
92 : {
93 320 : appendElement(aElementName, makeAny(aStringValue));
94 320 : }
95 :
96 : } // namespace oox
97 :
98 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|