Just another undocumented and bad code snippet
Nur für diejenigen die sich auch mit Metakit befassen ein weiteres schlechtes Beispiel Code, kein schöner Code aber vielleicht hilft es jemandem. Es hat zumindest meinen Zweck erfüllt eine Akregator Datenbank auszulesen. Geholfen hat mir auch die cplusplus.com Referenz geholfen.
#include <mk4.h> // http://www.equi4.com/metakit/api/mk4_8h.html
#include <mk4io.h> // http://www.equi4.com/metakit/api/mk4io_8h.html
#include <mk4str.h> // http://www.equi4.com/metakit/api/mk4str_8h.html
#include <string>
#include <vector>
#include <iostream>
#include <time.h>
using namespace std;
int main (int argc, char** argv) {
vector<string> toc;
string::iterator tocStringIt;
vector<string>::iterator tocIt;
int index = 0, stack = 0, lastStringIndex = 0;
c4_Storage storage (argv[1], true);
string tocString = string(storage.Description()); // get a Table of Content as String
c4_View db = storage.GetAs(tocString.c_str());
cout << "Read MetaKit Database with " << (long)db.GetSize() << " rows" << endl;
cout << "and the following table of content: " << endl;
cout << tocString << endl;
for (tocStringIt = tocString.begin(); tocStringIt <= tocString.end(); tocStringIt++) {
if(*tocStringIt == ',' || *tocStringIt == '') {
if(stack == 0) {
// split string at this position
// and add substring to the toc (Array)
// maybe http://www.cplusplus.com/reference/string/string/ helps
// It would be cooler to solve this completely with itarators and not with the lastStringIndex int.
cout << "Split Sting" << endl;
toc.push_back(tocString.substr(lastStringIndex,(int)(tocStringIt-tocString.begin())));
lastStringIndex = (int)(tocStringIt-tocString.begin())+1;
}
else if (*tocStringIt == '') {
cout << "Am Ende des Strings ";
if(stack > 1) cout << "liegen"; else cout << "liegt";
cout << "noch" << stack;
if(stack > 1) cout << "Klammern"; else cout << "Klammer";
cout << "auf dem Stack, das ist nicht gut." << endl;
}
}
else if(*tocStringIt == '[') stack++;
else if(*tocStringIt == ']') stack--;
}
vector<c4_View> views;
cout << "the splitted toc" << endl;
for (tocIt=toc.begin(); tocIt < toc.end(); tocIt++) {
cout << " " << *tocIt << endl;
c4_View view = storage.GetAs((*tocIt).c_str());
views.push_back(view);
}
vector<c4_View>::iterator viewIt;
c4_StringProp guid("guid"), title("title"), description("description"), link("link"), commentsLink("commentsLink"), enclosureUrl("enclosureUrl"), enclosureType("enclosureType"), author("author");
c4_IntProp hash("hash"), guidIsHash("guidIsHash"), guidIsPermaLink("guidIsPermaLink"), comments("comments"), status("status"), pubDate("pubDate"), hasEnclosure("hasEnclosure"), enclosureLength("enclosureLength");
for (int article = 0; article < views.at(0).GetSize(); article++) {
time_t time = (time_t)pubDate((views.at(0))[article]);
char* date = ctime(&time);
cout << "<h2>" << title((views.at(0))[article]) << "</h2>" << endl;
cout << "<em>" << date << "</em>" << endl;
cout << description((views.at(0))[article]) << endl;
cout << "<em>" << author((views.at(0))[article]) << "</em>" << endl;
cout << endl;
}
return 0;
}
- Eclipse crashed in lucid after code completion: http://www.bearfruit.org/2010/06/26/eclipse-ubuntu-renderbadpicture-error/ 26.07.2010
- @gerbsen test 123, test test 19.07.2010
Blogroll
- Christoph
- comiles.eu
- Franka about New Media
- Halbwertszeit
- namenlose's Blog
- Nur fast
- Schafblog
- Splatte
- SV Lindenau
- Tux Weblog