[DEV] add move & copy operator in Map
This commit is contained in:
parent
aa572c8d98
commit
d4cc68f7e3
@ -165,5 +165,17 @@ namespace etk {
|
||||
|
||||
}
|
||||
};
|
||||
class RuntimeError : public etk::Exception {
|
||||
public:
|
||||
/**
|
||||
* @brief Contructor of an generic Exception.
|
||||
* @param[in] _what The explanation of the problem.
|
||||
* @param[in] _function Function name to find faster the source od the problem.
|
||||
*/
|
||||
RuntimeError(const etk::String& _what, const char* _function = nullptr):
|
||||
etk::Exception("RUNTIME-ERROR", _what, _function) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace etk {
|
||||
class FunctionPrivateLambda<ETK_TYPE_FUNCTION_FUNCTOR, ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>:
|
||||
public FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> {
|
||||
private:
|
||||
ETK_TYPE_FUNCTION_FUNCTOR m_dataPointer;
|
||||
mutable ETK_TYPE_FUNCTION_FUNCTOR m_dataPointer;
|
||||
public:
|
||||
FunctionPrivateLambda(ETK_TYPE_FUNCTION_FUNCTOR _functor):
|
||||
m_dataPointer(_functor) {
|
||||
|
50
etk/Map.hpp
50
etk/Map.hpp
@ -244,12 +244,37 @@ namespace etk {
|
||||
/**
|
||||
* @brief Constructor of the Map table.
|
||||
* @param[in] _count Number of basic element in the table.
|
||||
* @param[in] _ordered select an ordered map or an onordered map.
|
||||
*/
|
||||
Map(int32_t _count = 0, bool _ordered=true) :
|
||||
m_data(_count),
|
||||
m_ordered(_ordered) {
|
||||
// nothing to do
|
||||
}
|
||||
/**
|
||||
* @brief Move constructor
|
||||
* @param[in] _obj Other Map to move
|
||||
*/
|
||||
Map(Map&& _obj):
|
||||
m_data(0),
|
||||
m_ordered(true) {
|
||||
_obj.swap(*this);
|
||||
}
|
||||
/**
|
||||
* @brief Copy constructor
|
||||
* @param[in] _obj Other Map to copy
|
||||
*/
|
||||
Map(const Map& _obj) :
|
||||
m_data(),
|
||||
m_ordered(_obj.m_ordered) {
|
||||
m_data.reserve(_obj.m_data.size());
|
||||
for (auto &it : _obj.m_data) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
m_data.pushBack(new etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>(it->first, it->second));
|
||||
}
|
||||
}
|
||||
void setOrdered(bool _ordered) {
|
||||
m_ordered = _ordered;
|
||||
if (m_ordered == true) {
|
||||
@ -262,6 +287,31 @@ namespace etk {
|
||||
~Map() {
|
||||
clear();
|
||||
}
|
||||
/**
|
||||
* @brief Swap two map
|
||||
* @param[in] _obj Other Map to swap with
|
||||
*/
|
||||
void swap(Map& _obj) {
|
||||
etk::swap(m_data, _obj.m_data);
|
||||
etk::swap(m_ordered, _obj.m_ordered);
|
||||
}
|
||||
/**
|
||||
* @brief Move operator
|
||||
* @param[in] _obj Other Map to move
|
||||
*/
|
||||
Map& operator=(Map&& _obj) {
|
||||
_obj.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* @brief Copy operator
|
||||
* @param[in] _obj Other Map to copy
|
||||
*/
|
||||
Map& operator=(const Map& _obj) {
|
||||
Map tmp(_obj);
|
||||
tmp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* @brief Remove all entry in the Map table.
|
||||
* @note It does not delete pointer if your value is a pointer type...
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/move.hpp>
|
||||
#include <etk/Stream.hpp>
|
||||
|
||||
namespace etk {
|
||||
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
|
||||
|
@ -580,6 +580,12 @@ bool etk::String::to<bool>() const {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::String& _obj) {
|
||||
_os << _obj.c_str();
|
||||
return _os;
|
||||
}
|
||||
|
||||
void etk::sort(etk::Vector<etk::String *> &_list) {
|
||||
etk::Vector<etk::String *> tmpList(_list);
|
||||
_list.clear();
|
||||
|
@ -519,6 +519,8 @@ namespace etk {
|
||||
inline bool operator<= (const char* _left, const String& _right) {
|
||||
return _right <= _left;
|
||||
}
|
||||
//! @not_in_doc
|
||||
etk::Stream& operator <<(etk::Stream& _os, const etk::String& _obj);
|
||||
/**
|
||||
* @brief Template to declare conversion from anything in etk::String
|
||||
* @param[in] _variable Variable to convert
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <etk/types.hpp>
|
||||
//#include <etk/debug.hpp>
|
||||
#include <etk/Stream.hpp>
|
||||
|
||||
namespace etk {
|
||||
class Stream;
|
||||
@ -878,4 +879,18 @@ namespace etk {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class Stream;
|
||||
//! @not_in_doc
|
||||
template<class ETK_VECTOR_TYPE>
|
||||
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
||||
_os << "{";
|
||||
for (size_t iii=0; iii< _obj.size(); iii++) {
|
||||
if (iii>0) {
|
||||
_os << ";";
|
||||
}
|
||||
_os << _obj[iii];
|
||||
}
|
||||
_os << "}";
|
||||
return _os;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/Stream.hpp>
|
||||
|
||||
extern "C" {
|
||||
#include <math.h>
|
||||
|
@ -56,5 +56,5 @@ ETK_DECLARE_TYPE(etk::exception::OverflowError);
|
||||
ETK_DECLARE_TYPE(etk::exception::UnderflowError);
|
||||
ETK_DECLARE_TYPE(etk::exception::CastError);
|
||||
ETK_DECLARE_TYPE(etk::exception::AllocationError);
|
||||
|
||||
ETK_DECLARE_TYPE(etk::exception::RuntimeError);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user