summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action.cpp8
-rw-r--r--common/action.h17
-rw-r--r--common/list.h34
-rw-r--r--common/tile.cpp4
-rw-r--r--common/tile.h18
5 files changed, 41 insertions, 40 deletions
diff --git a/common/action.cpp b/common/action.cpp
index 58b7392..77988d6 100644
--- a/common/action.cpp
+++ b/common/action.cpp
@@ -12,11 +12,3 @@ Action::Action(Type ty, int ta) : type(ty), target(ta) {
bool Action::operator==(const Action& other) {
return type == other.type && target == other.target;
}
-
-Actions::operator bool() {
- return !empty();
-}
-
-bool Actions::contains(Action action) {
- return std::find(begin(), end(), action) != end();
-}
diff --git a/common/action.h b/common/action.h
index 4024c67..e1b06f2 100644
--- a/common/action.h
+++ b/common/action.h
@@ -1,8 +1,7 @@
#ifndef ACTION_H
#define ACTION_H
-#include <vector>
-#include <boost/serialization/base_object.hpp>
+#include "list.h"
class Action {
public:
@@ -39,18 +38,6 @@ class Action {
};
//! List of actions.
-class Actions : public std::vector<Action> {
- public:
- //! Check if specified action is present in list.
- bool contains(Action action);
-
- //! Check whether list is empty or not.
- operator bool();
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
- ar & boost::serialization::base_object<std::vector<Action> >(*this);
- }
-};
+typedef List<Action> Actions;
#endif
diff --git a/common/list.h b/common/list.h
new file mode 100644
index 0000000..92452f1
--- /dev/null
+++ b/common/list.h
@@ -0,0 +1,34 @@
+#ifndef LIST_H
+#define LIST_H
+
+#include <vector>
+#include <algorithm>
+#include <boost/serialization/base_object.hpp>
+
+//! List class with extended functionality over std::vector.
+template<class T, class B = std::vector<T> >
+class List : public B {
+ public:
+ //! Sort the list.
+ void sort() {
+ std::sort(B::begin(), B::end());
+ }
+
+ //! Check if specified item is present in list.
+ bool contains(T item) {
+ return std::find(B::begin(), B::end(), item) != B::end();
+ }
+
+ //! Check whether list is empty or not.
+ operator bool() {
+ return !B::empty();
+ }
+
+ //! Allow serialization through Boost.Serialize.
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version) {
+ ar & boost::serialization::base_object<B>(*this);
+ }
+};
+
+#endif
diff --git a/common/tile.cpp b/common/tile.cpp
index 5a05548..0fb2230 100644
--- a/common/tile.cpp
+++ b/common/tile.cpp
@@ -59,7 +59,3 @@ Tile Tile::operator++(int) {
type = Type(type + 1);
return *this;
}
-
-void Tiles::sort() {
- std::sort(begin(), end());
-}
diff --git a/common/tile.h b/common/tile.h
index fe25a06..748d80b 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -1,9 +1,7 @@
#ifndef TILE_H
#define TILE_H
-#include <stdint.h>
-#include <vector>
-#include <boost/serialization/base_object.hpp>
+#include "list.h"
class Tile {
public:
@@ -99,15 +97,9 @@ class Tile {
};
//! List of tiles.
-class Tiles : public std::vector<Tile> {
- public:
- //! Sort the list of tiles.
- void sort();
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
- ar & boost::serialization::base_object<std::vector<Tile> >(*this);
- }
-};
+typedef List<Tile> Tiles;
+
+//! List of list of tiles.
+typedef List<Tiles> Tilegroups;
#endif