Advertisement
Guest User

Untitled

a guest
May 26th, 2016
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include "ini_stream.h"
  2.  
  3. namespace stream
  4. {
  5.     ini_stream & ini_stream::operator >> (section & section)
  6.     {
  7.         std::string line;
  8.        
  9.         int index = 0;
  10.  
  11.         while (std::getline(fs, line))
  12.         {
  13.             if (is_comment(line) || is_empty(line)) continue;
  14.             if (is_section(line))
  15.             {      
  16.                 if (index != 0) {
  17.                     for (size_t i = 0; i <= line.length(); i++)
  18.                     {
  19.                         fs.unget();
  20.                     }
  21.                     return *this;
  22.                 }
  23.  
  24.                 section.name = line.substr(1, line.size() - 2);
  25.                 ++index;
  26.             }
  27.  
  28.             else if (is_pair(line)) {
  29.                 auto s = split(line);
  30.                 section.pairs.push_back(pair{ s[0],s[1],&section});
  31.             }
  32.         }
  33.         return *this;
  34.     }
  35.     std::ostream & operator<<(std::ostream & os, const section & section)
  36.     {
  37.         os << "[" << section.name << "]" << std::endl;
  38.         for (auto p : section.pairs) os << p << std::endl;
  39.         return os;
  40.     }
  41.     std::ostream & operator<<(std::ostream & os, const pair & pair)
  42.     {
  43.         return os << pair.name << "=" << pair.value;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement