Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial release of etl::map without balance #1

Merged
merged 1 commit into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,779 changes: 1,779 additions & 0 deletions imap.h

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
///\file

/******************************************************************************
The MIT License(MIT)

Embedded Template Library.

Copyright(c) 2014 jwellbelove, rlindeman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#ifndef __ETL_MAP__
#define __ETL_MAP__

#include <stddef.h>
#include <iterator>
#include <functional>

#include "imap.h"
#include "container.h"
#include "pool.h"

//*****************************************************************************
///\defgroup map map
/// A map with the capacity defined at compile time.
///\ingroup containers
//*****************************************************************************

namespace etl
{
//*************************************************************************
/// A templated map implementation that uses a fixed size buffer.
//*************************************************************************
template <typename TKey, typename TValue, const size_t MAX_SIZE_, typename TCompare = std::less<TKey>>
class map : public imap<TKey, TValue, TCompare>
{
public:

static const size_t MAX_SIZE = MAX_SIZE_;

//*************************************************************************
/// Default constructor.
//*************************************************************************
map()
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
{
}

//*************************************************************************
/// Copy constructor.
//*************************************************************************
explicit map(const map& other)
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
{
imap<TKey, TValue, TCompare>::assign(other.cbegin(), other.cend());
}

//*************************************************************************
/// Constructor, from an iterator range.
///\tparam TIterator The iterator type.
///\param first The iterator to the first element.
///\param last The iterator to the last element + 1.
//*************************************************************************
template <typename TIterator>
map(TIterator first, TIterator last)
: imap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
{
imap<TKey, TValue, TCompare>::insert(first, last);
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
map& operator = (const map& rhs)
{
// Skip if doing self assignment
if (this != &rhs)
{
imap<TKey, TValue, TCompare>::assign(rhs.cbegin(), rhs.cend());
}

return *this;
}

private:

/// The pool of data nodes used for the map.
pool<typename imap<TKey, TValue, TCompare>::Data_Node, MAX_SIZE> node_pool;
};

}

#endif
174 changes: 174 additions & 0 deletions map_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
///\file

/******************************************************************************
The MIT License(MIT)

Embedded Template Library.

Copyright(c) 2014 jwellbelove, rlindeman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#ifndef __ETL_IN_IMAP_H__
#error This header is a private element of etl::map & etl::imap
#endif

#ifndef __ETL_MAP_BASE__
#define __ETL_MAP_BASE__

#include <stddef.h>
#include "exception.h"

namespace etl
{
//***************************************************************************
/// Exception for the map.
///\ingroup map
//***************************************************************************
class map_exception : public exception
{
public:

map_exception(const char* what)
: exception(what)
{
}
};

//***************************************************************************
/// Full exception for the map.
///\ingroup map
//***************************************************************************
class map_full : public map_exception
{
public:

map_full()
: map_exception("map: full")
{
}
};

//***************************************************************************
/// Map out of bounds exception.
///\ingroup map
//***************************************************************************
class map_out_of_bounds : public map_exception
{
public:

map_out_of_bounds()
: map_exception("map: out of bounds")
{
}
};

//***************************************************************************
/// Iterator exception for the map.
///\ingroup map
//***************************************************************************
class map_iterator : public map_exception
{
public:

map_iterator()
: map_exception("map: iterator problem")
{
}
};

//***************************************************************************
/// The base class for all maps.
///\ingroup map
//***************************************************************************
class map_base
{
public:

typedef size_t size_type; ///< The type used for determining the size of map.

//*************************************************************************
/// Gets the size of the map.
//*************************************************************************
size_type size() const
{
return current_size;
}

//*************************************************************************
/// Gets the maximum possible size of the map.
//*************************************************************************
size_type max_size() const
{
return MAX_SIZE;
}

//*************************************************************************
/// Checks to see if the map is empty.
//*************************************************************************
bool empty() const
{
return current_size == 0;
}

//*************************************************************************
/// Checks to see if the map is full.
//*************************************************************************
bool full() const
{
return current_size == MAX_SIZE;
}

//*************************************************************************
/// Returns the capacity of the vector.
///\return The capacity of the vector.
//*************************************************************************
size_type capacity() const
{
return MAX_SIZE;
}

//*************************************************************************
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t available() const
{
return max_size() - size();
}

protected:

//*************************************************************************
/// The constructor that is called from derived classes.
//*************************************************************************
map_base(size_type max_size)
: current_size(0)
, MAX_SIZE(max_size)

{
}

size_type current_size; ///< The number of the used nodes.
const size_type MAX_SIZE; ///< The maximum size of the map.
};
}

#endif
4 changes: 4 additions & 0 deletions test/codeblocks/ETL.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<Unit filename="../../iforward_list.h" />
<Unit filename="../../ilist.h" />
<Unit filename="../../ilookup.h" />
<Unit filename="../../imap.h" />
<Unit filename="../../instance_count.h" />
<Unit filename="../../integral_limits.h" />
<Unit filename="../../iqueue.h" />
Expand All @@ -160,6 +161,8 @@
<Unit filename="../../log.h" />
<Unit filename="../../lookup.h" />
<Unit filename="../../lookup_base.h" />
<Unit filename="../../map.h" />
<Unit filename="../../map_base.h" />
<Unit filename="../../nullptr.h" />
<Unit filename="../../numeric.h" />
<Unit filename="../../observer.h" />
Expand Down Expand Up @@ -203,6 +206,7 @@
<Unit filename="../test_largest.cpp" />
<Unit filename="../test_list.cpp" />
<Unit filename="../test_lookup.cpp" />
<Unit filename="../test_map.cpp" />
<Unit filename="../test_maths.cpp" />
<Unit filename="../test_numeric.cpp" />
<Unit filename="../test_observer.cpp" />
Expand Down
31 changes: 31 additions & 0 deletions test/codeblocks/ETL.depend
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@
<list>
<vector>

1421601674 source:u:\users\john\documents\programming\github\etl\test\test_map.cpp
<UnitTest++/UnitTest++.h>
"ExtraCheckMacros.h"
"../map.h"
"data.h"
<algorithm>
<array>
<map>
<vector>

1418906586 u:\users\john\documents\programming\github\etl\test\extracheckmacros.h
<UnitTest++/HelperMacros.h>
<UnitTest++/ExceptionMacros.h>
Expand All @@ -358,6 +368,12 @@
"container.h"
"pool.h"

1421601517 u:\users\john\documents\programming\github\etl\map.h
<stddef.h>
"imap.h"
"container.h"
"pool.h"

1421608839 u:\users\john\documents\programming\github\etl\ilist.h
<iterator>
<algorithm>
Expand All @@ -369,10 +385,25 @@
"parameter_type.h"
"pool.h"

1421608839 u:\users\john\documents\programming\github\etl\imap.h
<iterator>
<algorithm>
<functional>
<stddef.h>
"nullptr.h"
"map_base.h"
"type_traits.h"
"parameter_type.h"
"pool.h"

1421068120 u:\users\john\documents\programming\github\etl\list_base.h
<stddef.h>
"exception.h"

1421068120 u:\users\john\documents\programming\github\etl\map_base.h
<stddef.h>
"exception.h"

1414930704 source:u:\users\john\documents\programming\github\etl\test\test_math.cpp
<UnitTest++/UnitTest++.h>
"../log.h"
Expand Down
10 changes: 10 additions & 0 deletions test/codeblocks/ETL.layout
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<Cursor1 position="17660" topLine="539" />
</Cursor>
</File>
<File name="..\..\imap.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="17660" topLine="539" />
</Cursor>
</File>
<File name="..\..\ilookup.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="10573" topLine="244" />
Expand Down Expand Up @@ -96,6 +101,11 @@
<Cursor1 position="5955" topLine="137" />
</Cursor>
</File>
<File name="..\..\map.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="5955" topLine="137" />
</Cursor>
</File>
<File name="..\..\endian.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2235" topLine="37" />
Expand Down
Loading