Advertisement
DmitryPythonDevelop

Untitled

Apr 18th, 2020
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1. template<typename type>
  2. struct DataStruct
  3. {
  4.     type data; // Переменная для хранения элемента
  5.     DataStruct *next; // Указатель на след. элемент
  6.         public : DataStruct() {};
  7. };
  8.  
  9.  
  10. // Односвязный список
  11. template<typename type>
  12. class List
  13. {
  14.     protected:
  15.         // Голова и хвост
  16.         DataStruct<type> *head;
  17.         DataStruct<type> *tail;
  18.  
  19.     public:
  20.  
  21.         List(); // Конструктор
  22.  
  23.         void addElement ( const type &element );               // Добавление елемента в список
  24.         void deleteElement( const int i );               // Удаление элемента из списка
  25.         void clear ();                                   // Очистить список
  26.  
  27.         const nlohmann::json serialization ();           // Сериализация данных
  28.         void deserialization ( const nlohmann::json &data );
  29.  
  30.         type* operator[] ( const int i ); // Оператор индексирования
  31.  
  32.         ~List(); // Деструктор
  33. };
  34.  
  35. template<typename type>
  36. void List<type>::addElement( const type &element) {
  37.     DataStruct<type>* tmp = new DataStruct<type>(); // буферная структура
  38.  
  39.     tmp->data = element;
  40.     tmp->next = nullptr;
  41.  
  42.     // Если в списке уже есть объекты
  43.     if( this->head != nullptr ) {
  44.         this->tail->next = tmp;  
  45.         this->tail = tmp;  
  46.     } else {
  47.         // Если элемент первый - он является и хвостом и головой
  48.         this->tail = this->head = tmp; 
  49.     }
  50. }
  51.  
  52.  
  53. // Вот это производный от первого класс, именно в нем храниться объект о котором дальше пойдет речь
  54. template<typename type>
  55. class WalletList : public List<type>
  56. {
  57.     public:
  58.         type* getWalletByCurrency ( const std::string &Currency); // Получить кошелек
  59.        
  60.         void createWalletsFromJson ( nlohmann::json &data );
  61.         void createWalletsSecureFromJson ( nlohmann::json &data );
  62.  
  63.         std::map<std::string, long> getWallets();
  64. };
  65.  
  66.  
  67. // Вот это сам объект с которым возникают проблемы
  68. class Money
  69. {
  70.     protected:
  71.  
  72.         std::string Currency;
  73.         long Summ;
  74.  
  75.     public:
  76.  
  77.         Money () {};
  78.         Money ( const std::string Currency, const long Summ );
  79.  
  80.         const std::string getCurrency ();   // Получить наименование валюты
  81.         const long getSum ();       // Получить кол-во средств на счету
  82.  
  83.         virtual const nlohmann::json serialization ();
  84.  
  85.         bool withdraw ( const long &Summ );
  86.  
  87.         void operator+= ( const long &Summ); // Увеличить счет
  88.         bool operator== ( const Money &money);
  89.  
  90.         static std::vector<std::string> getValidCurrencies();
  91. };
  92. // Это производный от первого, с ним сообветственно тоже такие же проблемы,
  93. // но это я скорее для полноты картины скинул
  94. class MoneySecure : public Money, public SecurePassword {
  95.     public:
  96.         MoneySecure () {};
  97.         MoneySecure ( const std::string Currency, const long Summ, const std::string password ) : Money(Currency, Summ), SecurePassword(password) {}
  98.         MoneySecure ( const std::string Currency, const long Summ, const long password ) : Money(Currency, Summ), SecurePassword(password) {}
  99.         const nlohmann::json serialization () override;
  100. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement