Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | List of all members
QPatternist::XsdStateMachineBuilder Class Reference

A helper class to build up validation state machines. More...

#include <qxsdstatemachinebuilder_p.h>

Inheritance diagram for QPatternist::XsdStateMachineBuilder:
QSharedData

Public Types

enum  Mode { CheckingMode, ValidatingMode }
 
typedef QExplicitlySharedDataPointer< XsdStateMachineBuilderPtr
 

Public Functions

XsdStateMachine< XsdTerm::Ptr >::StateId addStartState (XsdStateMachine< XsdTerm::Ptr >::StateId state)
 
XsdStateMachine< XsdTerm::Ptr >::StateId buildParticle (const XsdParticle::Ptr &particle, XsdStateMachine< XsdTerm::Ptr >::StateId endState)
 
XsdStateMachine< XsdTerm::Ptr >::StateId buildTerm (const XsdTerm::Ptr &term, XsdStateMachine< XsdTerm::Ptr >::StateId endState)
 
XsdStateMachine< XsdTerm::Ptr >::StateId reset ()
 
 XsdStateMachineBuilder (XsdStateMachine< XsdTerm::Ptr > *machine, const NamePool::Ptr &namePool, Mode mode=CheckingMode)
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Static Public Functions

static QHash< XsdTerm::Ptr, XsdParticle::PtrparticleLookupMap (const XsdParticle::Ptr &particle)
 

Properties

Mode m_mode
 
NamePool::Ptr m_namePool
 
XsdStateMachine< XsdTerm::Ptr > * m_stateMachine
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

A helper class to build up validation state machines.

Author
Tobias Koenig tobia.nosp@m.s.ko.nosp@m.enig@.nosp@m.noki.nosp@m.a.com

Definition at line 74 of file qxsdstatemachinebuilder_p.h.

Typedefs

◆ Ptr

Definition at line 77 of file qxsdstatemachinebuilder_p.h.

Enumerations

◆ Mode

Constructors and Destructors

◆ XsdStateMachineBuilder()

XsdStateMachineBuilder::XsdStateMachineBuilder ( XsdStateMachine< XsdTerm::Ptr > *  machine,
const NamePool::Ptr namePool,
Mode  mode = CheckingMode 
)

Creates a new state machine builder.

Parameters
machineThe state machine it should work on.
namePoolThe name pool used by all schema components.
modeThe mode the machine shall be build for.

Definition at line 90 of file qxsdstatemachinebuilder.cpp.

Functions

◆ addStartState()

XsdStateMachine< XsdTerm::Ptr >::StateId XsdStateMachineBuilder::addStartState ( XsdStateMachine< XsdTerm::Ptr >::StateId  state)

Prepends a start state to the given state. That is needed to allow the conversion of the state machine from a FSA to a DFA.

Definition at line 104 of file qxsdstatemachinebuilder.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::createAndPushStateMachine(), QPatternist::XsdParticleChecker::isUPAConform(), and QPatternist::XsdParticleChecker::subsumes().

105 {
107  m_stateMachine->addEpsilonTransition(startState, state);
108 
109  return startState;
110 }
XsdStateMachine< XsdTerm::Ptr > * m_stateMachine
A state machine used for evaluation.

◆ buildParticle()

XsdStateMachine< XsdTerm::Ptr >::StateId XsdStateMachineBuilder::buildParticle ( const XsdParticle::Ptr particle,
XsdStateMachine< XsdTerm::Ptr >::StateId  endState 
)

Creates the state machine for the given particle that should have the given endState.

Returns
The new start state.

Definition at line 115 of file qxsdstatemachinebuilder.cpp.

Referenced by buildTerm(), QPatternist::XsdValidatingInstanceReader::createAndPushStateMachine(), QPatternist::XsdParticleChecker::isUPAConform(), and QPatternist::XsdParticleChecker::subsumes().

116 {
117  XsdStateMachine<XsdTerm::Ptr>::StateId currentStartState = endState;
118  XsdStateMachine<XsdTerm::Ptr>::StateId currentEndState = endState;
119 
120  // 2
121  if (particle->maximumOccursUnbounded()) {
123  const XsdStateMachine<XsdTerm::Ptr>::StateId n = buildTerm(particle->term(), t);
124 
125  m_stateMachine->addEpsilonTransition(t, n);
126  m_stateMachine->addEpsilonTransition(n, endState);
127 
128  currentEndState = t;
129  currentStartState = t;
130  } else { // 3
131  int count = (particle->maximumOccurs() - particle->minimumOccurs());
132  if (count > 100)
133  count = 100;
134 
135  for (int i = 0; i < count; ++i) {
136  currentStartState = buildTerm(particle->term(), currentEndState);
137  m_stateMachine->addEpsilonTransition(currentStartState, endState);
138  currentEndState = currentStartState;
139  }
140  }
141 
142  int minOccurs = particle->minimumOccurs();
143  if (minOccurs > 100)
144  minOccurs = 100;
145 
146  for (int i = 0; i < minOccurs; ++i) {
147  currentStartState = buildTerm(particle->term(), currentEndState);
148  currentEndState = currentStartState;
149  }
150 
151  return currentStartState;
152 }
XsdTerm::Ptr term() const
XsdStateMachine< XsdTerm::Ptr >::StateId buildTerm(const XsdTerm::Ptr &term, XsdStateMachine< XsdTerm::Ptr >::StateId endState)
unsigned int maximumOccurs() const
unsigned int minimumOccurs() const
XsdStateMachine< XsdTerm::Ptr > * m_stateMachine
bool maximumOccursUnbounded() const
A state machine used for evaluation.

◆ buildTerm()

XsdStateMachine< XsdTerm::Ptr >::StateId XsdStateMachineBuilder::buildTerm ( const XsdTerm::Ptr term,
XsdStateMachine< XsdTerm::Ptr >::StateId  endState 
)

Creates the state machine for the given term that should have the given endState.

Returns
The new start state.

Definition at line 157 of file qxsdstatemachinebuilder.cpp.

Referenced by buildParticle().

158 {
159  if (term->isWildcard()) { // 1
161  m_stateMachine->addTransition(b, term, endState);
162  return b;
163  } else if (term->isElement()) { // 2
165  m_stateMachine->addTransition(b, term, endState);
166 
167  const XsdElement::Ptr element(term);
168  if (m_mode == CheckingMode) {
169  const XsdElement::WeakList substGroups = element->substitutionGroups();
170  for (int i = 0; i < substGroups.count(); ++i)
171  m_stateMachine->addTransition(b, XsdElement::Ptr(substGroups.at(i)), endState);
172  } else if (m_mode == ValidatingMode) {
173  const XsdElement::WeakList substGroups = element->substitutionGroups();
174  for (int i = 0; i < substGroups.count(); ++i) {
176  m_stateMachine->addTransition(b, XsdElement::Ptr(substGroups.at(i)), endState);
177  }
178  }
179 
180  return b;
181  } else if (term->isModelGroup()) {
182  const XsdModelGroup::Ptr group(term);
183 
184  if (group->compositor() == XsdModelGroup::ChoiceCompositor) { // 3
186 
187  for (int i = 0; i < group->particles().count(); ++i) {
188  const XsdParticle::Ptr particle(group->particles().at(i));
189  if (particle->maximumOccurs() != 0) {
190  const XsdStateMachine<XsdTerm::Ptr>::StateId state = buildParticle(particle, endState);
191  m_stateMachine->addEpsilonTransition(b, state);
192  }
193  }
194 
195  return b;
196  } else if (group->compositor() == XsdModelGroup::SequenceCompositor) { // 4
197  XsdStateMachine<XsdTerm::Ptr>::StateId currentStartState = endState;
198  XsdStateMachine<XsdTerm::Ptr>::StateId currentEndState = endState;
199 
200  for (int i = (group->particles().count() - 1); i >= 0; --i) { // iterate reverse
201  const XsdParticle::Ptr particle(group->particles().at(i));
202  if (particle->maximumOccurs() != 0) {
203  currentStartState = buildParticle(particle, currentEndState);
204  currentEndState = currentStartState;
205  }
206  }
207 
208  return currentStartState;
209  } else if (group->compositor() == XsdModelGroup::AllCompositor) {
211 
212  const QList<XsdParticle::List> list = allCombinations(group->particles());
213 
214  for (int i = 0; i < list.count(); ++i) {
215  XsdStateMachine<XsdTerm::Ptr>::StateId currentStartState = endState;
216  XsdStateMachine<XsdTerm::Ptr>::StateId currentEndState = endState;
217 
218  const XsdParticle::List particles = list.at(i);
219  for (int j = (particles.count() - 1); j >= 0; --j) { // iterate reverse
220  const XsdParticle::Ptr particle(particles.at(j));
221  if (particle->maximumOccurs() != 0) {
222  currentStartState = buildParticle(particle, currentEndState);
223  currentEndState = currentStartState;
224  }
225  }
226  m_stateMachine->addEpsilonTransition(newStartState, currentStartState);
227  }
228 
229  if (list.isEmpty())
230  return endState;
231  else
232  return newStartState;
233  }
234  }
235 
236  Q_ASSERT(false);
237  return 0;
238 }
The model group contains elements only.
XsdStateMachine< XsdTerm::Ptr >::StateId buildParticle(const XsdParticle::Ptr &particle, XsdStateMachine< XsdTerm::Ptr >::StateId endState)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual bool isWildcard() const
Definition: qxsdterm.cpp:58
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
virtual bool isElement() const
Definition: qxsdterm.cpp:48
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
XsdStateMachine< XsdTerm::Ptr > * m_stateMachine
virtual bool isModelGroup() const
Definition: qxsdterm.cpp:53
A state machine used for evaluation.
static bool substitutionGroupOkTransitive(const XsdElement::Ptr &head, const XsdElement::Ptr &member, const NamePool::Ptr &namePool)
QList< QList< T > > allCombinations(const QList< T > &input)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ particleLookupMap()

QHash< XsdTerm::Ptr, XsdParticle::Ptr > XsdStateMachineBuilder::particleLookupMap ( const XsdParticle::Ptr particle)
static

Returns a hash that maps each term that appears inside particle, to the particle it belongs.

Note
These information are used by XsdParticleChecker to check particle inheritance.

Definition at line 252 of file qxsdstatemachinebuilder.cpp.

Referenced by QPatternist::XsdParticleChecker::subsumes().

253 {
255  internalParticleLookupMap(particle, result);
256 
257  return result;
258 }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
static void internalParticleLookupMap(const XsdParticle::Ptr &particle, QHash< XsdTerm::Ptr, XsdParticle::Ptr > &hash)

◆ reset()

XsdStateMachine< XsdTerm::Ptr >::StateId XsdStateMachineBuilder::reset ( )

Resets the state machine.

Returns
The initial end state.

Definition at line 95 of file qxsdstatemachinebuilder.cpp.

Referenced by QPatternist::XsdValidatingInstanceReader::createAndPushStateMachine(), QPatternist::XsdParticleChecker::isUPAConform(), and QPatternist::XsdParticleChecker::subsumes().

96 {
98 
99  m_stateMachine->clear();
100 
102 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
XsdStateMachine< XsdTerm::Ptr > * m_stateMachine
A state machine used for evaluation.

Properties

◆ m_mode

Mode QPatternist::XsdStateMachineBuilder::m_mode
private

Definition at line 133 of file qxsdstatemachinebuilder_p.h.

Referenced by buildTerm().

◆ m_namePool

NamePool::Ptr QPatternist::XsdStateMachineBuilder::m_namePool
private

Definition at line 132 of file qxsdstatemachinebuilder_p.h.

Referenced by buildTerm().

◆ m_stateMachine

XsdStateMachine<XsdTerm::Ptr>* QPatternist::XsdStateMachineBuilder::m_stateMachine
private

Definition at line 131 of file qxsdstatemachinebuilder_p.h.

Referenced by addStartState(), buildParticle(), buildTerm(), and reset().


The documentation for this class was generated from the following files: