Hit the group-fetching code so it compiles.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:01:57 +0000 (16:01 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:01:57 +0000 (16:01 +0000)
bigscreen/Makefile
bigscreen/ccbs_bigscreen.cpp
bigscreen/fetch_group.cpp
bigscreen/fetch_list_of_active_groups.cpp
bigscreen/fetch_list_of_active_groups.h
bigscreen/group.h

index 76d280d..aca8243 100644 (file)
@@ -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 fetch_current_tournament.o fetch_list_of_active_groups.o fonts.o
+CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_group.o fonts.o
 
 all: ccbs-bigscreen
 
index 9db87c8..f509912 100644 (file)
@@ -8,10 +8,11 @@
 #include "widestring.h"
 #include "fetch_current_tournament.h"
 #include "fetch_list_of_active_groups.h"
+#include "fetch_group.h"
 #include "fonts.h"
 
 Tournament active_tournament;
-std::vector<Group> active_groups;
+std::vector<SkeletonGroup> active_groups;
 unsigned char framebuf[800 * 600 * 4];
 
 void init(pqxx::connection &conn)
@@ -24,9 +25,13 @@ void init(pqxx::connection &conn)
        } else {
                std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
 
-               for (std::vector<Group>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
+               for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
                        std::fprintf(stderr, "tourn: %u  round: %u   parallel: %u\n",
                                i->tournament, i->round, i->parallel);
+
+                       Group gr;
+                       conn.perform(FetchGroup(i->tournament, i->round, i->parallel, &gr));
+                       std::fprintf(stderr, "%u players in group\n", gr.players.size());
                }
        }
 }
index 7e131c4..e1d0112 100644 (file)
@@ -5,7 +5,7 @@ FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, G
        
 void FetchGroup::operator() (pqxx::transaction<> &t)
 {
-       pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE " +
+       pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE " 
                "tournament=" + pqxx::to_string(tournament) + " AND " +
                "round=" + pqxx::to_string(round) + " AND " +
                "parallel=" + pqxx::to_string(parallel) + " " +
@@ -18,16 +18,16 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
        // massage the data we get back into a Group object and children
        int curr_player = -1;
        for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
-               if (i["player"] != curr_player) {
+               if (i["player"].as(curr_player) != curr_player) {
                        Player p;
 
-                       p.id = i["player"];
+                       p.id = i["player"].as(p.id);
                        p.nick = i["nick"].as(p.nick);
                        p.total = 0;
                        p.rank = 1;
                        curr_group.players.push_back(p);
                        
-                       curr_player = i["player"];
+                       curr_player = i["player"].as(curr_player);
                }
 
                // note: we _will_ get some duplication here (multiple identical Song
@@ -40,10 +40,10 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
                so.artist = i["song"].as(so.artist);
        
                sc.song = so;
-               sc.chosen = i["chosen"].as(s.chosen);
-               sc.score = i["score"].as(s.score);
+               sc.chosen = i["chosen"].as(sc.chosen);
+               sc.score = i["score"].as(sc.score);
                
-               curr_group.players[curr.group.players.size() - 1].scores.push_back(sc);
+               curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
        }
 }
 
index 1df6758..c2d587b 100644 (file)
@@ -1,6 +1,6 @@
 #include "fetch_list_of_active_groups.h"
 
-FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<Group> *active) : active(active) {}
+FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<SkeletonGroup> *active) : active(active) {}
 void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t)
 {
        // make sure we start with an empty list
@@ -8,7 +8,7 @@ void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t)
        
        pqxx::result res( t.exec("SELECT * FROM bigscreen.active_groups") );
        for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
-               Group g;
+               SkeletonGroup g;
 
                g.tournament = i["tournament"].as(g.tournament);
                g.round = i["round"].as(g.round);
index 113160d..b1039d3 100644 (file)
@@ -4,17 +4,17 @@
 #include <pqxx/transactor>
 #include <vector>
 
-struct Group {
+struct SkeletonGroup {
        unsigned tournament, round, parallel;
 };
 
 /* A transactor that fetches the current list of active groups. */
 class FetchListOfActiveGroups : public pqxx::transactor<> {
 private:
-       std::vector<Group> *active;
+       std::vector<SkeletonGroup> *active;
 
 public:
-       FetchListOfActiveGroups(std::vector<Group> *active);
+       FetchListOfActiveGroups(std::vector<SkeletonGroup> *active);
        void operator() (pqxx::transaction<> &t);
 };
 
index 6961a90..f6348c0 100644 (file)
@@ -13,11 +13,11 @@ struct Score {
        Song song;
        bool chosen;
        unsigned score;
-}:
+};
 struct Player {
        unsigned id;
        widestring nick;
-       unsigned score, rank;
+       unsigned total, rank;
        
        std::vector<Score> scores;
 };