Skip to content

Instantly share code, notes, and snippets.

@TurtleShip
Last active April 7, 2019 07:45
Show Gist options
  • Select an option

  • Save TurtleShip/22041177fd36f6d57b01feb10e2e8925 to your computer and use it in GitHub Desktop.

Select an option

Save TurtleShip/22041177fd36f6d57b01feb10e2e8925 to your computer and use it in GitHub Desktop.

Revisions

  1. TurtleShip revised this gist Apr 7, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion restore_pref.cpp
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
    auto fromType = StringToUnit(outerTokens[0]);
    auto toType = StringToUnit(outerTokens[1]);
    m_currentCategory = StringToCategory(outerTokens[2]);


    // Only restore from the saved units if they are valid in the current available units.
    auto itr = m_categoryToUnits.find(m_currentCategory);
    if (itr != m_categoryToUnits.end())
    {
  2. TurtleShip created this gist Apr 7, 2019.
    30 changes: 30 additions & 0 deletions restore_pref.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
    {
    if (userPreferences.empty())
    {
    return;
    }

    vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
    if (outerTokens.size() == 3)
    {

    auto fromType = StringToUnit(outerTokens[0]);
    auto toType = StringToUnit(outerTokens[1]);
    m_currentCategory = StringToCategory(outerTokens[2]);

    auto itr = m_categoryToUnits.find(m_currentCategory);
    if (itr != m_categoryToUnits.end())
    {
    auto curUnits = itr->second;
    if (find(curUnits.begin(), curUnits.end(), fromType) != curUnits.end())
    {
    m_fromType = fromType;
    }
    if (find(curUnits.begin(), curUnits.end(), fromType) != curUnits.end())
    {
    m_toType = toType;
    }
    }
    }
    }