Ref T459 Update xswiftbus dataref classes to the latest available and use C++11.

This commit is contained in:
Mat Sutcliffe
2018-12-16 20:45:59 +00:00
parent acdbf9d43d
commit ceb6ff7451
3 changed files with 16562 additions and 13329 deletions

View File

@@ -33,6 +33,7 @@ namespace XSwiftBus
{
XPLMDebugString("Missing dataref:");
XPLMDebugString(name);
XPLMDebugString("\n");
}
}
@@ -56,6 +57,7 @@ namespace XSwiftBus
{
XPLMDebugString("Missing dataref:");
XPLMDebugString(name);
XPLMDebugString("\n");
}
}
@@ -95,7 +97,7 @@ namespace XSwiftBus
using DataRefType = typename DataRefTraits::type;
//! Set the value of the dataref (if it is writable)
void set(DataRefType d) { DataRefImpl::implSet(d); }
void set(DataRefType d) { static_assert(DataRefTraits::writable, "read-only dataref"); DataRefImpl::implSet(d); }
//! Set as integer, avoids cast warnings such as "possible loss of data"
void setAsInt(int d) { this->set(static_cast<DataRefType>(d)); }
@@ -126,13 +128,13 @@ namespace XSwiftBus
using DataRefType = typename DataRefTraits::type;
//! Set the value of the whole array (if it is writable)
void setAll(std::vector<DataRefType> const &a) { ArrayDataRefImpl::implSetAll(a); }
void setAll(std::vector<DataRefType> const &a) { static_assert(DataRefTraits::writable, "read-only dataref"); ArrayDataRefImpl::implSetAll(a); }
//! Get the value of the whole array
std::vector<DataRefType> getAll() const { return ArrayDataRefImpl::implGetAll<DataRefType>(); }
//! Set the value of a single element (if it is writable)
void setAt(int index, DataRefType d) { ArrayDataRefImpl::implSetAt(index, d); }
void setAt(int index, DataRefType d) { static_assert(DataRefTraits::writable, "read-only dataref"); ArrayDataRefImpl::implSetAt(index, d); }
//! Get the value of a single element
DataRefType getAt(int index) const { return ArrayDataRefImpl::implGetAt<DataRefType>(index); }
@@ -154,6 +156,7 @@ namespace XSwiftBus
{
XPLMDebugString("Missing dataref:");
XPLMDebugString(DataRefTraits::name());
XPLMDebugString("\n");
}
}
@@ -165,11 +168,21 @@ namespace XSwiftBus
//! Set the value of part of the string (if it is writable)
void setSubstr(size_t offset, std::string const &s)
{ assert((s.size() + 1) <= (DataRefTraits::size - offset)); XPLMSetDatab(m_ref, (void *)s.c_str(), (int)offset, (int)s.size() + 1); }
{
static_assert(DataRefTraits::writable, "read-only dataref");
assert((s.size() + 1) <= (DataRefTraits::size - offset));
XPLMSetDatab(m_ref, (void *)s.c_str(), (int)offset, (int)s.size() + 1);
}
//! Get the value of part of the string
std::string getSubstr(size_t offset, size_t size) const
{ std::string s(size, 0); XPLMGetDatab(m_ref, &s[0], (int)offset, (int)size); size = s.find(char(0)); if (size != std::string::npos) s.resize(size); return s; }
{
std::string s(size, 0);
XPLMGetDatab(m_ref, &s[0], (int)offset, (int)size);
size = s.find(char(0));
if (size != std::string::npos) s.resize(size);
return s;
}
private:
XPLMDataRef m_ref;

File diff suppressed because it is too large Load Diff

View File

@@ -2,10 +2,17 @@
#
# Script to generate C++ traits classes for all X-Plane datarefs.
#
# Copyright (C) 2014 VATSIM Community / contributors
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
# Copyright (C) 2014 swift Project Community / contributors
#
# This program 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.
#
# This program 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.
use strict;
use warnings;
@@ -118,19 +125,19 @@ ${in}//! $comment
${in}struct $key
${in}{
${in}${indent}//! Dataref name
${in}${indent}static const char *name() { return "$name"; }
${in}${indent}static constexpr const char *name() { return "$name"; }
${in}${indent}//! Can be written to?
${in}${indent}static const bool writable = $writable;
${in}${indent}static constexpr bool writable = $writable;
EOF
print <<"EOF" if $type =~ m(int|float|double);
${in}${indent}//! Dataref type
${in}${indent}typedef $type type;
${in}${indent}using type = $type;
EOF
print <<"EOF" if defined $size;
${in}${indent}//! Size of array dataref
${in}${indent}static const size_t size = $size;
${in}${indent}static constexpr size_t size = $size;
EOF
print <<"EOF";