Skip to content

Commit 600615c

Browse files
committed
Add HasClassRegistry static method getAliasedTypes.
Return a map of alias strings to standard type names.
1 parent c413b35 commit 600615c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/diffpy/HasClassRegistry.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class HasClassRegistry
6767
/// Return true if string is a registered string type or its alias.
6868
static bool isRegisteredType(const std::string& tp);
6969

70+
/// Return a map of string aliases to standard type strings.
71+
static std::map<std::string, std::string> getAliasedTypes();
72+
7073
/// Return a set of all registered string types
7174
static std::set<std::string> getRegisteredTypes();
7275

src/diffpy/HasClassRegistry.ipp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ HasClassRegistry<TBase>::isRegisteredType(const std::string& tp)
105105
}
106106

107107

108+
template <class TBase>
109+
std::map<std::string, std::string>
110+
HasClassRegistry<TBase>::getAliasedTypes()
111+
{
112+
using namespace std;
113+
map<string, string> rv;
114+
const RegistryStorage& reg = getRegistry();
115+
typename RegistryStorage::const_iterator irg = reg.begin();
116+
for (; irg != reg.end(); ++irg)
117+
{
118+
if (irg->first != irg->second->type())
119+
{
120+
rv[irg->first] = irg->second->type();
121+
}
122+
}
123+
return rv;
124+
}
125+
126+
108127
template <class TBase>
109128
std::set<std::string>
110129
HasClassRegistry<TBase>::getRegisteredTypes()

src/tests/TestHasClassRegistry.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ class TestHasClassRegistry : public CxxTest::TestSuite
5151
TS_ASSERT_EQUALS(false, mpreg->isRegisteredType("invalid"));
5252
}
5353

54+
55+
void test_getAliasedTypes()
56+
{
57+
std::map<std::string, std::string> atps;
58+
atps = ScatteringFactorTable::getAliasedTypes();
59+
TS_ASSERT_EQUALS(4, atps.size());
60+
TS_ASSERT(atps.count("X"));
61+
TS_ASSERT_EQUALS("xray", atps["X"]);
62+
TS_ASSERT_EQUALS("electronnumber", atps["EN"]);
63+
}
64+
5465
}; // class TestHasClassRegistry
5566

5667
// End of file

0 commit comments

Comments
 (0)