337 |
vasco |
1 |
/*
|
|
|
2 |
* Trida RNDFParser poskytuje metody ke zpracovani textoveho souboru ve
|
|
|
3 |
* formatu RNDF definovaneho v soutezi Rotobour 2007
|
|
|
4 |
*
|
|
|
5 |
* @author: Vasco
|
|
|
6 |
* @date: Sat, 21 Jul 2007 15:56:28 +0200
|
|
|
7 |
* @version: 0.0.0
|
|
|
8 |
*
|
|
|
9 |
*/
|
|
|
10 |
#include <iostream>
|
|
|
11 |
#include <string>
|
|
|
12 |
#include <map>
|
|
|
13 |
#include <vector>
|
|
|
14 |
#include <cctype>
|
|
|
15 |
|
|
|
16 |
#ifdef DBG
|
|
|
17 |
// vypisuje ladici hlaseni
|
|
|
18 |
#include "rndf_dbg.cpp"
|
|
|
19 |
#endif
|
|
|
20 |
|
|
|
21 |
class RNDFParser {
|
|
|
22 |
private:
|
|
|
23 |
std::string rndfname;
|
|
|
24 |
|
|
|
25 |
protected:
|
|
|
26 |
/* funkce vezme retezec a rozlozi jej na slova, vraci vector<std::string> */
|
|
|
27 |
std::vector<std::string> toWord(const std::string& veta);
|
|
|
28 |
|
|
|
29 |
public:
|
|
|
30 |
RNDFParser(std::string name) { rndfname = name; } // konstruktor, ulozi jmeno souboru
|
|
|
31 |
std::string rndfName() { return rndfname; } // vrati jmeno zpracovavaneho souboru
|
|
|
32 |
std::map<double, double> parseSegment(int numSegment); // rozparsuje zadany segment cesty
|
|
|
33 |
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* @param veta retezec, ktery chceme rozlozit na slova
|
|
|
38 |
*
|
|
|
39 |
* Metoda vezme vstupni retezec a rozlozi jej na slova. Slovo zacina a konci libovolnym poctem
|
|
|
40 |
* bilych znaku, veta konci s koncem retezce. Vysledna slova jsou ukladana do vector<string>,
|
|
|
41 |
* ktery je nasledne vracen volajicimu.
|
|
|
42 |
*/
|
|
|
43 |
std::vector<std::string> RNDFParser::toWord(const std::string& veta) {
|
|
|
44 |
// definice vlastnich typu
|
|
|
45 |
typedef std::string::size_type vel_vety; // velikost retezce
|
|
|
46 |
|
|
|
47 |
// mistni promnene
|
|
|
48 |
std::vector<std::string> slova; // sem se budou ukladat slova
|
|
|
49 |
vel_vety i = 0; // velikost zadane vety
|
|
|
50 |
|
|
|
51 |
#ifdef DBG
|
|
|
52 |
// pro kontrolu vypiseme vetu
|
|
|
53 |
echoDbg(veta);
|
|
|
54 |
#endif
|
|
|
55 |
|
|
|
56 |
// dokud nedojdeme na konec retezce
|
|
|
57 |
while(i != veta.size()) {
|
|
|
58 |
// jsou na zacatku mezery? preskoc je
|
|
|
59 |
while(i != veta.size() && std::isspace(veta[i]))
|
|
|
60 |
i++;
|
|
|
61 |
|
|
|
62 |
// uloz pozici zacatku slova
|
|
|
63 |
vel_vety j = i; // pomocny ukazatel v retezci
|
|
|
64 |
|
|
|
65 |
// slovo, dokud nenarazime na dalsi mezeru
|
|
|
66 |
while(j != veta.size() && !(std::isspace(veta[j])))
|
|
|
67 |
j++;
|
|
|
68 |
|
|
|
69 |
// pokud se ve vete vyskytovaly slova
|
|
|
70 |
if(i != j) {
|
|
|
71 |
// vloz slovo do vectoru
|
|
|
72 |
slova.push_back(veta.substr(i, j - i));
|
|
|
73 |
|
|
|
74 |
// opet ulozime pozici a jdem na dalsi slovo
|
|
|
75 |
i = j;
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
} //end while
|
|
|
79 |
|
|
|
80 |
return slova;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/* funkce main je jen pro testovaci ucely, prelozi se pouze s definovanym makrem 'DBG' */
|
|
|
84 |
#ifdef DBG
|
|
|
85 |
int main(void) {
|
|
|
86 |
|
|
|
87 |
std::cout << "PARSER:\tvypisuji RNDF soubor:" << std::endl;
|
|
|
88 |
|
|
|
89 |
RNDFParser parser("RNDF_stromovka.txt");
|
|
|
90 |
std::cout << "PARSER:\tJmeno souboru je " << parser.rndfName() << std::endl;
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
return 0;
|
|
|
94 |
}
|
|
|
95 |
#endif
|