Skip to content

Commit

Permalink
simple client calls for usable/settable
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Oct 3, 2024
1 parent 73a0a81 commit 4a087af
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
17 changes: 6 additions & 11 deletions src/core/data/ions/ion_population/ion_population.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#ifndef PHARE_ION_POPULATION_HPP
#define PHARE_ION_POPULATION_HPP

#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <tuple>
#include <array>
#include <string>
#include <sstream>


#include "core/def.hpp"
#include "core/hybrid/hybrid_quantities.hpp"
#include "initializer/data_provider.hpp"
#include "particle_pack.hpp"
#include "initializer/data_provider.hpp"
#include "core/hybrid/hybrid_quantities.hpp"

namespace PHARE
{
Expand Down Expand Up @@ -52,15 +49,13 @@ namespace core

NO_DISCARD bool isUsable() const
{
return particles_.isUsable() && rho_.isUsable() && flux_.isUsable()
&& momentumTensor_.isUsable();
return core::isUsable(particles_, rho_, flux_, momentumTensor_);
}


NO_DISCARD bool isSettable() const
{
return particles_.isSettable() && rho_.isSettable() && flux_.isSettable()
&& momentumTensor_.isSettable();
return core::isSettable(particles_, rho_, flux_, momentumTensor_);
}

NO_DISCARD auto& domainParticles() const { return particles_.domainParticles(); }
Expand Down
14 changes: 3 additions & 11 deletions src/core/data/ions/ion_population/particle_pack.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PHARE_CORE_DATA_PARTICLES_PARTICLE_PACK_HPP
#define PHARE_CORE_DATA_PARTICLES_PARTICLE_PACK_HPP

#include "core/def.hpp"
#include "core/data/particles/particle_array.hpp"

namespace PHARE
Expand Down Expand Up @@ -36,25 +37,16 @@ namespace core

auto& name() const { return _name; }

auto _as_tuple() const
{
return std::forward_as_tuple(_domainParticles, _patchGhostParticles,
_levelGhostParticles);
}

NO_DISCARD bool isUsable() const
{
auto tup = _as_tuple();
return for_N_all<std::tuple_size_v<pointer_tuple_t>>(
[&](auto i) { return std::get<i>(tup) != nullptr; });
return core::isUsable(_domainParticles, _patchGhostParticles, _levelGhostParticles);
}


NO_DISCARD bool isSettable() const
{
auto tup = _as_tuple();
return for_N_all<std::tuple_size_v<pointer_tuple_t>>(
[&](auto i) { return std::get<i>(tup) == nullptr; });
return core::isSettable(_domainParticles, _patchGhostParticles, _levelGhostParticles);
}


Expand Down
35 changes: 35 additions & 0 deletions src/core/def.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
#ifndef PHARE_CORE_DEF_HPP
#define PHARE_CORE_DEF_HPP

#include <type_traits>

#define NO_DISCARD [[nodiscard]]

#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO)
#define PHARE_DEBUG_DO(...) __VA_ARGS__
#else
#define PHARE_DEBUG_DO(...)
#endif

#define _PHARE_TO_STR(x) #x // convert macro text to string
#define PHARE_TO_STR(x) _PHARE_TO_STR(x)

#define PHARE_TOKEN_PASTE(x, y) x##y
#define PHARE_STR_CAT(x, y) PHARE_TOKEN_PASTE(x, y)


namespace PHARE::core
{
template<typename... Args>
NO_DISCARD bool isUsable(Args const&... args)
{
auto check = [](auto const& arg) {
if constexpr (std::is_pointer_v<std::decay_t<decltype(arg)>>)
return arg != nullptr;
else
return arg.isUsable();
};
return (check(args) && ...);
}

template<typename... Args>
NO_DISCARD bool isSettable(Args const&... args)
{
auto check = [](auto const& arg) {
if constexpr (std::is_pointer_v<std::decay_t<decltype(arg)>>)
return arg == nullptr;
else
return arg.isSettable();
};
return (check(args) && ...);
}
} // namespace PHARE::core

#endif // PHARE_CORE_DEF_HPP
9 changes: 1 addition & 8 deletions src/core/utilities/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@

#include "cppdict/include/dict.hpp"

#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO)
#define PHARE_DEBUG_DO(...) __VA_ARGS__
#else
#define PHARE_DEBUG_DO(...)
#endif

#define _PHARE_TO_STR(x) #x // convert macro text to string
#define PHARE_TO_STR(x) _PHARE_TO_STR(x)


namespace PHARE
{
Expand Down

0 comments on commit 4a087af

Please sign in to comment.