aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 13:57:42 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 13:57:42 +0100
commit76ee405c9c9f91684e42bddb0ba527e29e1084a8 (patch)
treef2115500c253ff89dcce8b8f67e5a6f98c526976
parentc57b86336fbf7449ea4f78efafb337af03c6325e (diff)
downloadpaludis-76ee405c9c9f91684e42bddb0ba527e29e1084a8.tar.gz
paludis-76ee405c9c9f91684e42bddb0ba527e29e1084a8.tar.xz
Don't bother pimping options
-rw-r--r--paludis/util/options.cc68
-rw-r--r--paludis/util/options.hh7
-rw-r--r--paludis/util/options_TEST.cc3
3 files changed, 23 insertions, 55 deletions
diff --git a/paludis/util/options.cc b/paludis/util/options.cc
index 0bbde8c..2445c45 100644
--- a/paludis/util/options.cc
+++ b/paludis/util/options.cc
@@ -18,48 +18,25 @@
*/
#include "options.hh"
-#include <paludis/util/pimp-impl.hh>
-#include <vector>
-#include <algorithm>
-#include <functional>
-#include <stdint.h>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/exception.hh>
using namespace paludis;
-namespace paludis
-{
- template<>
- struct Imp<OptionsStore>
- {
- std::vector<uint8_t> pool;
-
- Imp()
- {
- }
-
- Imp(const Imp & i) :
- pool(i.pool)
- {
- }
- };
-}
-
OptionsStore::OptionsStore() :
- Pimp<OptionsStore>()
+ _bits(0)
{
}
OptionsStore::OptionsStore(const OptionsStore & s) :
- Pimp<OptionsStore>(*s._imp.get())
+ _bits(s._bits)
{
}
const OptionsStore &
OptionsStore::operator= (const OptionsStore & s)
{
- if (this != &s)
- _imp.reset(new Imp<OptionsStore>(*s._imp.get()));
-
+ _bits = s._bits;
return *this;
}
@@ -70,60 +47,51 @@ OptionsStore::~OptionsStore()
void
OptionsStore::add(const unsigned e)
{
- if (_imp->pool.size() < e / 8 + 1)
- _imp->pool.resize(e / 8 + 1, 0);
+ if (e > (8 * sizeof(unsigned long)))
+ throw InternalError(PALUDIS_HERE, "options oversized");
- _imp->pool.at(e / 8) |= (1 << (e % 8));
+ _bits |= (1ul << e);
}
void
OptionsStore::remove(const unsigned e)
{
- if (_imp->pool.size() < e / 8 + 1)
- _imp->pool.resize(e / 8 + 1, 0);
+ if (e > (8 * sizeof(unsigned long)))
+ throw InternalError(PALUDIS_HERE, "options oversized");
- _imp->pool.at(e / 8) &= ~(1 << (e % 8));
+ _bits &= ~(1ul << e);
}
void
OptionsStore::combine(const OptionsStore & e)
{
- if (_imp->pool.size() < e._imp->pool.size())
- _imp->pool.resize(e._imp->pool.size(), 0);
-
- for (unsigned s(0), s_end(e._imp->pool.size()) ; s != s_end ; ++s)
- _imp->pool.at(s) |= e._imp->pool.at(s);
+ _bits |= e._bits;
}
void
OptionsStore::subtract(const OptionsStore & e)
{
- if (_imp->pool.size() < e._imp->pool.size())
- _imp->pool.resize(e._imp->pool.size(), 0);
-
- for (unsigned s(0), s_end(e._imp->pool.size()) ; s != s_end ; ++s)
- _imp->pool.at(s) &= ~e._imp->pool.at(s);
+ _bits &= ~e._bits;
}
bool
OptionsStore::test(const unsigned e) const
{
- if (_imp->pool.size() < e / 8 + 1)
- return false;
+ if (e > (8 * sizeof(unsigned long)))
+ throw InternalError(PALUDIS_HERE, "options oversized");
- return _imp->pool.at(e / 8) & (1 << (e % 8));
+ return 0 != (_bits & (1ul << e));
}
bool
OptionsStore::any() const
{
- return _imp->pool.end() != std::find_if(_imp->pool.begin(), _imp->pool.end(),
- std::bind2nd(std::not_equal_to<uint8_t>(), 0));
+ return 0 != _bits;
}
unsigned
OptionsStore::highest_bit() const
{
- return _imp->pool.size() * 8;
+ return sizeof(unsigned long) * 8;
}
diff --git a/paludis/util/options.hh b/paludis/util/options.hh
index 50874ee..bfe9681 100644
--- a/paludis/util/options.hh
+++ b/paludis/util/options.hh
@@ -21,7 +21,6 @@
#define PALUDIS_GUARD_PALUDIS_UTIL_OPTIONS_HH 1
#include <paludis/util/options-fwd.hh>
-#include <paludis/util/pimp.hh>
#include <paludis/util/attributes.hh>
/** \file
@@ -45,9 +44,11 @@ namespace paludis
* \see Options<>
* \ingroup g_data_structures
*/
- class PALUDIS_VISIBLE OptionsStore :
- private Pimp<OptionsStore>
+ class PALUDIS_VISIBLE OptionsStore
{
+ private:
+ unsigned long _bits;
+
public:
///\name Basic operations
///\{
diff --git a/paludis/util/options_TEST.cc b/paludis/util/options_TEST.cc
index 2d67f18..3de24b2 100644
--- a/paludis/util/options_TEST.cc
+++ b/paludis/util/options_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -92,7 +92,6 @@ namespace test_cases
options -= mo_seven;
TEST_CHECK(! options.any());
TEST_CHECK(options.highest_bit() >= static_cast<int>(last_mo));
- TEST_CHECK(options.highest_bit() <= 8 + static_cast<int>(last_mo));
}
} test_options;
}