mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-13 00:32:52 -07:00
Remove Serialize/Deserialize functions never used in StandardCalculatorViewModel, UnitConverter, UnitConverterViewModel and CalculatorManager (#392)
* remove unused serializer * remove all unused serialization/deserialization from StandardCalculatorViewModel and UnitConverterViewModel * formatting
This commit is contained in:
parent
750130c2bc
commit
28888d8df1
13 changed files with 12 additions and 771 deletions
|
@ -1163,110 +1163,6 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
|
|||
}
|
||||
}
|
||||
|
||||
Array<unsigned char> ^ StandardCalculatorViewModel::Serialize()
|
||||
{
|
||||
DataWriter ^ writer = ref new DataWriter();
|
||||
writer->WriteUInt32(static_cast<UINT32>(m_CurrentAngleType));
|
||||
writer->WriteBoolean(IsFToEChecked);
|
||||
writer->WriteBoolean(IsCurrentViewPinned);
|
||||
writer->WriteUInt32(static_cast<UINT32>(m_standardCalculatorManager.SerializeSavedDegreeMode()));
|
||||
|
||||
// Serialize Memory
|
||||
vector<long> serializedMemory;
|
||||
serializedMemory = m_standardCalculatorManager.GetSerializedMemory();
|
||||
size_t lengthOfSerializedMemory = serializedMemory.size();
|
||||
writer->WriteUInt32(static_cast<UINT32>(lengthOfSerializedMemory));
|
||||
for (auto data : serializedMemory)
|
||||
{
|
||||
writer->WriteInt32(data);
|
||||
}
|
||||
|
||||
// Serialize Primary Display
|
||||
vector<long> serializedPrimaryDisplay = m_standardCalculatorManager.GetSerializedPrimaryDisplay();
|
||||
writer->WriteUInt32(static_cast<UINT32>(serializedPrimaryDisplay.size()));
|
||||
for (auto data : serializedPrimaryDisplay)
|
||||
{
|
||||
writer->WriteInt32(data);
|
||||
}
|
||||
|
||||
// For ProgrammerMode
|
||||
writer->WriteUInt32(static_cast<UINT32>(CurrentRadixType));
|
||||
|
||||
// Serialize commands of calculator manager
|
||||
vector<unsigned char> serializedCommand = m_standardCalculatorManager.SerializeCommands();
|
||||
writer->WriteUInt32(static_cast<UINT32>(serializedCommand.size()));
|
||||
writer->WriteBytes(ref new Array<unsigned char>(serializedCommand.data(), static_cast<unsigned int>(serializedCommand.size())));
|
||||
|
||||
if (IsInError)
|
||||
{
|
||||
Utils::SerializeCommandsAndTokens(m_tokens, m_commands, writer);
|
||||
}
|
||||
|
||||
// Convert viewmodel data in writer to bytes
|
||||
IBuffer ^ buffer = writer->DetachBuffer();
|
||||
DataReader ^ reader = DataReader::FromBuffer(buffer);
|
||||
Platform::Array<unsigned char> ^ viewModelDataAsBytes = ref new Array<unsigned char>(buffer->Length);
|
||||
reader->ReadBytes(viewModelDataAsBytes);
|
||||
|
||||
// Return byte array
|
||||
return viewModelDataAsBytes;
|
||||
}
|
||||
|
||||
void StandardCalculatorViewModel::Deserialize(Array<unsigned char> ^ state)
|
||||
{
|
||||
// Read byte array into a buffer
|
||||
DataWriter ^ writer = ref new DataWriter();
|
||||
writer->WriteBytes(state);
|
||||
IBuffer ^ buffer = writer->DetachBuffer();
|
||||
|
||||
// Read view model data
|
||||
if (buffer->Length != 0)
|
||||
{
|
||||
DataReader ^ reader = DataReader::FromBuffer(buffer);
|
||||
m_CurrentAngleType = ConvertIntegerToNumbersAndOperatorsEnum(reader->ReadUInt32());
|
||||
|
||||
IsFToEChecked = reader->ReadBoolean();
|
||||
IsCurrentViewPinned = reader->ReadBoolean();
|
||||
Command serializedDegreeMode = static_cast<Command>(reader->ReadUInt32());
|
||||
|
||||
m_standardCalculatorManager.SendCommand(serializedDegreeMode);
|
||||
|
||||
// Deserialize Memory
|
||||
UINT32 memoryDataLength = reader->ReadUInt32();
|
||||
vector<long> serializedMemory;
|
||||
for (unsigned int i = 0; i < memoryDataLength; i++)
|
||||
{
|
||||
serializedMemory.push_back(reader->ReadInt32());
|
||||
}
|
||||
m_standardCalculatorManager.DeSerializeMemory(serializedMemory);
|
||||
|
||||
// Serialize Primary Display
|
||||
UINT32 serializedPrimaryDisplayLength = reader->ReadUInt32();
|
||||
vector<long> serializedPrimaryDisplay;
|
||||
for (unsigned int i = 0; i < serializedPrimaryDisplayLength; i++)
|
||||
{
|
||||
serializedPrimaryDisplay.push_back(reader->ReadInt32());
|
||||
}
|
||||
m_standardCalculatorManager.DeSerializePrimaryDisplay(serializedPrimaryDisplay);
|
||||
|
||||
CurrentRadixType = reader->ReadUInt32();
|
||||
// Read command data and Deserialize
|
||||
UINT32 modeldatalength = reader->ReadUInt32();
|
||||
Array<unsigned char> ^ modelDataAsBytes = ref new Array<unsigned char>(modeldatalength);
|
||||
reader->ReadBytes(modelDataAsBytes);
|
||||
m_standardCalculatorManager.DeSerializeCommands(vector<unsigned char>(modelDataAsBytes->begin(), modelDataAsBytes->end()));
|
||||
|
||||
// After recalculation. If there is an error then
|
||||
// IsInError should be set synchronously.
|
||||
if (IsInError)
|
||||
{
|
||||
shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> commandVector = Utils::DeserializeCommands(reader);
|
||||
shared_ptr<CalculatorVector<pair<wstring, int>>> tokenVector = Utils::DeserializeTokens(reader);
|
||||
SetExpressionDisplay(tokenVector, commandVector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname)
|
||||
{
|
||||
if (propertyname == IsScientificPropertyName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue