Advertisement
Guest User

Untitled

a guest
May 29th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #ifndef DATABASE_HPP_INCLUDED
  2. #define DATABASE_HPP_INCLUDED
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <json/json.h>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. class Database {
  12. public:
  13. void loadFromFile (const string& fname) {
  14. Json::Value root;
  15. ifstream file (fname);
  16. if (!file.is_open())
  17. cout << "shit happens\n";
  18.  
  19. file >> root;
  20. Json::Value jBooks = root["books"];
  21.  
  22. if (!jBooks.isNull()) {
  23. for (int i = 0; i < jBooks.size(); i++) {
  24. Book b;
  25. b.author = jBooks[i]["author"].asString();
  26. books.push_back (b);
  27. }
  28. }
  29. }
  30.  
  31. private:
  32. vector <Book> books;
  33. };
  34.  
  35. #endif // DATABASE_HPP_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement