Standardize data types using a data type enum. Get function implemented.

master
sigonasr2 1 year ago
parent 8336b0e305
commit 05f8c90ec0
  1. BIN
      SHNFileDecryptor/AbState.shn.bak
  2. 50
      SHNFileDecryptor/SHNFileDecryptor.h
  3. 2
      SHNFileDecryptor/SHNFile_example.cpp

Binary file not shown.

@ -37,9 +37,19 @@ class SHNFile{
std::string ReadString();
uint32_t GetRecordLength();
public:
enum class DataType:int{
BYTE=1,
SBYTE=7,
UINT16=2,
INT16=6,
UINT32=3,
INT32=8,
FLOAT=4,
STRING=5
};
struct Data{
std::shared_ptr<void>data;
int type=0;
DataType type=DataType::BYTE;
Data(byte b);
Data(sbyte b);
Data(uint16_t n);
@ -82,6 +92,7 @@ public:
void Write(int row,int col,uint32_t val);
void Write(int row,int col,float val);
void Write(int row,int col,std::string val);
const SHNFile::Data Get(int row,int col)const;
SHNFile();
};
#ifdef OLC_PGEX_SHNFile
@ -223,7 +234,7 @@ float SHNFile::ReadSingle(){
return f;
}
void SHNFile::WriteSingle(std::ofstream&f,float n){
byte bytes[4];
byte bytes[4]={};
memcpy(&n,&bytes,4);
for(int i=0;i<4;i++){
f<<unsigned char(bytes[i]);
@ -254,42 +265,42 @@ uint32_t SHNFile::GetRecordLength(){
SHNFile::Data::Data(byte b){
std::shared_ptr<byte>ptr=std::make_shared<byte>(byte(b));
data=ptr;
type=1;
type=DataType::BYTE;
}
SHNFile::Data::Data(sbyte b){
std::shared_ptr<sbyte>ptr=std::make_shared<sbyte>(sbyte(b));
data=ptr;
type=7;
type=DataType::SBYTE;
}
SHNFile::Data::Data(uint16_t n){
std::shared_ptr<uint16_t>ptr=std::make_shared<uint16_t>(uint16_t(n));
data=ptr;
type=2;
type=DataType::UINT16;
}
SHNFile::Data::Data(int16_t n){
std::shared_ptr<int16_t>ptr=std::make_shared<int16_t>(int16_t(n));
data=ptr;
type=6;
type=DataType::INT16;
}
SHNFile::Data::Data(uint32_t n){
std::shared_ptr<uint32_t>ptr=std::make_shared<uint32_t>(uint32_t(n));
data=ptr;
type=3;
type=DataType::UINT32;
}
SHNFile::Data::Data(int32_t n){
std::shared_ptr<int32_t>ptr=std::make_shared<int32_t>(int32_t(n));
data=ptr;
type=8;
type=DataType::INT32;
}
SHNFile::Data::Data(float n){
std::shared_ptr<float>ptr=std::make_shared<float>(float(n));
data=ptr;
type=4;
type=DataType::FLOAT;
}
SHNFile::Data::Data(std::string str){
std::shared_ptr<std::string>ptr=std::make_shared<std::string>(str);
data=ptr;
type=5;
type=DataType::STRING;
}
template <typename T>
T SHNFile::Data::Get(){
@ -301,28 +312,28 @@ void SHNFile::Data::Set(T b){
}
std::string SHNFile::Data::GetDisplayText(){
switch(type){
case 1:{
case DataType::BYTE:{
return std::to_string(int(Get<byte>()));
}break;
case 7:{
case DataType::SBYTE:{
return std::to_string(int(Get<sbyte>()));
}break;
case 2:{
case DataType::UINT16:{
return std::to_string(Get<uint16_t>());
}break;
case 6:{
case DataType::INT16:{
return std::to_string(Get<int16_t>());
}break;
case 3:{
case DataType::UINT32:{
return std::to_string(Get<uint32_t>());
}break;
case 8:{
case DataType::INT32:{
return std::to_string(Get<int32_t>());
}break;
case 4:{
case DataType::FLOAT:{
return std::to_string(Get<float>());
}break;
case 5:{
case DataType::STRING:{
return Get<std::string>();
}break;
}
@ -497,6 +508,9 @@ void SHNFile::Save(){
WriteBytes(encryptedFile,data);
std::cout<<"File "<<filename<<" Saved!"<<std::endl;
}
const SHNFile::Data SHNFile::Get(int row,int col)const{
return contents[row][col];
};
void SHNFile::Write(int row,int col,byte val){
contents[row][col].Set<byte>(val);
}

@ -4,6 +4,8 @@
int main(){
SHNFile shn;
shn.Load("AbState.shn");
SHNFile::Data dat=shn.Get(3,6);
std::cout<<dat<<std::endl;
shn.Write(1,1,"Noodles");
shn.Save();
}
Loading…
Cancel
Save