// A bijection is a one-to-one mapping. // This particular bijection maps strings to strings. // It also copies anything which is put into it. #include "ut_bijection.h" #include #include "ut_string.h" #include UT_Bijection::UT_Bijection() { m_n = 0; m_first = m_second = NULL; } void UT_Bijection::clear() { if (!m_n) return; for(int i=0;i(g_try_realloc(static_cast(m_first),(m_n+1)*sizeof(char*))); m_first[m_n] = g_strdup(f); m_second = static_cast(g_try_realloc(static_cast(m_second),(m_n+1)*sizeof(char*))); m_second[m_n] = g_strdup(s); ++m_n; } void UT_Bijection::add(const pair_data* items) { for(;items->s1 && items->s2;++items) add(items->s1, items->s2); } size_t UT_Bijection::size() const { return m_n; } const char* UT_Bijection::nth1(size_t idx) const { return ( idx>(size()-1) ) ? NULL : m_first[idx]; } const char* UT_Bijection::nth2(size_t idx) const { return ( idx>(size()-1) ) ? NULL : m_second[idx]; }