00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "projectiondfatransitions.h"
00036 #include "projectiondfastate.h"
00037
00038 ProjectionDFATransitions::ProjectionDFATransitions(ProjectionDFAState * _parent):
00039 parent(_parent), text_transition_computed(false), text_transition(NULL) {
00040 }
00041
00042 ProjectionDFATransitions::~ProjectionDFATransitions() {
00043 delete text_transition;
00044
00045 hash_map < TAG,
00046 ProjectionDFAState * >::iterator it = transitions.begin();
00047
00048 while (it != transitions.end()) {
00049 delete(ProjectionDFAState *) it->second;
00050 it++;
00051 }
00052 }
00053
00054 void ProjectionDFATransitions::print(OutputStream & dos, unsigned indents) {
00055
00056
00057 if (text_transition) {
00058 dos << resetIndents() << incrementIndents(indents);
00059 dos << writeIndents();
00060 dos << "#PCDATA --> ";
00061 text_transition->print(dos, indents + 1, true);
00062 }
00063
00064 hash_map < TAG,
00065 ProjectionDFAState * >::iterator it = transitions.begin();
00066
00067 while (it != transitions.end()) {
00068 dos << resetIndents() << incrementIndents(indents);
00069 dos << writeIndents();
00070 dos << "<" << TagMap::getInstance()->getTag(it->first) << "> --> ";
00071 ProjectionDFAState *follow_up = it->second;
00072
00073 if (follow_up != NULL) {
00074 follow_up->print(dos, indents + 1);
00075 } else {
00076 dos << "NULL" << NEWLINE;
00077 }
00078 it++;
00079 };
00080 }
00081
00082 ProjectionDFAState *ProjectionDFATransitions::takeTransition(TAG t,
00083 short &t_type) {
00084 hash_map < TAG,
00085 ProjectionDFAState * >::iterator it = transitions.find(t);
00086
00087 if (it == transitions.end()) {
00088 t_type = TRANSITION_UNKNOWN;
00089 return NULL;
00090 } else {
00091 t_type = TRANSITION_REGULAR;
00092 return it->second;
00093 }
00094 }
00095
00096 ProjectionDFAState *ProjectionDFATransitions::takeTextTransition(bool is_root) {
00097 if (!text_transition_computed) {
00098 computeTextTransition(is_root);
00099 }
00100 return text_transition;
00101 }
00102
00103 void ProjectionDFATransitions::computeTransition(ProjectionDFAState * parent,
00104 TAG t) {
00105 TokenConfiguration *new_conf = parent->getTokenConfiguration()->applyTag(t);
00106 PassiveProjectionTreeConfiguration *new_pconf =
00107 parent->getPassiveProjectionTreeConfiguration() ==
00108 NULL ? NULL : parent->getPassiveProjectionTreeConfiguration()->
00109 applyTag(t);
00110 if (new_conf) {
00111 transitions[t] = new ProjectionDFAState(parent, new_conf, new_pconf);
00112 } else {
00113 delete new_pconf;
00114
00115 transitions[t] = NULL;
00116 }
00117 }
00118
00119 void ProjectionDFATransitions::computeTextTransition(bool is_root) {
00120 text_transition_computed = true;
00121 if (is_root) {
00122 text_transition = NULL;
00123 } else {
00124 TokenConfiguration *new_conf =
00125 parent->getTokenConfiguration()->applyText();
00126 PassiveProjectionTreeConfiguration *new_pconf =
00127 parent->getPassiveProjectionTreeConfiguration() ==
00128 NULL ? NULL : parent->getPassiveProjectionTreeConfiguration()->
00129 applyText();
00130 if (new_conf) {
00131 text_transition =
00132 new ProjectionDFAState(parent, new_conf, new_pconf);
00133 } else {
00134 if (parent->isOutput()) {
00135 text_transition = new ProjectionDFAState(parent, new_pconf);
00136 } else {
00137 delete new_pconf;
00138
00139 text_transition = NULL;
00140 }
00141 }
00142 }
00143 }