All pastes #1077086 Raw Edit

Someone

public cpp v1 · immutable
#1077086 ·published 2008-07-19 22:48 UTC
rendered paste body
//simple_project_list.cpp#include <iostream>#include "ConnectionManager.h"#include "ClientConnection.h"#include "Project.h"#include "ProjectList.h"#include "Formatter.h"int main() {    ConnectionManager mgr;    ClientConnection connection(mgr);    if (!connection.connect("127.0.0.1")) {        std::cerr << "Connection error" << std::endl;    }    const ProjectList& projects = connection.get_projects();    for (ProjectList::const_iterator it = projects.begin(); it != projects.end(); ++it) {        Project* p = *it;        std::cout << formatter("Project %1 (%2)").arg(p->name()).arg(p->master_url()) << std::endl;    }    return 0;}/* vim: set ts=4 sw=4 et: *///------------------------//simple_project_list_async.cpp#include <iostream>#include "ConnectionManager.h"#include "ClientConnection.h"#include "Project.h"#include "ProjectList.h"#include "Formatter.h"#include <sigc++/sigc++.h>void connection_done(ClientConnection& connection, bool success);void project_list_retrieved(const ProjectList& projects);//Global?! Yes, global. I could pass it along via arguments using//sigc::bind, but that makes this sample more confusing.ConnectionManager mgr; int main() {    ClientConnection connection(mgr);    connection.connect_async("127.0.0.1", sigc::ptr_fun(&connection_done));    mgr.run();    return 0;}void connection_done(ClientConnection& connection, bool success) {    if (success) {        connection.get_projects_async(sigc::ptr_fun(&project_list_retrieved));    } else {        std::cerr << "Connection error" << std::endl;        mgr.stop();    }}void project_list_retrieved(const ProjectList& projects) {    for (ProjectList::const_iterator it = projects.begin(); it != projects.end(); ++it) {        Project* p = *it;        std::cout << formatter("Project %1 (%2)").arg(p->name()).arg(p->master_url()) << std::endl;    }    mgr.stop();}/* vim: set ts=4 sw=4 et: */