Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parameter/BitParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool CBitParameterType::toBlackboard(const string& strValue, uint64_t& uiValue,

strStream << "Value " << strValue << " standing out of admitted range [";

if (CUtility::isHexadecimal(strValue)) {
if (utility::isHexadecimal(strValue)) {

strStream << "0x0, " << "0x" << std::hex << std::uppercase;
} else {
Expand Down
2 changes: 1 addition & 1 deletion parameter/BooleanParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool CBooleanParameterType::toBlackboard(const std::string& strValue, uint32_t&
} else {
parameterAccessContext.setError(strValue + " value not part of numerical space {");

if (CUtility::isHexadecimal(strValue)) {
if (utility::isHexadecimal(strValue)) {

parameterAccessContext.appendToError("0x0, 0x1");
} else {
Expand Down
2 changes: 1 addition & 1 deletion parameter/ConfigurableDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen
core::Results infos;
if (!addConfigurableElement(pConfigurableElement, NULL, infos)) {

CUtility::asString(infos, strError);
strError = utility::asString(infos);
serializingContext.setError(strError);

return false;
Expand Down
4 changes: 2 additions & 2 deletions parameter/FixedPointParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerial

bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
bool bValueProvidedAsHexa = CUtility::isHexadecimal(strValue);
bool bValueProvidedAsHexa = utility::isHexadecimal(strValue);

// Check data integrity
if (bValueProvidedAsHexa && !parameterAccessContext.valueSpaceIsRaw()) {
Expand Down Expand Up @@ -161,7 +161,7 @@ void CFixedPointParameterType::setOutOfRangeError(const string& strValue, CParam

strStream << "raw range [";

if (CUtility::isHexadecimal(strValue)) {
if (utility::isHexadecimal(strValue)) {

// Format Min
strStream << "0x" << std::hex << std::uppercase <<
Expand Down
4 changes: 2 additions & 2 deletions parameter/FloatingPointParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool CFloatingPointParameterType::toBlackboard(
CParameterAccessContext& parameterAccessContext) const
{
// Check Value integrity
if (CUtility::isHexadecimal(strValue) && !parameterAccessContext.valueSpaceIsRaw()) {
if (utility::isHexadecimal(strValue) && !parameterAccessContext.valueSpaceIsRaw()) {

parameterAccessContext.setError("Hexadecimal values are not supported for "
+ getKind()
Expand Down Expand Up @@ -198,7 +198,7 @@ void CFloatingPointParameterType::setOutOfRangeError(
uint32_t uiMin = reinterpret_cast<const uint32_t&>(_fMin);
uint32_t uiMax = reinterpret_cast<const uint32_t&>(_fMax);

if (CUtility::isHexadecimal(strValue)) {
if (utility::isHexadecimal(strValue)) {

ostrStream << std::showbase << std::hex
<< std::setw(getSize() * 2) << std::setfill('0');
Expand Down
2 changes: 1 addition & 1 deletion parameter/IntegerParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi
bool CIntegerParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
// Hexa
bool bValueProvidedAsHexa = CUtility::isHexadecimal(strValue);
bool bValueProvidedAsHexa = utility::isHexadecimal(strValue);

// Get integer value from the string provided
int64_t iData;
Expand Down
6 changes: 1 addition & 5 deletions parameter/MappingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ bool CMappingData::getValue(const std::string& strkey, const std::string*& pStrV

std::string CMappingData::asString() const
{
std::string strValue;

CUtility::asString(_keyToValueMap, strValue, ", ", ":");

return strValue;
return utility::asString(_keyToValueMap, ", ", ":");
}

bool CMappingData::addValue(const std::string& strkey, const std::string& strValue)
Expand Down
22 changes: 10 additions & 12 deletions parameter/ParameterMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces

// Show status
/// General section
CUtility::appendTitle(strResult, "General:");
utility::appendTitle(strResult, "General:");
// System class
strResult += "System Class: ";
strResult += pSystemClass->getName();
Expand All @@ -838,25 +838,23 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces
strResult += "\n";

/// Subsystem list
CUtility::appendTitle(strResult, "Subsystems:");
utility::appendTitle(strResult, "Subsystems:");
string strSubsystemList;
pSystemClass->listChildrenPaths(strSubsystemList);
strResult += strSubsystemList;

/// Last applied configurations
CUtility::appendTitle(strResult, "Last Applied [Pending] Configurations:");
utility::appendTitle(strResult, "Last Applied [Pending] Configurations:");
string strLastAppliedConfigurations;
getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
strResult += strLastAppliedConfigurations;

/// Criteria states
CUtility::appendTitle(strResult, "Selection Criteria:");
utility::appendTitle(strResult, "Selection Criteria:");
list<string> lstrSelectionCriteria;
getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
// Concatenate the criterion list as the command result
string strCriteriaStates;
CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
strResult += strCriteriaStates;
strResult += utility::asString(lstrSelectionCriteria);

return CCommandHandler::ESucceeded;
}
Expand Down Expand Up @@ -1028,7 +1026,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommand
getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable);

// Concatenate the criterion list as the command result
CUtility::asString(lstrResult, strResult);
strResult += utility::asString(lstrResult);

return CCommandHandler::ESucceeded;
}
Expand Down Expand Up @@ -1165,7 +1163,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfiguratio
core::Results result;
if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), result)) {
//Concatenate the error list as the command result
CUtility::asString(result, strResult);
strResult = utility::asString(result);

return CCommandHandler::EFailed;
}
Expand Down Expand Up @@ -1859,7 +1857,7 @@ bool CParameterMgr::sync(string& strError)
core::Results error;
if (! syncerSet.sync(*_pMainParameterBlackboard, false, &error)){

CUtility::asString(error, strError);
strError = utility::asString(error);
return false;
};

Expand Down Expand Up @@ -2058,7 +2056,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons
warning() << infos;
}

CUtility::asString(infos, strError);
strError = utility::asString(infos);
return isSuccess;
}

Expand Down Expand Up @@ -2126,7 +2124,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable
warning() << infos;
}

CUtility::asString(infos, strError);
strError = utility::asString(infos);
return isSuccess;
}

Expand Down
2 changes: 1 addition & 1 deletion parameter/SelectionCriterion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ std::string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo, boo
if (bWithTypeInfo) {

// Display type info
CUtility::appendTitle(strFormattedDescription, getName() + ":");
utility::appendTitle(strFormattedDescription, getName() + ":");

// States
strFormattedDescription += "Possible states ";
Expand Down
8 changes: 3 additions & 5 deletions parameter/SystemClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool CSystemClass::loadSubsystems(string& strError,

// Fill strError for caller, he has to decide if there is a problem depending on
// bVirtualSubsystemFallback value
CUtility::asString(errors, strError);
strError = utility::asString(errors);

return bLoadPluginsSuccess || bVirtualSubsystemFallback;
}
Expand Down Expand Up @@ -151,10 +151,8 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors,

if (!lstrPluginFiles.empty()) {
// Unable to load at least one plugin
string strPluginUnloaded;
CUtility::asString(lstrPluginFiles, strPluginUnloaded, ", ");

errors.push_back("Unable to load the following plugins: " + strPluginUnloaded + ".");
errors.push_back("Unable to load the following plugins: " +
utility::asString(lstrPluginFiles, ", ") + ".");
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions parameter/log/include/log/LogWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ class LogWrapper
*/
LogWrapper& operator<<(const std::list<std::string>& logs)
{
std::string formatedLogs;
std::string separator = "\n" + mProlog;
CUtility::asString(logs, formatedLogs, separator);
std::string formatedLogs = utility::asString(logs, separator);

// Check if there is something in the log to know if we have to add a prefix
if (!mLog.str().empty() && mLog.str()[mLog.str().length() - 1] == separator[0]) {
Expand Down
10 changes: 2 additions & 8 deletions remote-processor/RemoteCommandHandlerTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,11 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler

std::string strUsage = pRemoteCommandParserItem->usage();

strResult += strUsage;

// Align
size_t spacesToAdd = _maxCommandUsageLength + 5 - strUsage.length();

while (spacesToAdd--) {

strResult += " ";
}

strResult += std::string("=> ") + std::string(pRemoteCommandParserItem->getDescription()) + "\n";
strResult += strUsage + std::string(spacesToAdd, ' ') + "=> " +
pRemoteCommandParserItem->getDescription() + '\n';
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/test-platform/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ int main(int argc, char *argv[])

// All arguments should have been consumed
if (not options.empty()) {
std::string extraArgs;
CUtility::asString(options, extraArgs);
showInvalidUsage("Unexpected extra arguments: " + extraArgs);
showInvalidUsage("Unexpected extra arguments: " + utility::asString(options));
return 3;
}

Expand Down
9 changes: 9 additions & 0 deletions utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ install(FILES
Utility.h
convert.hpp
DESTINATION "include/utility")

if(BUILD_TESTING)
# Add unit test
add_executable(utilityUnitTest test/utility.cpp)

target_link_libraries(utilityUnitTest pfw_utility catch)
add_test(NAME utilityUnitTest
COMMAND utilityUnitTest)
endif()
57 changes: 21 additions & 36 deletions utility/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,61 +32,46 @@

#include <sstream>
#include <iterator>
#include <stdint.h>
#include <algorithm>

using std::string;

namespace utility
{

// Format string list
void CUtility::asString(const std::list<std::string>& lstr,
std::string& strOutput,
std::string asString(const std::list<std::string>& lstr,
const std::string& strSeparator)
{
std::ostringstream ostrFormatedList;

std::copy(lstr.begin(), lstr.end(),
std::ostream_iterator<std::string>(ostrFormatedList, strSeparator.c_str()));

strOutput = ostrFormatedList.str();

// Remove last separator
if (strOutput.size() > strSeparator.size()) {

strOutput.erase(strOutput.size() - strSeparator.size());
}
return join<std::string>(begin(lstr), end(lstr),
[strSeparator](string acc, string right) {
return acc + strSeparator + right;
});
}

// Format string map
void CUtility::asString(const std::map<std::string, std::string>& mapStr,
std::string& strOutput,
const std::string& strItemSeparator,
const std::string& strKeyValueSeparator)
std::string asString(const std::map<std::string, std::string>& mapStr,
const std::string& strItemSeparator,
const std::string& strKeyValueSeparator)
{
std::list<std::string> listKeysValues;

std::map<std::string, std::string>::const_iterator iter;

for(iter = mapStr.begin(); iter != mapStr.end(); ++iter) {

listKeysValues.push_back(iter->first + strKeyValueSeparator + iter->second);
for (const auto & item: mapStr) {
listKeysValues.emplace_back(item.first + strKeyValueSeparator + item.second);
}

CUtility::asString(listKeysValues, strOutput, strItemSeparator);
return asString(listKeysValues, strItemSeparator);
}

void CUtility::appendTitle(string& strTo, const string& strTitle)
void appendTitle(string& strTo, const string& strTitle)
{
strTo += "\n" + strTitle + "\n";

size_t uiLength = strTitle.size();

while (uiLength--) {

strTo += "=";
}
strTo += "\n";
strTo += "\n" + strTitle + "\n" +
string(strTitle.size(), '=') + "\n";
}

bool CUtility::isHexadecimal(const string& strValue)
bool isHexadecimal(const string& strValue)
{
return (strValue.compare(0, 2, "0x") == 0) or (strValue.compare(0, 2, "0X") == 0);
}

} // namespace utility
Loading