Skip to content

Commit

Permalink
Remove own variant implementation, use C++17 std::variant instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Haefner committed Mar 28, 2022
1 parent 06dab86 commit eeb6610
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 451 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ endif()
# Reference the FindDBus module until an upstream one is available
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand Down
6 changes: 4 additions & 2 deletions include/simppl/detail/holders.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define SIMPPL_DETAIL_HOLDERS_H


#include <variant>

#include "callinterface.h"


Expand Down Expand Up @@ -128,10 +130,10 @@ struct PropertyCallbackHolder
DBusMessageIter iter;
dbus_message_iter_init(msg.get(), &iter);

simppl::Variant<DataT> v;
std::variant<DataT> v;
decode(iter, v);

that->f_(cs, *v.template get<DataT>());
that->f_(cs, std::get<DataT>(v));
}
else
that->f_(cs, DataT());
Expand Down
10 changes: 5 additions & 5 deletions include/simppl/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace simppl
{

namespace dbus
{

Expand Down Expand Up @@ -67,9 +67,9 @@ struct PropertyCodec
{
detail::VariantSerializer(iter).operator()(t);
}
static


static
void decode(DBusMessageIter& iter, T& t)
{
DBusMessageIter _iter;
Expand All @@ -78,7 +78,7 @@ struct PropertyCodec
Codec<T>::decode(_iter, t);

dbus_message_iter_next(&iter);
}
}
};


Expand Down
10 changes: 4 additions & 6 deletions include/simppl/serverside.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ struct BaseProperty : ServerPropertyBase

const DataT& value() const
{
const DataT* t = t_.template get<DataT>();
assert(t);
return *t;
return std::get<DataT>(t_);
}

static
Expand All @@ -283,7 +281,7 @@ struct BaseProperty : ServerPropertyBase
// missing initialization?
assert(!that->t_.empty());

detail::PropertyCodec<DataT>::encode(*iter, that->t_.template get<cb_type>() ? (*that->t_.template get<cb_type>())() : *that->t_.template get<DataT>());
detail::PropertyCodec<DataT>::encode(*iter, std::get_if<cb_type>(&that->t_) ? (std::get<cb_type>(that->t_))() : std::get<DataT>(that->t_));
}

/**
Expand Down Expand Up @@ -314,7 +312,7 @@ struct BaseProperty : ServerPropertyBase

protected:

Variant<DataT, cb_type> t_;
std::variant<DataT, cb_type> t_;
};


Expand Down Expand Up @@ -377,7 +375,7 @@ namespace detail
static
void eval(BaseProperty<DataT>& p, const DataT& d)
{
if (!p.t_.template get<DataT>() || PropertyComparator<DataT, (Flags & Always ? false : true)>::compare(p.value(), d))
if (!std::get_if<DataT>(&p.t_) || PropertyComparator<DataT, (Flags & Always ? false : true)>::compare(p.value(), d))
{
p.t_ = d;
p.notify(d);
Expand Down
1 change: 0 additions & 1 deletion include/simppl/stubbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "simppl/callstate.h"
#include "simppl/pendingcall.h"
#include "simppl/variant.h"

#include "simppl/detail/constants.h"
#include "simppl/detail/holders.h"
Expand Down
Loading

1 comment on commit eeb6610

@supersaiyanmode
Copy link
Contributor

@supersaiyanmode supersaiyanmode commented on eeb6610 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this library! :-)

A tiny suggestion/comment: this could have used __cplusplus preprocessor macro (Or a custom one being passed in via CMake) to conditionally compile instead of deleting simppl::Variant<> pieces. Would have helped retain C++14 compatibility.

Please sign in to comment.