From: Steinar H. Gunderson Date: Sat, 19 Feb 2005 14:57:41 +0000 (+0000) Subject: Move Tournament and FetchCurrentTournament into its own file. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=2561f34f160440e5df8c3891a50d6e3c2b83c715;hp=141adc9f5acb9ed1e98a206abb0d2e9cfdce6d2f Move Tournament and FetchCurrentTournament into its own file. --- diff --git a/bigscreen/Makefile b/bigscreen/Makefile index ac92796..00a8e92 100644 --- a/bigscreen/Makefile +++ b/bigscreen/Makefile @@ -4,7 +4,7 @@ CPPFLAGS=-I/usr/include/postgresql $(shell freetype-config --cflags) -Itinyptc/ CXXFLAGS=-g -Wall LDFLAGS=-L/usr/X11R6/lib LIBS=$(shell freetype-config --libs) $(shell libpq3-config) -lpqxx tinyptc/libtinyptc.a -lX11 -CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o +CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o all: ccbs-bigscreen diff --git a/bigscreen/ccbs_bigscreen.cpp b/bigscreen/ccbs_bigscreen.cpp index fb0d757..745faa5 100644 --- a/bigscreen/ccbs_bigscreen.cpp +++ b/bigscreen/ccbs_bigscreen.cpp @@ -8,40 +8,13 @@ #include #include "flagtrigger.h" #include "widestring.h" +#include "fetch_current_tournament.h" int my_draw_text(const widestring &str, unsigned char *buf, int xpos, int ypos, bool real_render, int r, int g, int b, std::vector &fontlist); -class Tournament { -public: - int id; - widestring name; -}; - Tournament active_tournament; std::vector fonts; -/* A transactor that fetches the current tournament and some information about it. */ -class FetchCurrentTournament : public pqxx::transactor<> { -private: - Tournament *tourn; - -public: - FetchCurrentTournament(Tournament *tourn) : tourn(tourn) {} - void operator() (pqxx::transaction<> &t) - { - pqxx::result res( t.exec("SELECT * FROM bigscreen.active_tournament NATURAL JOIN tournaments") ); - try { - pqxx::result::tuple tournament = res.at(0); - - tourn->id = tournament["tournament"].as(tourn->id); - tourn->name = tournament["tournamentname"].as(tourn->name); - } catch (PGSTD::out_of_range &e) { - tourn->id = -1; - tourn->name = ""; - } - } -}; - void init(pqxx::connection &conn) { conn.perform(FetchCurrentTournament(&active_tournament)); diff --git a/bigscreen/fetch_current_tournament.cpp b/bigscreen/fetch_current_tournament.cpp new file mode 100644 index 0000000..364d8b3 --- /dev/null +++ b/bigscreen/fetch_current_tournament.cpp @@ -0,0 +1,16 @@ +#include "fetch_current_tournament.h" + +FetchCurrentTournament::FetchCurrentTournament(Tournament *tourn) : tourn(tourn) {} +void FetchCurrentTournament::operator() (pqxx::transaction<> &t) +{ + pqxx::result res( t.exec("SELECT * FROM bigscreen.active_tournament NATURAL JOIN tournaments") ); + try { + pqxx::result::tuple tournament = res.at(0); + + tourn->id = tournament["tournament"].as(tourn->id); + tourn->name = tournament["tournamentname"].as(tourn->name); + } catch (PGSTD::out_of_range &e) { + tourn->id = -1; + tourn->name = ""; + } +} diff --git a/bigscreen/fetch_current_tournament.h b/bigscreen/fetch_current_tournament.h new file mode 100644 index 0000000..4700871 --- /dev/null +++ b/bigscreen/fetch_current_tournament.h @@ -0,0 +1,23 @@ +#ifndef _FETCH_CURRENT_TOURNAMENT_H +#define _FETCH_CURRENT_TOURNAMENT_H 1 + +#include +#include "widestring.h" + +class Tournament { +public: + int id; + widestring name; +}; + +/* A transactor that fetches the current tournament and some information about it. */ +class FetchCurrentTournament : public pqxx::transactor<> { +private: + Tournament *tourn; + +public: + FetchCurrentTournament(Tournament *tourn); + void operator() (pqxx::transaction<> &t); +}; + +#endif /* !defined(_FETCH_CURRENT_TOURNAMENT_H) */