added: utl::getDirs

this creates a direction integer like '123'
This commit is contained in:
Arne Morten Kvarving 2022-10-03 11:34:24 +02:00
parent cd60e90fca
commit d748bdc0eb
3 changed files with 26 additions and 0 deletions

View File

@ -192,3 +192,16 @@ TEST(TestUtilities, GetAttribute)
EXPECT_FLOAT_EQ(val4.y, 3.4);
EXPECT_FLOAT_EQ(val4.z, 5.6);
}
TEST(TestUtilities, getDirs)
{
int cmp1 = utl::getDirs(1);
int cmp2 = utl::getDirs(2);
int cmp3 = utl::getDirs(3);
int cmp4 = utl::getDirs(4);
EXPECT_EQ(cmp1, 1);
EXPECT_EQ(cmp2, 12);
EXPECT_EQ(cmp3, 123);
EXPECT_EQ(cmp4, 1234);
}

View File

@ -445,6 +445,16 @@ std::set<int> utl::getDigits (int num)
}
int utl::getDirs (int ncmp)
{
int res = 0, mul = 1;
for (int i = ncmp; i >= 1; --i, mul *= 10)
res += i*mul;
return res;
}
namespace utl
{
/*!

View File

@ -203,6 +203,9 @@ namespace utl
//! \brief Splits an integer into its (unique) digits in ascending order.
std::set<int> getDigits(int value);
//! \brief Makes a direction integer for given number of components.
int getDirs(int ncmp);
//! \brief Returns a const iterator to the entry with value \a iVal.
IntMap::const_iterator findValue(const IntMap& iMap, int iVal);
//! \brief Returns the key corresponding to the value \a iVal.