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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #include <iostream>
00043 #include <cstdlib>
00044 #include <set>
00045
00046 #include "lateq.hh"
00047 #include "Text.hh"
00048
00049
00050 map<string, string> gDocMathStringMap;
00051 set<string> gDocMathKeySet;
00052
00053 static int getLateqIndex(const string& s);
00054 static bool compLateqIndexes(const string& s1, const string& s2);
00055 static void initDocMathKeySet();
00056
00057
00058
00059
00060
00061
00062
00063
00077 void Lateq::println(ostream& docout)
00078 {
00079 docout << endl << gDocMathStringMap["lateqcomment"] << endl;
00080 docout << "\\begin{enumerate}" << endl << endl;
00081
00082
00083 string sInputs = fInputSigsFormulas.size() > 1 ? gDocMathStringMap["inputsigtitle2"] : gDocMathStringMap["inputsigtitle1"];
00084 string sOutputs = fOutputSigsFormulas.size() > 1 ? gDocMathStringMap["outputsigtitle2"] : gDocMathStringMap["outputsigtitle1"];
00085 string sConstants = fConstSigsFormulas.size() > 1 ? gDocMathStringMap["constsigtitle2"] : gDocMathStringMap["constsigtitle1"];
00086 string sUIElements = fUISigsFormulas.size() > 1 ? gDocMathStringMap["uisigtitle2"] : gDocMathStringMap["uisigtitle1"];
00087 string sParameters = fParamSigsFormulas.size() > 1 ? gDocMathStringMap["paramsigtitle2"] : gDocMathStringMap["paramsigtitle1"];
00088
00089 unsigned int internalSigsCount = fStoreSigsFormulas.size() + fRecurSigsFormulas.size() + fRDTblSigsFormulas.size() + fRWTblSigsFormulas.size() + fSelectSigsFormulas.size() + fPrefixSigsFormulas.size();
00090 string sInternals = internalSigsCount > 1 ? gDocMathStringMap["internalsigtitle2"] : gDocMathStringMap["internalsigtitle1"];
00091
00092
00093 printOneLine (subst("\\item $0: ", sInputs), fInputSigsFormulas, docout);
00094 printDGroup (subst("\\item $0: ", sOutputs), fOutputSigsFormulas, docout);
00095 printDGroup (subst("\\item $0: ", sConstants), fConstSigsFormulas, docout);
00096 printHierarchy (subst("\\item $0: ", sUIElements), fUISigsFormulas, docout);
00097 printDGroup (subst("\\item $0: ", sParameters), fParamSigsFormulas, docout);
00098
00099
00100 if( internalSigsCount > 0 ) {
00101 docout << subst("\\item $0: ", sInternals);
00102 }
00103 fStoreSigsFormulas.sort(compLateqIndexes);
00104 printDGroup ("", fStoreSigsFormulas, docout);
00105 printDGroup ("", fRecurSigsFormulas, docout);
00106 printDGroup ("", fRDTblSigsFormulas, docout);
00107 printMath ("", fRWTblSigsFormulas, docout);
00108 printMath ("", fSelectSigsFormulas, docout);
00109 printMath ("", fPrefixSigsFormulas, docout);
00110
00111 docout << "\\end{enumerate}" << endl << endl;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00130 void Lateq::printOneLine(const string& section, list<string>& field, ostream& docout)
00131 {
00132 if (field.size() > 0) {
00133 field.sort(compLateqIndexes);
00134 docout << section << "\t ";
00135 list<string>::const_iterator s;
00136 string sep = "";
00137 for (s = field.begin(); s != field.end(); ++s) {
00138 docout << sep << "$" << *s << "$" << endl;
00139 sep = ", ";
00140 }
00141 } else {
00142 docout << section << "\t" << gDocMathStringMap["emptyformulafield"] << endl << endl;
00143 }
00144 }
00145
00146
00158 void Lateq::printDGroup(const string& section, list<string>& field, ostream& docout)
00159 {
00160 if (field.size() > 0) {
00161 docout << section << endl;
00162 tab(1,docout); docout << "\\begin{dgroup*}" << endl;
00163 list<string>::const_iterator s;
00164 for (s = field.begin(); s != field.end(); ++s) {
00165 tab(2,docout); docout << "\\begin{" << "dmath*" << "}" << endl;
00166 tab(3,docout); docout << "\t" << *s << endl;
00167 tab(2,docout); docout << "\\end{" << "dmath*" << "}" << endl;
00168 }
00169 tab(1,docout); docout << "\\end{dgroup*}" << endl;
00170 docout << endl;
00171 }
00172 }
00173
00174
00198 void Lateq::printHierarchy(const string& section, multimap<string,string>& field, ostream& docout)
00199 {
00200 if (field.size() > 0) {
00201 docout << section << endl;
00202
00203 bool hasSomePaths = hasNotOnlyEmptyKeys(field);
00204 unsigned int n;
00205
00206 if (hasSomePaths) {
00207 tab(0,docout); docout << "\\begin{itemize}" << endl;
00208 n = 1;
00209 } else {
00210 n = 0;
00211 }
00212
00213 multimap<string,string>::iterator it;
00214 string uidir = "improbable_starting_dirname";
00215 bool startFlag = true;
00216
00217 for (it = field.begin(); it != field.end(); ++it) {
00218
00219 if (it->first != uidir) {
00220 if (!startFlag) {
00221 tab(n+2,docout); docout << "\\end{supertabular}" << endl;
00222 tab(n+1,docout); docout << "\\end{center}" << endl;
00223 } else {
00224 startFlag = false;
00225 }
00226 if (hasSomePaths) {
00227
00228 if (it->first != "") {
00229 tab(n+0,docout); docout << "\\item \\textsf{" << it->first << "}" << endl;
00230 } else {
00231 tab(n+0,docout); docout << "\\item \\textit{" << "(at root level)" << "}" << endl;
00232 }
00233 }
00234 tab(n+1,docout); docout << "\\begin{center}" << endl;
00235 tab(n+2,docout); docout << "\\begin{supertabular}{rllll}" << endl;
00236 }
00237
00238 tab(n+3,docout); docout << it->second << endl;
00239 uidir = it->first;
00240 }
00241 tab(n+2,docout); docout << "\\end{supertabular}" << endl;
00242 tab(n+1,docout); docout << "\\end{center}" << endl;
00243 if (hasSomePaths) {
00244 tab(n+0,docout); docout << "\\end{itemize}" << endl;
00245 }
00246 docout << endl;
00247 }
00248 }
00249
00250
00262 void Lateq::printMath(const string& section, list<string>& field, ostream& docout)
00263 {
00264 if (field.size() > 0) {
00265 docout << section;
00266 docout << "\\begin{displaymath}" << endl;
00267 list<string>::iterator s;
00268 for (s = field.begin(); s != field.end(); ++s) {
00269 docout << *s << endl;
00270 }
00271 docout << "\\end{displaymath}" << endl;
00272 docout << endl;
00273 }
00274 }
00275
00276
00278 void Lateq::tab (int n, ostream& docout) const
00279 {
00280 while (n--) docout << '\t';
00281 }
00282
00283
00293 bool Lateq::hasNotOnlyEmptyKeys(multimap<string,string>& mm)
00294 {
00295 typedef multimap<string,string>::iterator MMIT;
00296 pair<MMIT,MMIT> range;
00297 range = mm.equal_range("");
00298 bool hasOnlyEmptyPaths = (range.first == mm.begin()) && (range.second == mm.end());
00299 return !hasOnlyEmptyPaths;
00300 }
00301
00302
00303
00307 void initDocMath()
00308 {
00309 initDocMathKeySet();
00310 }
00311
00312
00313
00314
00315
00316
00317
00322 static bool compLateqIndexes(const string& s1, const string& s2)
00323 {
00324 return getLateqIndex(s1) < getLateqIndex(s2);
00325 }
00326
00327
00335 static int getLateqIndex(const string& s)
00336 {
00337 size_t p1;
00338 size_t p2;
00339 string sIndex;
00340
00341 p1 = s.find("_{");
00342 if (p1==string::npos) {
00343 cerr << "Error : getLateqIndex found no \"{_\" substring.\n";
00344 exit(1); }
00345 p1 += 2;
00346
00347 p2 = s.find("}", p1);
00348 if (p2==string::npos) {
00349 cerr << "Error : getLateqIndex found no \"}\" substring\n.";
00350 exit(1); }
00351 p2 -= 3;
00352
00353 sIndex = s.substr (p1, p2);
00354
00355 return atoi(sIndex.c_str());
00356 }
00357
00358
00362 static void initDocMathKeySet()
00363 {
00364 gDocMathKeySet.insert("inputsigtitle1");
00365 gDocMathKeySet.insert("inputsigtitle2");
00366 gDocMathKeySet.insert("outputsigtitle1");
00367 gDocMathKeySet.insert("outputsigtitle2");
00368 gDocMathKeySet.insert("constsigtitle1");
00369 gDocMathKeySet.insert("constsigtitle2");
00370 gDocMathKeySet.insert("uisigtitle1");
00371 gDocMathKeySet.insert("uisigtitle2");
00372 gDocMathKeySet.insert("paramsigtitle1");
00373 gDocMathKeySet.insert("paramsigtitle2");
00374 gDocMathKeySet.insert("internalsigtitle1");
00375 gDocMathKeySet.insert("internalsigtitle2");
00376 gDocMathKeySet.insert("lateqcomment");
00377 gDocMathKeySet.insert("emptyformulafield");
00378 gDocMathKeySet.insert("defaultvalue");
00379 }