Changeset 7ccc366e52cc1e51e123b39fccaf56267361ca58

Show
Ignore:
Timestamp:
08/25/10 18:30:39 (18 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
43f521291669f483d361949fa6c886c0fbd94daf
Parents:
7eb42bed950e3f81ef9f0d39432e07c55f12cc22
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (08/25/10 18:30:39)
Message:

[db::db_reader] Move from db_detail

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Location:
db
Files:
3 added
2 modified

Legend:

Unmodified
Added
Removed
  • db/db.cc

    r050d01b r7ccc366  
    1919 
    2020#include "db.hh" 
     21#include "db_reader.hh" 
    2122#include "role.hh" 
     23#include "role_exists.hh" 
    2224#include "user.hh" 
    2325#include "user_exists.hh" 
     
    3335#include <fstream> 
    3436 
    35 // TODO: Decouple record parsing by an "event" mechanism. 
    36  
    37 namespace db_detail 
    38 { 
    39         class illformed_db : public std::exception 
    40         { 
    41                 const std::string s; 
    42         public: 
    43                 illformed_db(std::string s) : s("illformed db: " + s) {} 
    44                 ~illformed_db() throw() {} 
    45                 const char *what() const throw() { return s.c_str(); } 
    46         }; 
    47  
    48         class role_exists : public std::exception 
    49         { 
    50                 const std::string s; 
    51         public: 
    52                 role_exists(std::string name) : s(name + " exists") {} 
    53                 ~role_exists() throw() {} 
    54                 const char *what() const throw() { return s.c_str(); } 
    55         }; 
    56  
    57         class rollback {}; 
    58  
    59         class db_reader : public boost::noncopyable 
    60         { 
    61                 std::istream &dbfile; 
    62         public: 
    63                 db_reader(std::istream &is) : dbfile(is) {} 
    64                 void readline(std::string &line) { 
    65                         std::getline(dbfile, line); 
    66                         if (line.substr(0, 7) == ".BEGIN ") throw rollback(); 
    67                 } 
    68  
    69                 std::string readline(std::string &line, std::string cmd){ 
    70                         readline(line); 
    71                         util::strip(line); 
    72                         if (line.substr(0, cmd.length()+1) != cmd + " ") 
    73                                 throw illformed_db(cmd + " missing"); 
    74                         return line.substr(cmd.length()+1); 
    75                 } 
    76  
    77                 void endrec(std::string &line) { 
    78                         std::getline(dbfile, line); 
    79                         if (!dbfile || line.substr(0, 7) == ".BEGIN ")  
    80                                 throw rollback(); 
    81                         util::strip(line); 
    82                         if (line != ".END") throw illformed_db(".END missing"); 
    83                 } 
    84                 bool valid() { return dbfile; } 
    85         }; 
    86  
    87 } 
    88  
    8937namespace db 
    9038{ 
    91         using namespace db_detail; 
    92  
    9339        db::db() 
    9440                : dbname(config["db-file"].as<std::string>()) 
  • db/db.hh

    r5d836bd r7ccc366  
    3737namespace msg { class msg; } 
    3838 
    39 namespace db_detail { class db_reader; } 
    40  
    4139namespace db 
    4240{ 
    4341        class user; 
    4442        class password_handler; 
     43        class db_reader; 
    4544 
    4645        class db : private boost::noncopyable 
     
    114113 
    115114                void add_record(std::string record); 
    116                  
    117115        private: 
    118116                mutable boost::recursive_mutex mt; 
     
    133131                boost::random_device rand; 
    134132 
    135                 void do_newgroup(db_detail::db_reader &, std::string, 
     133                void do_newgroup(db_reader &, std::string, 
    136134                                 boost::posix_time::ptime); 
    137                 void do_user(db_detail::db_reader &, std::string); 
    138                 void do_article(db_detail::db_reader &, std::string); 
    139                 void do_role(db_detail::db_reader &, std::string); 
    140                 void read_record(db_detail::db_reader &dr, 
    141                                  boost::posix_time::ptime); 
     135                void do_user(db_reader &, std::string); 
     136                void do_article(db_reader &, std::string); 
     137                void do_role(db_reader &, std::string); 
     138                void read_record(db_reader &dr, boost::posix_time::ptime); 
    142139                void register_role(boost::shared_ptr<role>); 
    143140        };