1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qxsdstatemachinebuilder_p.h"
|
---|
43 |
|
---|
44 | #include "qxsdelement_p.h"
|
---|
45 | #include "qxsdmodelgroup_p.h"
|
---|
46 | #include "qxsdschemahelper_p.h"
|
---|
47 |
|
---|
48 | QT_BEGIN_NAMESPACE
|
---|
49 |
|
---|
50 | using namespace QPatternist;
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * This methods takes a list of objects and returns a list of list
|
---|
54 | * of all combinations the objects can be ordered.
|
---|
55 | *
|
---|
56 | * e.g. input = [ 1, 2, 3 ]
|
---|
57 | * output = [
|
---|
58 | * [ 1, 2, 3 ],
|
---|
59 | * [ 1, 3, 2 ],
|
---|
60 | * [ 2, 1, 3 ],
|
---|
61 | * [ 2, 3, 1 ],
|
---|
62 | * [ 3, 1, 2 ],
|
---|
63 | * [ 3, 2, 1 ]
|
---|
64 | * ]
|
---|
65 | *
|
---|
66 | * The method is used to create all possible combinations for the particles
|
---|
67 | * in an <all> model group.
|
---|
68 | */
|
---|
69 | template <typename T>
|
---|
70 | QList< QList<T> > allCombinations(const QList<T> &input)
|
---|
71 | {
|
---|
72 | if (input.count() == 1)
|
---|
73 | return (QList< QList<T> >() << input);
|
---|
74 |
|
---|
75 | QList< QList<T> > result;
|
---|
76 | for (int i = 0; i < input.count(); ++i) {
|
---|
77 | QList<T> subList = input;
|
---|
78 | T value = subList.takeAt(i);
|
---|
79 |
|
---|
80 | QList< QList<T> > subLists = allCombinations(subList);
|
---|
81 | for (int j = 0; j < subLists.count(); ++j) {
|
---|
82 | subLists[j].prepend(value);
|
---|
83 | }
|
---|
84 | result << subLists;
|
---|
85 | }
|
---|
86 |
|
---|
87 | return result;
|
---|
88 | }
|
---|
89 |
|
---|
90 | XsdStateMachineBuilder::XsdStateMachineBuilder(XsdStateMachine<XsdTerm::Ptr> *machine, const NamePool::Ptr &namePool, Mode mode)
|
---|
91 | : m_stateMachine(machine), m_namePool(namePool), m_mode(mode)
|
---|
92 | {
|
---|
93 | }
|
---|
94 |
|
---|
95 | XsdStateMachine<XsdTerm::Ptr>::StateId XsdStateMachineBuilder::reset()
|
---|
96 | {
|
---|
97 | Q_ASSERT(m_stateMachine);
|
---|
98 |
|
---|
99 | m_stateMachine->clear();
|
---|
100 |
|
---|
101 | return m_stateMachine->addState(XsdStateMachine<XsdTerm::Ptr>::EndState);
|
---|
102 | }
|
---|
103 |
|
---|
104 | XsdStateMachine<XsdTerm::Ptr>::StateId XsdStateMachineBuilder::addStartState(XsdStateMachine<XsdTerm::Ptr>::StateId state)
|
---|
105 | {
|
---|
106 | const XsdStateMachine<XsdTerm::Ptr>::StateId startState = m_stateMachine->addState(XsdStateMachine<XsdTerm::Ptr>::StartState);
|
---|
|
---|