|
From: Markus R. <god...@us...> - 2009-11-12 12:49:39
|
Module: performous
Branch: master
Commit: 36ddd9d00735ad724aae153c40d05ea9f80b5aa1
Author: Markus Raab <un...@ma...>
Date: Wed Nov 11 12:38:01 2009 +0100
performous compiles from now on again
(BUT it is only a small test program for the database)
difference between addSong and addSongItem introduced
---
game/CMakeLists.txt | 3 ++-
game/songitems.cc | 20 ++++++++++++++++----
game/songitems.hh | 16 +++++++++++++++-
3 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 3b191fa..4f48dfa 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.6)
-FILE(GLOB SOURCE_FILES "*.cc")
+# FILE(GLOB SOURCE_FILES "*.cc")
+SET(SOURCE_FILES hiscore.cc database.cc players.cc configuration.cc fs.cc unicode.cc songitems.cc song.cc notes.cc songparser-ini.cc songparser-txt.cc midifile.cc)
FILE(GLOB HEADER_FILES "*.hh")
set(SOURCES ${SOURCE_FILES} ${HEADER_FILES})
diff --git a/game/songitems.cc b/game/songitems.cc
index 775661c..db61ff3 100644
--- a/game/songitems.cc
+++ b/game/songitems.cc
@@ -1,7 +1,10 @@
#include "songitems.hh"
+#include "unicode.hh"
+
#include <string>
+#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <libxml++/libxml++.h>
@@ -22,7 +25,7 @@ void SongItems::load(xmlpp::NodeSet const& n)
xmlpp::Attribute* a_title = element.get_attribute("title");
if (!a_title) throw SongItemsException("No attribute title");
- addSong(a_artist->get_value(), a_title->get_value(), boost::lexical_cast<int>(a_id->get_value()));
+ addSongItem(a_artist->get_value(), a_title->get_value(), boost::lexical_cast<int>(a_id->get_value()));
}
}
@@ -37,13 +40,13 @@ void SongItems::save(xmlpp::Element *songs)
}
}
-void SongItems::addSong(std::string const& artist, std::string const& title, int id)
+void SongItems::addSongItem(std::string const& artist, std::string const& title, int id)
{
SongItem si;
if (id==-1) id = assign_id_internal();
si.id = id;
- si.artist = artist;
- si.title = title;
+ si.artist = unicodeCollate(artist);
+ si.title = unicodeCollate(title);
std::pair<songs_t::iterator, bool> ret = m_songs.insert(si);
if (!ret.second)
@@ -53,6 +56,15 @@ void SongItems::addSong(std::string const& artist, std::string const& title, int
}
}
+void SongItems::addSong(boost::shared_ptr<Song> song)
+{
+ for (songs_t::iterator it = m_songs.begin(); it != m_songs.end(); ++it)
+ {
+ if (song->artist == it->artist && song->title == it->title) return;
+ }
+ addSongItem(song->artist, song->title);
+}
+
int SongItems::assign_id_internal()
{
songs_t::const_reverse_iterator it = m_songs.rbegin();
diff --git a/game/songitems.hh b/game/songitems.hh
index ee089b6..d51c03d 100644
--- a/game/songitems.hh
+++ b/game/songitems.hh
@@ -1,10 +1,14 @@
#pragma once
+#include "song.hh"
+
#include <set>
#include <vector>
#include <string>
#include <stdexcept>
+#include <boost/shared_ptr.hpp>
+
namespace xmlpp { class Node; class Element; typedef std::vector<Node*>NodeSet; }
/**Exception which will be thrown when loading or
@@ -33,7 +37,17 @@ struct SongItems
void load(xmlpp::NodeSet const& n);
void save(xmlpp::Element *players);
- void addSong(std::string const& artist, std::string const& title, int id = -1);
+ /**Adds a song item.
+ If the id is not unique or -1 a new one will be assigned.
+ There will be no check if artist and title already exist - if you
+ need that you want addSong().
+ */
+ void addSongItem(std::string const& artist, std::string const& title, int id = -1);
+ /**Adds or Links an already existing song with an songitem.
+ The id will be assigned and artist and title will be filled in.
+ If there is already a song with the same artist and title nothing will be done.
+ */
+ void addSong(boost::shared_ptr<Song> song);
private:
int assign_id_internal();
|