summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/array.cpp26
-rw-r--r--src/generic/array.hpp9
-rw-r--r--src/generic/db.cpp26
-rw-r--r--src/generic/db.hpp40
-rw-r--r--src/generic/dumb_ptr.cpp26
-rw-r--r--src/generic/dumb_ptr.hpp5
-rw-r--r--src/generic/enum.cpp26
-rw-r--r--src/generic/enum.hpp3
-rw-r--r--src/generic/fwd.hpp32
-rw-r--r--src/generic/intern-pool.cpp26
-rw-r--r--src/generic/matrix.cpp26
-rw-r--r--src/generic/md5.hpp1
-rw-r--r--src/generic/operators.cpp26
-rw-r--r--src/generic/operators.hpp68
-rw-r--r--src/generic/random.hpp4
-rw-r--r--src/generic/random2.hpp4
16 files changed, 69 insertions, 279 deletions
diff --git a/src/generic/array.cpp b/src/generic/array.cpp
deleted file mode 100644
index 3063569..0000000
--- a/src/generic/array.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "array.hpp"
-// array.cpp - A simple bounds-checked array.
-//
-// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/array.hpp b/src/generic/array.hpp
index dccb91e..3575db6 100644
--- a/src/generic/array.hpp
+++ b/src/generic/array.hpp
@@ -26,6 +26,7 @@
#include "oops.hpp"
+// half the important stuff is now in fwd.hpp !!!
namespace tmwa
{
template<class I, I be, I en>
@@ -39,9 +40,6 @@ struct ExclusiveIndexing
constexpr static size_t alloc_size = index_to_offset(en) - index_to_offset(be);
};
-template<size_t n>
-using SimpleIndexing = ExclusiveIndexing<size_t, 0, n>;
-
template<class I, I lo, I hi>
struct InclusiveIndexing
{
@@ -53,7 +51,7 @@ struct InclusiveIndexing
constexpr static size_t alloc_size = index_to_offset(hi) - index_to_offset(lo) + 1;
};
-template<class E, E n=E::COUNT>
+template<class E, E n>
struct EnumIndexing : ExclusiveIndexing<E, static_cast<E>(0), n>
{
};
@@ -112,7 +110,4 @@ public:
return !(lhs == rhs);
}
};
-
-template<class T, size_t n>
-using Array = GenericArray<T, SimpleIndexing<n>>;
} // namespace tmwa
diff --git a/src/generic/db.cpp b/src/generic/db.cpp
deleted file mode 100644
index 458068c..0000000
--- a/src/generic/db.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "db.hpp"
-// db.cpp - convenience wrappers over std::map<K, V>
-//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/db.hpp b/src/generic/db.hpp
index 90c4f92..04ead79 100644
--- a/src/generic/db.hpp
+++ b/src/generic/db.hpp
@@ -23,6 +23,8 @@
#include <map>
#include <memory>
+#include "../compat/borrow.hpp"
+
namespace tmwa
{
@@ -45,19 +47,19 @@ public:
const_iterator begin() const { return impl.begin(); }
const_iterator end() const { return impl.end(); }
- V *search(const K& k)
+ Option<Borrowed<V>> search(const K& k)
{
iterator it = impl.find(k);
if (it == impl.end())
- return nullptr;
- return &it->second;
+ return None;
+ return Some(borrow(it->second));
}
- const V *search(const K& k) const
+ Option<Borrowed<const V>> search(const K& k) const
{
const_iterator it = impl.find(k);
if (it == impl.end())
- return nullptr;
- return &it->second;
+ return None;
+ return Some(borrow(it->second));
}
void insert(const K& k, V v)
{
@@ -72,9 +74,9 @@ public:
return (void)&it->second;
}
- V *init(const K& k)
+ Borrowed<V> init(const K& k)
{
- return &impl[k];
+ return borrow(impl[k]);
}
void erase(const K& k)
{
@@ -112,8 +114,13 @@ public:
// const V& ? with a static default V?
V get(const K& k)
{
- V *vp = impl.search(k);
- return vp ? *vp : V();
+ Option<Borrowed<V>> vp = impl.search(k);
+ OMATCH_BEGIN_SOME (v, vp)
+ {
+ return *v;
+ }
+ OMATCH_END ();
+ return V();
}
void put(const K& k, V v)
{
@@ -153,10 +160,15 @@ public:
const_iterator end() const { return impl.end(); }
// const V& ? with a static default V?
- V *get(const K& k)
- {
- U *up = impl.search(k);
- return up ? up->get() : nullptr;
+ Option<Borrowed<V>> get(const K& k)
+ {
+ Option<Borrowed<U>> up = impl.search(k);
+ OMATCH_BEGIN_SOME (u, up)
+ {
+ return Some(borrow(*u->get()));
+ }
+ OMATCH_END ();
+ return None;
}
void put(const K& k, U v)
{
diff --git a/src/generic/dumb_ptr.cpp b/src/generic/dumb_ptr.cpp
deleted file mode 100644
index e690f7d..0000000
--- a/src/generic/dumb_ptr.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "dumb_ptr.hpp"
-// dumb_ptr.cpp - dummy file to make Make dependencies work
-//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/dumb_ptr.hpp b/src/generic/dumb_ptr.hpp
index 72247d5..2ada93b 100644
--- a/src/generic/dumb_ptr.hpp
+++ b/src/generic/dumb_ptr.hpp
@@ -35,8 +35,11 @@ class dumb_ptr
friend class dumb_ptr;
T *impl;
public:
+ dumb_ptr() noexcept
+ : impl(nullptr)
+ {}
explicit
- dumb_ptr(T *p=nullptr) noexcept
+ dumb_ptr(T *p) noexcept
: impl(p)
{}
template<class U>
diff --git a/src/generic/enum.cpp b/src/generic/enum.cpp
deleted file mode 100644
index 49402e9..0000000
--- a/src/generic/enum.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "enum.hpp"
-// enum.cpp - Safe building blocks for enumerated types.
-//
-// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/enum.hpp b/src/generic/enum.hpp
index 81c9b12..d5d50ea 100644
--- a/src/generic/enum.hpp
+++ b/src/generic/enum.hpp
@@ -33,8 +33,7 @@
namespace tmwa
{
-template<class T, class E, E max>
-using earray = GenericArray<T, EnumIndexing<E, max>>;
+// part moved to fwd.hpp
template<class T, class E, E max>
class eptr
diff --git a/src/generic/fwd.hpp b/src/generic/fwd.hpp
index 3215903..31fb13a 100644
--- a/src/generic/fwd.hpp
+++ b/src/generic/fwd.hpp
@@ -20,10 +20,42 @@
#include "../sanity.hpp"
+#include "../strings/fwd.hpp" // rank 1
+#include "../compat/fwd.hpp" // rank 2
+// generic/fwd.hpp is rank 3
+
namespace tmwa
{
// meh, add more when I feel like it
template<class T>
class dumb_ptr;
+
+template<class K, class V>
+class Map;
+template<class K, class V>
+class DMap;
+template<class K, class V>
+class UPMap;
+
+class InternPool;
+
+// arrays are complicated
+template<class I, I be, I en>
+struct ExclusiveIndexing;
+template<size_t n>
+using SimpleIndexing = ExclusiveIndexing<size_t, 0, n>;
+template<class I, I lo, I hi>
+struct InclusiveIndexing;
+template<class E, E n=E::COUNT>
+struct EnumIndexing;
+template<class I, size_t limit>
+struct InventoryIndexing;
+template<class T, class I>
+struct GenericArray;
+template<class T, size_t n>
+using Array = GenericArray<T, SimpleIndexing<n>>;
+
+template<class T, class E, E max>
+using earray = GenericArray<T, EnumIndexing<E, max>>;
} // namespace tmwa
diff --git a/src/generic/intern-pool.cpp b/src/generic/intern-pool.cpp
deleted file mode 100644
index f45b098..0000000
--- a/src/generic/intern-pool.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "intern-pool.hpp"
-// intern-pool.cpp - Cached integer/string lookups.
-//
-// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/matrix.cpp b/src/generic/matrix.cpp
deleted file mode 100644
index b14ab7d..0000000
--- a/src/generic/matrix.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "matrix.hpp"
-// matrix.cpp - A 2D array.
-//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/md5.hpp b/src/generic/md5.hpp
index 50bc987..2f07789 100644
--- a/src/generic/md5.hpp
+++ b/src/generic/md5.hpp
@@ -24,7 +24,6 @@
#include <array>
-#include "../strings/fwd.hpp"
#include "../strings/vstring.hpp"
diff --git a/src/generic/operators.cpp b/src/generic/operators.cpp
deleted file mode 100644
index 614ae51..0000000
--- a/src/generic/operators.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "operators.hpp"
-// operators.cpp - ADL helper for value wrappers.
-//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "../poison.hpp"
-
-
-namespace tmwa
-{
-} // namespace tmwa
diff --git a/src/generic/operators.hpp b/src/generic/operators.hpp
deleted file mode 100644
index bb05765..0000000
--- a/src/generic/operators.hpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#pragma once
-// operators.hpp - ADL helper for value wrappers.
-//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
-//
-// This file is part of The Mana World (Athena server)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include "fwd.hpp"
-
-
-namespace tmwa
-{
-namespace _operators
-{
- class Comparable {};
-
- template<class T>
- bool operator == (T l, T r)
- {
- return l.value == r.value;
- }
-
- template<class T>
- bool operator != (T l, T r)
- {
- return l.value != r.value;
- }
-
- template<class T>
- bool operator < (T l, T r)
- {
- return l.value < r.value;
- }
-
- template<class T>
- bool operator <= (T l, T r)
- {
- return l.value <= r.value;
- }
-
- template<class T>
- bool operator > (T l, T r)
- {
- return l.value > r.value;
- }
-
- template<class T>
- bool operator >= (T l, T r)
- {
- return l.value >= r.value;
- }
-}
-
-using _operators::Comparable;
-} // namespace tmwa
diff --git a/src/generic/random.hpp b/src/generic/random.hpp
index 5d67236..897ad43 100644
--- a/src/generic/random.hpp
+++ b/src/generic/random.hpp
@@ -18,10 +18,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "fwd.hpp"
-
#include "random.t.hpp"
+#include "fwd.hpp"
+
#include <random>
diff --git a/src/generic/random2.hpp b/src/generic/random2.hpp
index 23d165c..3d481f4 100644
--- a/src/generic/random2.hpp
+++ b/src/generic/random2.hpp
@@ -18,10 +18,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "fwd.hpp"
-
#include "random.hpp"
+#include "fwd.hpp"
+
#include <algorithm>
#include "../compat/iter.hpp"