96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
/* Copyright 2022, Michele Santullo
|
|
* This file is part of duckticker.
|
|
*
|
|
* Wrenpp is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Wrenpp is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with duckticker. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "ticker_price.hpp"
|
|
#include <wrenpp/vm_fun.hpp>
|
|
#include <wrenpp/callback_manager.hpp>
|
|
#include <wrenpp/class_manager.hpp>
|
|
#include <utility>
|
|
|
|
namespace duck {
|
|
const std::string_view g_ticker_price_wren_module {
|
|
R"wren(foreign class TickerPrice {
|
|
construct new() { }
|
|
|
|
foreign price
|
|
foreign timestamp
|
|
foreign currency
|
|
foreign exchange
|
|
foreign is_valid
|
|
}
|
|
)wren"};
|
|
|
|
TickerPrice::TickerPrice (
|
|
double price,
|
|
std::uint64_t timestamp,
|
|
std::string&& currency,
|
|
std::string&& exchange
|
|
) :
|
|
m_price(price),
|
|
m_timestamp(timestamp),
|
|
m_currency(std::move(currency)),
|
|
m_exchange(std::move(exchange))
|
|
{}
|
|
|
|
void TickerPrice::set_price (double price) {
|
|
m_price = price;
|
|
}
|
|
|
|
void TickerPrice::set_timestamp(std::uint64_t timestamp) {
|
|
m_timestamp = timestamp;
|
|
}
|
|
|
|
void TickerPrice::set_currency (std::string&& currency) {
|
|
m_currency = std::move(currency);
|
|
}
|
|
|
|
void TickerPrice::set_exchange (std::string&& exchange) {
|
|
m_exchange = std::move(exchange);
|
|
}
|
|
|
|
double TickerPrice::price() const noexcept {
|
|
return m_price;
|
|
}
|
|
|
|
std::uint64_t TickerPrice::timestamp() const noexcept {
|
|
return m_timestamp;
|
|
}
|
|
|
|
const char* TickerPrice::currency() const noexcept {
|
|
return m_currency.c_str();
|
|
}
|
|
|
|
const char* TickerPrice::exchange() const noexcept {
|
|
return m_exchange.c_str();
|
|
}
|
|
|
|
bool TickerPrice::is_valid() const noexcept {
|
|
return not m_exchange.empty();
|
|
}
|
|
|
|
void register_ticker_price_to_wren(wren::VM& vm) {
|
|
vm.callback_manager()
|
|
.add_callback(false, "ticker_price", "TickerPrice", "price", wren::make_method_bindable<&TickerPrice::price>())
|
|
.add_callback(false, "ticker_price", "TickerPrice", "timestamp", wren::make_method_bindable<&TickerPrice::timestamp>())
|
|
.add_callback(false, "ticker_price", "TickerPrice", "currency", wren::make_method_bindable<&TickerPrice::currency>())
|
|
.add_callback(false, "ticker_price", "TickerPrice", "is_valid", wren::make_method_bindable<&TickerPrice::is_valid>())
|
|
.add_callback(false, "ticker_price", "TickerPrice", "exchange", wren::make_method_bindable<&TickerPrice::exchange>());
|
|
vm.class_manager()
|
|
.add_class_maker("ticker_price", "TickerPrice", &wren::make_foreign_class<duck::TickerPrice>);
|
|
}
|
|
} //namespace duck
|