Skip to content

Commit

Permalink
Release v2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Sep 18, 2019
2 parents 3bc69ba + 3950e23 commit 9bd72ff
Show file tree
Hide file tree
Showing 33 changed files with 483 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ endwhile ()
include(GNUInstallDirs)

if ("${CC_TAG}" STREQUAL "")
set (CC_TAG "v2.0.2")
set (CC_TAG "v2.1")
endif()

add_subdirectory(lib)
Expand Down
9 changes: 7 additions & 2 deletions app/commsdsl2comms/src/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool Field::prepare(unsigned parentVersion)
m_parentVersion = parentVersion;
m_customRead = m_generator.getCustomReadForField(m_externalRef);
m_customRefresh = m_generator.getCustomRefreshForField(m_externalRef);
m_customWrite = m_generator.getCustomWriteForField(m_externalRef);
return prepareImpl();
}

Expand Down Expand Up @@ -1073,6 +1074,10 @@ void Field::updateExtraOptions(
common::addToList("comms::option::def::HasCustomRefresh", options);
}

if (!m_customWrite.empty()) {
common::addToList("comms::option::def::HasCustomWrite", options);
}

if (m_forcedPseudo || m_dslObj.isPseudo()) {
common::addToList("comms::option::def::EmptySerialization", options);
}
Expand All @@ -1085,9 +1090,9 @@ const std::string& Field::getCustomRead() const
return m_customRead;
}

std::string Field::getCustomWrite() const
const std::string& Field::getCustomWrite() const
{
return m_generator.getCustomWriteForField(m_externalRef);
return m_customWrite;
}

std::string Field::getCustomLength() const
Expand Down
3 changes: 2 additions & 1 deletion app/commsdsl2comms/src/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class Field
bool ignoreFailOnInvalid = false) const;

const std::string& getCustomRead() const;
std::string getCustomWrite() const;
const std::string& getCustomWrite() const;
std::string getCustomLength() const;
std::string getCustomValid() const;
const std::string& getCustomRefresh() const;
Expand Down Expand Up @@ -301,6 +301,7 @@ class Field
unsigned m_parentVersion = 0U;
std::string m_customRead;
std::string m_customRefresh;
std::string m_customWrite;
bool m_focedFailOnInvalid = false;
bool m_forcedPseudo = false;
bool m_forcedNoOptionsConfig = false;
Expand Down
112 changes: 110 additions & 2 deletions app/commsdsl2comms/src/FloatField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <type_traits>
#include <cmath>
#include <limits>
#include <map>
#include <set>

#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -332,13 +334,119 @@ std::string FloatField::getClassDefinitionImpl(
std::string FloatField::getPluginPropertiesImpl(bool serHiddenParam) const
{
static_cast<void>(serHiddenParam);
common::StringsList props;
auto obj = floatFieldDslObj();
auto decimals = obj.displayDecimals();
if (decimals == 0U) {
if (decimals != 0U) {
props.push_back(".decimals(" + common::numToString(decimals) + ")");
}

do {
if (!obj.displaySpecials()) {
break;
}

auto& specials = obj.specialValues();
if (specials.empty()) {
break;
}

auto addSpecDisplayNameFunc =
[&props](double val, const std::string& name, const std::string& displayName)
{
std::string valStr;
if (std::isnan(val)) {
valStr = "std::numeric_limits<double>::quiet_NaN()";
}
else if (std::isinf(val)) {
valStr = "std::numeric_limits<double>::infinity()";
if (val < 0.0) {
valStr = '-' + valStr;
}
}
else {
valStr = std::to_string(val);
}

auto* nameToAdd = &displayName;
if (nameToAdd->empty()) {
nameToAdd = &name;
}

props.push_back(".addSpecial(\"" + *nameToAdd + "\", " + valStr + ")");
};

for (auto& s : specials) {
addSpecDisplayNameFunc(s.second.m_value, s.first, s.second.m_displayName);
}
break;

// The code below removes duplicates, but probably not needed.
// if (!obj.hasNonUniqueSpecials()) {
// for (auto& s : specials) {
// addSpecDisplayNameFunc(s.second.m_value, s.first, s.second.m_displayName);
// }
// break;
// }

// using SpecialsDisplayMap = std::multimap<double, std::pair<const std::string*, const std::string*> >;
// using SpecialsValuesSet = std::set<double>;
// using SpecialsNanList = std::vector<std::pair<const std::string*, const std::string*> >;

// SpecialsDisplayMap displayMap;
// SpecialsValuesSet specialsSet;
// SpecialsNanList specialNans;
// for (auto& s : specials) {
// if (std::isnan(s.second.m_value)) {
// specialNans.push_back(std::make_pair(&s.first, &s.second.m_displayName));
// continue;
// }

// specialsSet.insert(s.second.m_value);
// displayMap.insert(std::make_pair(s.second.m_value, std::make_pair(&s.first, &s.second.m_displayName)));
// }

// if (!specialNans.empty()) {
// auto nanIter =
// std::find_if(
// specialNans.begin(), specialNans.end(),
// [](auto& elem)
// {
// return !elem.second->empty();
// });

// if (nanIter == specialNans.end()) {
// nanIter = specialNans.begin();
// }

// assert(nanIter != specialNans.end());
// addSpecDisplayNameFunc(std::numeric_limits<double>::quiet_NaN(), *nanIter->first, *nanIter->second);
// }

// for (auto val : specialsSet) {
// auto mapIter = displayMap.equal_range(val);
// assert(mapIter.first != mapIter.second);
// auto iter =
// std::find_if(
// mapIter.first, mapIter.second,
// [](auto& elem)
// {
// return !elem.second.second->empty(); // displayName is not empty
// });
// if (iter == mapIter.second) {
// iter = mapIter.first;
// }

// addSpecDisplayNameFunc(val, *(iter->second.first), *(iter->second.second));
// }

} while (false);

if (props.empty()) {
return common::emptyString();
}
return common::listToString(props, "\n", common::emptyString());

return ".decimals(" + common::numToString(decimals) + ")";
}

std::string FloatField::getFieldBaseParams() const
Expand Down
2 changes: 1 addition & 1 deletion app/commsdsl2comms/src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace
{

const unsigned MaxDslVersion = 2U;
const std::string MinCommsVersionStr("2, 0, 2");
const std::string MinCommsVersionStr("2, 1, 0");
const std::string ScopeSep("::");
const std::string ReplaceSuffix(".replace");
const std::string ExtendSuffix(".extend");
Expand Down
28 changes: 28 additions & 0 deletions app/commsdsl2comms/src/IntField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,34 @@ std::string IntField::getPluginPropertiesImpl(bool serHiddenParam) const
props.push_back(".displayOffset(" + common::numToString(offset) + ')');
}

auto& specials = obj.specialValues();
if (!specials.empty() && (obj.displaySpecials())) {
auto type = obj.type();
bool bigUnsigned =
(type == commsdsl::IntField::Type::Uint64) ||
(type == commsdsl::IntField::Type::Uintvar);

auto addSpecDisplayNameFunc =
[&props, bigUnsigned](std::intmax_t val, const std::string& name, const std::string& displayName)
{
auto valStr = common::numToString(val);
if (bigUnsigned) {
valStr = "static_cast<long long>(" + common::numToString(static_cast<std::uintmax_t>(val)) + ")";
}

auto* nameToAdd = &displayName;
if (nameToAdd->empty()) {
nameToAdd = &name;
}

props.push_back(".addSpecial(\"" + *nameToAdd + "\", " + valStr + ")");
};

for (auto& s : specials) {
addSpecDisplayNameFunc(s.second.m_value, s.first, s.second.m_displayName);
}
}

if (props.empty()) {
return common::emptyString();
}
Expand Down
2 changes: 1 addition & 1 deletion app/commsdsl2comms/src/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ bool Interface::writePluginSrc()
auto func =
"QString " + className + "::idAsStringImpl() const\n"
"{\n"
" return QString(\"0x%1\").arg(static_cast<unsigned long long>(getId()), " +
" return \"0x\" + QString(\"%1\").arg(static_cast<unsigned long long>(getId()), " +
std::to_string(hexWidth) + ", 16, QChar('0')).toUpper();\n"
"}\n";
replacements.insert(std::make_pair("ID_FUNC", std::move(func)));
Expand Down
2 changes: 2 additions & 0 deletions app/commsdsl2comms/src/ListField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ std::string ListField::getPluginPropertiesImpl(bool serHiddenParam) const
props.push_back(".prefixName(\"" + getPrefixName() + "\")");
props.push_back(".showPrefix()");
} while (false);

props.push_back(".appendIndexToElementName()");
return common::listToString(props, "\n", common::emptyString());
}

Expand Down
2 changes: 1 addition & 1 deletion app/commsdsl2comms/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,6 @@ test_func (test34)
test_func (test35)
test_func (test36)
test_func (test37)
#test_func (test38)
test_func (test38)


1 change: 1 addition & 0 deletions app/commsdsl2comms/test/test4/Schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<validRange value="[5, 10]" deprecated="2" />
<validValue value="20" sinceVersion="2" />
<validRange value="[30, 40]" sinceVersion="3" />
<special name="S1" val="5" />
</int>
<int name="I3" type="uint32" />
</fields>
Expand Down
2 changes: 1 addition & 1 deletion app/commsdsl2comms/test/test9/Schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<float name="F1" type="float" defaultValue="null">
<special name="null" val="NaN" />
<special name="s1" val="-inf" />
<special name="s1" val="-inf" displayName="Special 1"/>
<special name="s2" val="inf" />
<special name="s3" val="1.3" />
<special name="s4" val="1.4" />
Expand Down
3 changes: 3 additions & 0 deletions lib/include/commsdsl/FloatField.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class COMMSDSL_API FloatField : public Field
unsigned m_sinceVersion = 0;
unsigned m_deprecatedSince = Protocol::notYetDeprecated();
std::string m_description;
std::string m_displayName;
};
using SpecialValues = std::map<std::string, SpecialValueInfo>;

Expand All @@ -69,6 +70,8 @@ class COMMSDSL_API FloatField : public Field
bool validCheckVersion() const;
Units units() const;
unsigned displayDecimals() const;
bool displaySpecials() const;
bool hasNonUniqueSpecials() const;
};

inline
Expand Down
2 changes: 2 additions & 0 deletions lib/include/commsdsl/IntField.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class COMMSDSL_API IntField : public Field
unsigned m_sinceVersion = 0;
unsigned m_deprecatedSince = Protocol::notYetDeprecated();
std::string m_description;
std::string m_displayName;
};

using SpecialValues = std::map<std::string, SpecialValueInfo>;
Expand All @@ -88,6 +89,7 @@ class COMMSDSL_API IntField : public Field
unsigned displayDecimals() const;
std::intmax_t displayOffset() const;
bool signExt() const;
bool displaySpecials() const;
};

inline
Expand Down
2 changes: 1 addition & 1 deletion lib/include/commsdsl/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define COMMSDSL_MAJOR_VERSION 2U

/// @brief Minor verion of the library
#define COMMSDSL_MINOR_VERSION 3U
#define COMMSDSL_MINOR_VERSION 4U

/// @brief Patch level of the library
#define COMMSDSL_PATCH_VERSION 0U
Expand Down
10 changes: 10 additions & 0 deletions lib/src/FloatField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,14 @@ unsigned FloatField::displayDecimals() const
return cast(m_pImpl)->displayDecimals();
}

bool FloatField::displaySpecials() const
{
return cast(m_pImpl)->displaySpecials();
}

bool FloatField::hasNonUniqueSpecials() const
{
return cast(m_pImpl)->hasNonUniqueSpecials();
}

} // namespace commsdsl
Loading

0 comments on commit 9bd72ff

Please sign in to comment.