O_Egor

daatabase.cpp

Oct 15th, 2022
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include "database.h"
  2. using namespace std;
  3.  
  4. void Database::Add(const Date& _Date, const string& _Event)
  5. {
  6.     const auto it = Records[_Date].first.insert(_Event);
  7.     if (it.second)
  8.     {
  9.         Records[_Date].second.push_back(it.first);
  10.     }
  11. }
  12.  
  13. void Database::Print(ostream& os) const
  14. {
  15.     for (const auto& [_Key, _Value] : Records)
  16.     {
  17.         for (const auto& _Event : _Value.second)
  18.             os << _Key << ' ' << *_Event << "\n";
  19.     }
  20. }
  21.  
  22. string Database::Last(const Date& _Date) const
  23. {
  24.     const auto upperIt = Records.upper_bound(_Date);
  25.     if (upperIt == Records.begin())
  26.     {
  27.         return "No entries";
  28.     }
  29.  
  30.     return prev(upperIt)->first.DateToStr() + ' ' + *prev(upperIt)->second.second.back();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment