📄 database.h
字号:
#pragma once
#include<string.h>
void CharUpperCase(char & c){ //小写转大写
if(c>='a' && c<='z')c=c+'A'-'a';
}
class Base{ //基类
private:
int value;
public:
Base():value(0){} //默认构造函数
Base(int v):value(v){} //构造函数
int GetValue(){return value;}
void Set(int v){value=v;}
};
//以下为继承类,原理均是将模拟的各进制数(实质为char型)转化为value(int型)值
//用得到的value值又可计算得到所需进制值
class Binary:Base{ //二进制数类
friend class BinaryArray;
public:
Binary():Base(0){}
Binary(int v):Base(v){}
int GetValue(){return Base::GetValue();}
char GetChar();
bool SetValue(int);
bool SetChar(char);
};
char Binary::GetChar(){
static int v;
v=GetValue(); //得到转化后value的值
if(v==0)return '0'; //依据value值设置各位
else if(v==1)return '1';
return '?';
}
bool Binary::SetValue(int v){ //int型数
if(v==0 || v==1){Base::Set(v);return true;}
else return false;
}
bool Binary::SetChar(char c){ //char型数
if(c=='0' || c=='1'){SetValue((int)c+0-'0');return true;}
return false;
}
class BinaryArray{ //Binary对象链表
private:
int size;
int value;
Binary * array;
public:
BinaryArray(int s):size(s),value(0){array=new Binary[size];SetValue(0);}//Setvalue()为Binary[i]置值
BinaryArray(int s,int v):size(s),value(v){array=new Binary[size];SetValue(v);}
int GetValue(){return value;}
int GetValue(int i){return array[i].GetValue();}
char * GetString();
Binary * GetArray(){return array;}
void SetValue(int v);
void SetArray(int p,int v){array[p].SetValue(v);}
bool SetString(char *);
};
char * BinaryArray::GetString(){
char * ret=new char[size+1];
static int i;
for(i=0;i<size;i++)ret[i]=array[i].GetChar();
ret[size]='\0';
return ret;
}
bool BinaryArray::SetString(char * ch){
static int i;
static int v;
static char c;
static Binary b;
v=i=0;
while(c=ch[i],(c != '\0')&&(i<size)){
b.SetChar(c);
v=v*2+b.GetValue();
i++;
}
if(ch[i] != '\0')return false;
SetValue(v);return true;
}
void BinaryArray::SetValue(int v){
static int i;
static int temp;
for(i=size-1;i>=0;i--){
temp=v%2;
array[i].SetValue(temp);
v=(v-temp)/2;
}
}
class Hex:Base{ //16进制类
friend class HexArray;
public:
Hex():Base(0){}
Hex(int v):Base(v){}
int GetValue(){return Base::GetValue();}
char GetChar();
bool SetValue(int);
bool SetChar(char);
};
char Hex::GetChar(){
static int v;
v=GetValue();
if(v>=0 && v<=9) return (char)v+'0'-0;
else if(v>=10 && v<=15) return (char)v+'A'-10;
return '?';
}
bool Hex::SetValue(int v){
if(v>=0 && v<=15){Base::Set(v);return true;}
else return false;
}
bool Hex::SetChar(char c){
CharUpperCase(c);
if(c>='0' && c<='9'){SetValue((int)c+0-'0');return true;}
else if(c>='A' && c<='F'){SetValue((int)c+10-'A');return true;}
return false;
}
class HexArray{ //16进制对象链表
private:
int size;
int value;
Hex * Hexarray;
public:
Hex * GetArray(){return Hexarray;}
HexArray(int s):size(s){Hexarray=new Hex[size];SetValue(0);}
HexArray(int s,int v):size(s){Hexarray=new Hex[size];SetValue(v);}
int GetValue(){return value;}
char * GetString();
void SetValue(int v);
bool SetString(char *);
};
void HexArray::SetValue(int v){
value=v;
static int i;
static int temp;
for(i=size-1;i>=0;i--){
temp=v%16;
Hexarray[i].SetValue(temp);
v=(v-temp)/16;
}
}
char * HexArray::GetString(){
char * ret=new char[size+1];
static int i;
static Hex * ha;
ha=GetArray();
for(i=0;i<size;i++)ret[i]=ha[i].GetChar();
ret[size]='\0';
return ret;
}
bool HexArray::SetString(char * ch){
static int i;
static char c;
static Hex h;
static int v;
v=i=0;
while(c=ch[i],(c != '\0')&&(i<size)){
h.SetChar(c);
v=v*16+h.GetValue();
i++;
}
if(ch[i] != '\0')return false;
SetValue(v); return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -