Fix the project code style, as it is not consistent. (#236)

Fixes #202
This PR fixes code style for the project files.

The Problem
Different files in the project use different code style. That is not consistent and leads to harder maintenance of the project.

Description of the changes:
Have investigated and determined the most used code style across the given codebase
Have configured IDE and applied code style to all project files.
Have crafted clang-formatter config.
see https://clang.llvm.org/docs/ClangFormat.html
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Some cases were fixed manually
How changes were validated:
manual/ad-hoc testing, automated testing

All tests pass as before because these are only code style changes.
Additional
Please review, and let me know if I have any mistake in the code style. In case of any mistake, I will change the configuration and re-apply it to the project.
This commit is contained in:
Oleg Abrazhaev 2019-05-02 20:59:19 +02:00 committed by Daniel Belcher
parent c77f1de84c
commit 2826d37056
237 changed files with 12824 additions and 11843 deletions

View file

@ -26,13 +26,12 @@ namespace CalculatorApp::ViewModel::HistoryResourceKeys
StringReference HistoryCleared(L"HistoryList_Cleared");
}
HistoryViewModel::HistoryViewModel(_In_ CalculationManager::CalculatorManager* calculatorManager) :
m_calculatorManager(calculatorManager),
m_localizedHistoryCleared(nullptr)
HistoryViewModel::HistoryViewModel(_In_ CalculationManager::CalculatorManager* calculatorManager)
: m_calculatorManager(calculatorManager), m_localizedHistoryCleared(nullptr)
{
AreHistoryShortcutsEnabled = true;
Items = ref new Platform::Collections::Vector<HistoryItemViewModel^>();
Items = ref new Platform::Collections::Vector<HistoryItemViewModel ^>();
ItemSize = 0;
}
@ -59,7 +58,7 @@ void HistoryViewModel::ReloadHistory(_In_ ViewMode currentMode)
}
auto historyListModel = m_calculatorManager->GetHistoryItems(m_currentMode);
auto historyListVM = ref new Platform::Collections::Vector<HistoryItemViewModel^>();
auto historyListVM = ref new Platform::Collections::Vector<HistoryItemViewModel ^>();
const auto& localizer = LocalizationSettings::GetInstance();
if (historyListModel.size() > 0)
{
@ -70,9 +69,8 @@ void HistoryViewModel::ReloadHistory(_In_ ViewMode currentMode)
localizer.LocalizeDisplayValue(&expression);
localizer.LocalizeDisplayValue(&result);
auto item = ref new HistoryItemViewModel(ref new Platform::String( expression.c_str()),
ref new Platform::String(result.c_str()),
(*ritr)->historyItemVector.spTokens, (*ritr)->historyItemVector.spCommands);
auto item = ref new HistoryItemViewModel(ref new Platform::String(expression.c_str()), ref new Platform::String(result.c_str()),
(*ritr)->historyItemVector.spTokens, (*ritr)->historyItemVector.spCommands);
historyListVM->Append(item);
}
}
@ -89,15 +87,14 @@ void HistoryViewModel::OnHistoryItemAdded(_In_ unsigned int addedItemIndex)
wstring result = newItem->historyItemVector.result;
localizer.LocalizeDisplayValue(&expression);
localizer.LocalizeDisplayValue(&result);
auto item = ref new HistoryItemViewModel(ref new Platform::String(expression.c_str()),
ref new Platform::String(result.c_str()),
newItem->historyItemVector.spTokens, newItem->historyItemVector.spCommands );
auto item = ref new HistoryItemViewModel(ref new Platform::String(expression.c_str()), ref new Platform::String(result.c_str()),
newItem->historyItemVector.spTokens, newItem->historyItemVector.spCommands);
// check if we have not hit the max items
if (Items->Size >= m_calculatorManager->MaxHistorySize())
{
// this means the item already exists
Items->RemoveAt(Items->Size -1);
Items->RemoveAt(Items->Size - 1);
}
assert(addedItemIndex <= m_calculatorManager->MaxHistorySize() && addedItemIndex >= 0);
@ -106,18 +103,18 @@ void HistoryViewModel::OnHistoryItemAdded(_In_ unsigned int addedItemIndex)
SaveHistory();
}
void HistoryViewModel::SetCalculatorDisplay(CalculatorDisplay &calculatorDisplay)
void HistoryViewModel::SetCalculatorDisplay(CalculatorDisplay& calculatorDisplay)
{
WeakReference historyViewModel(this);
calculatorDisplay.SetHistoryCallback(historyViewModel);
}
void HistoryViewModel::ShowItem(_In_ HistoryItemViewModel^ e)
void HistoryViewModel::ShowItem(_In_ HistoryItemViewModel ^ e)
{
HistoryItemClicked(e);
}
void HistoryViewModel::DeleteItem(_In_ HistoryItemViewModel^ e)
void HistoryViewModel::DeleteItem(_In_ HistoryItemViewModel ^ e)
{
uint32_t itemIndex;
if (Items->IndexOf(e, &itemIndex))
@ -127,7 +124,7 @@ void HistoryViewModel::DeleteItem(_In_ HistoryItemViewModel^ e)
// Keys for the history container are index based.
// SaveHistory() re-inserts the items anyway, so it's faster to just clear out the container.
CalculationManager::CALCULATOR_MODE currentMode = m_currentMode;
ApplicationDataContainer^ historyContainer = GetHistoryContainer(currentMode);
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(currentMode);
historyContainer->Values->Clear();
Items->RemoveAt(itemIndex);
@ -137,13 +134,13 @@ void HistoryViewModel::DeleteItem(_In_ HistoryItemViewModel^ e)
}
}
void HistoryViewModel::OnHideCommand(_In_ Platform::Object^ e)
void HistoryViewModel::OnHideCommand(_In_ Platform::Object ^ e)
{
// added at VM layer so that the views do not have to individually raise events
HideHistoryClicked();
}
void HistoryViewModel::OnClearCommand(_In_ Platform::Object^ e)
void HistoryViewModel::OnClearCommand(_In_ Platform::Object ^ e)
{
TraceLogger::GetInstance().LogClearHistory();
if (AreHistoryShortcutsEnabled == true)
@ -165,8 +162,9 @@ void HistoryViewModel::OnClearCommand(_In_ Platform::Object^ e)
// this method restores history vector per mode
void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE cMode)
{
ApplicationDataContainer^ historyContainer = GetHistoryContainer(cMode);
std::shared_ptr<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>> historyVector = std::make_shared<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>>();
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode);
std::shared_ptr<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>> historyVector =
std::make_shared<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>>();
auto historyVectorLength = static_cast<int>(historyContainer->Values->Lookup(HistoryVectorLengthKey));
bool failure = false;
@ -181,7 +179,7 @@ void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE c
std::shared_ptr<CalculationManager::HISTORYITEM> Item = std::make_shared<CalculationManager::HISTORYITEM>(item);
historyVector->push_back(Item);
}
catch (Platform::Exception^ e)
catch (Platform::Exception ^ e)
{
failure = true;
break;
@ -204,19 +202,19 @@ void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE c
}
}
Platform::String^ HistoryViewModel::GetHistoryContainerKey(_In_ CalculationManager::CALCULATOR_MODE cMode)
Platform::String ^ HistoryViewModel::GetHistoryContainerKey(_In_ CalculationManager::CALCULATOR_MODE cMode)
{
Platform::ValueType^ modeValue = static_cast<int>(cMode);
Platform::ValueType ^ modeValue = static_cast<int>(cMode);
return Platform::String::Concat(modeValue->ToString(), L"_History");
}
ApplicationDataContainer^ HistoryViewModel::GetHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode)
ApplicationDataContainer ^ HistoryViewModel::GetHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode)
{
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
ApplicationDataContainer^ historyContainer;
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
ApplicationDataContainer ^ historyContainer;
// naming container based on mode
Platform::String^ historyContainerKey = GetHistoryContainerKey(cMode);
Platform::String ^ historyContainerKey = GetHistoryContainerKey(cMode);
if (localSettings->Containers->HasKey(historyContainerKey))
{
@ -235,14 +233,14 @@ ApplicationDataContainer^ HistoryViewModel::GetHistoryContainer(_In_ Calculation
void HistoryViewModel::ClearHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode)
{
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
localSettings->DeleteContainer(GetHistoryContainerKey(cMode));
}
// this method will be used to update the history item length
void HistoryViewModel::UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode)
{
ApplicationDataContainer^ historyContainer = GetHistoryContainer(cMode);
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode);
historyContainer->Values->Remove(HistoryVectorLengthKey);
historyContainer->Values->Insert(HistoryVectorLengthKey, newValue);
}
@ -255,11 +253,11 @@ void HistoryViewModel::ClearHistory()
void HistoryViewModel::SaveHistory()
{
ApplicationDataContainer^ historyContainer = GetHistoryContainer(m_currentMode);
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(m_currentMode);
auto currentHistoryVector = m_calculatorManager->GetHistoryItems(m_currentMode);
bool failure = false;
int index = 0;
Platform::String^ serializedHistoryItem;
Platform::String ^ serializedHistoryItem;
for (auto iter = currentHistoryVector.begin(); iter != currentHistoryVector.end(); ++iter)
{
@ -268,7 +266,7 @@ void HistoryViewModel::SaveHistory()
serializedHistoryItem = SerializeHistoryItem(*iter);
historyContainer->Values->Insert(index.ToString(), serializedHistoryItem);
}
catch (Platform::Exception^)
catch (Platform::Exception ^)
{
failure = true;
break;
@ -289,9 +287,9 @@ void HistoryViewModel::SaveHistory()
}
// this serializes a history item into a base64 encoded string
Platform::String^ HistoryViewModel::SerializeHistoryItem(_In_ std::shared_ptr<CalculationManager::HISTORYITEM> const &item)
Platform::String ^ HistoryViewModel::SerializeHistoryItem(_In_ std::shared_ptr<CalculationManager::HISTORYITEM> const& item)
{
DataWriter^ writer = ref new DataWriter();
DataWriter ^ writer = ref new DataWriter();
auto expr = item->historyItemVector.expression;
auto result = item->historyItemVector.result;
auto platformExpr = ref new Platform::String(expr.c_str());
@ -303,7 +301,7 @@ Platform::String^ HistoryViewModel::SerializeHistoryItem(_In_ std::shared_ptr<Ca
Utils::SerializeCommandsAndTokens(item->historyItemVector.spTokens, item->historyItemVector.spCommands, writer);
IBuffer^ buffer = writer->DetachBuffer();
IBuffer ^ buffer = writer->DetachBuffer();
if (buffer == nullptr)
{
throw ref new Platform::Exception(E_POINTER, ref new Platform::String(L"History Item is NULL"));
@ -312,27 +310,28 @@ Platform::String^ HistoryViewModel::SerializeHistoryItem(_In_ std::shared_ptr<Ca
return CryptographicBuffer::EncodeToBase64String(buffer);
}
CalculationManager::HISTORYITEM HistoryViewModel::DeserializeHistoryItem(_In_ Platform::String^ historyItemKey, _In_ ApplicationDataContainer^ historyContainer)
CalculationManager::HISTORYITEM HistoryViewModel::DeserializeHistoryItem(_In_ Platform::String ^ historyItemKey,
_In_ ApplicationDataContainer ^ historyContainer)
{
CalculationManager::HISTORYITEM historyItem;
if (historyContainer->Values->HasKey(historyItemKey))
{
Object^ historyItemValues = historyContainer->Values->Lookup(historyItemKey);
Object ^ historyItemValues = historyContainer->Values->Lookup(historyItemKey);
if (historyItemValues == nullptr)
{
throw ref new Platform::Exception(E_POINTER, ref new Platform::String(L"History Item is NULL"));
}
String^ historyData = safe_cast<Platform::String^>(historyItemValues);
IBuffer^ buffer = CryptographicBuffer::DecodeFromBase64String(historyData);
String ^ historyData = safe_cast<Platform::String ^>(historyItemValues);
IBuffer ^ buffer = CryptographicBuffer::DecodeFromBase64String(historyData);
if (buffer == nullptr)
{
throw ref new Platform::Exception(E_POINTER, ref new Platform::String(L"History Item is NULL"));
}
DataReader^ reader = DataReader::FromBuffer(buffer);
DataReader ^ reader = DataReader::FromBuffer(buffer);
auto exprLen = reader->ReadUInt32();
auto expression = reader->ReadString(exprLen);
historyItem.historyItemVector.expression = expression->Data();
@ -353,10 +352,8 @@ CalculationManager::HISTORYITEM HistoryViewModel::DeserializeHistoryItem(_In_ Pl
bool HistoryViewModel::IsValid(_In_ CalculationManager::HISTORYITEM item)
{
return (!item.historyItemVector.expression.empty() &&
!item.historyItemVector.result.empty() &&
(bool)item.historyItemVector.spCommands &&
(bool)item.historyItemVector.spTokens);
return (!item.historyItemVector.expression.empty() && !item.historyItemVector.result.empty() && (bool)item.historyItemVector.spCommands
&& (bool)item.historyItemVector.spTokens);
}
void HistoryViewModel::UpdateItemSize()
@ -364,9 +361,9 @@ void HistoryViewModel::UpdateItemSize()
ItemSize = Items->Size;
}
void HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String^ resourceKey, String^& formatVariable)
void HistoryViewModel::MakeHistoryClearedNarratorAnnouncement(String ^ resourceKey, String ^ &formatVariable)
{
String^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(resourceKey, formatVariable);
String ^ announcement = LocalizationStringUtil::GetLocalizedNarratorAnnouncement(resourceKey, formatVariable);
HistoryAnnouncement = CalculatorAnnouncement::GetHistoryClearedAnnouncement(announcement);
}