/// /// \file Proxy/ProxyImpl.hpp /// /// Proxy template method implementations. /// /// \copyright /// Copyright (c) 2013-2017 Josh Blum /// 2021 Nicholas Corgan /// SPDX-License-Identifier: BSL-1.0 /// #pragma once #include #include #include #include #include #include //enable_if #include //std::forward #include #include namespace Pothos { template ValueType Proxy::convert(void) const { return this->getEnvironment()->convertProxyToObject(*this).convert(); } namespace Detail { /*********************************************************************** * convertProxy either converts a proxy to a desired type * or returns a proxy if the requested type was a proxy **********************************************************************/ template typename std::enable_if::value, T>::type convertProxy(const Proxy &p) { return p.convert(); } template typename std::enable_if::value, T>::type convertProxy(const Proxy &p) { return p; } /*********************************************************************** * makeProxy either makes a proxy from an arbitrary type * or returns a proxy if the type is already a proxy **********************************************************************/ template typename std::enable_if::type, Proxy>::value, Proxy>::type makeProxy(const ProxyEnvironment::Sptr &env, T &&value) { return env->makeProxy(std::forward(value)); } template typename std::enable_if::type, Proxy>::value, Proxy>::type makeProxy(const ProxyEnvironment::Sptr &, T &&value) { // Explicitly copy the input proxy. This removes a Clang warning that says // that this happens anyway. Since the proxy class only stores a shared_ptr // to the implementation, this operation is cheap. return T(value); } } //namespace Detail template Proxy::operator ValueType(void) const { return this->convert(); } template ReturnType Proxy::call(const std::string &name, ArgsType&&... args) const { Proxy ret = this->call(name, std::forward(args)...); return Detail::convertProxy(ret); } template Proxy Proxy::call(const std::string &name, ArgsType&&... args) const { const std::array proxyArgs{{Detail::makeProxy(this->getEnvironment(), std::forward(args))...}}; auto handle = this->getHandle(); assert(handle); return handle->call(name, proxyArgs.data(), sizeof...(args)); } template Proxy Proxy::callProxy(const std::string &name, ArgsType&&... args) const { return this->call(name, std::forward(args)...); } template void Proxy::callVoid(const std::string &name, ArgsType&&... args) const { this->call(name, std::forward(args)...); } template ReturnType Proxy::get(const std::string &name) const { return this->call("get:"+name); } template void Proxy::set(const std::string &name, ValueType&& value) const { this->call("set:"+name, std::forward(value)); } template Proxy Proxy::operator()(ArgsType&&... args) const { return this->call("()", std::forward(args)...); } } //namespace Pothos