00001 #ifndef DVTICKET_USER_H 00002 #define DVTICKET_USER_H 00003 // $Id: user.h,v 1.9 2003/08/06 12:12:06 dvermeir Exp $ 00004 00005 #include <string> 00006 #include <iostream> 00007 #include <stdexcept> 00008 #include <dvxml/xml.h> 00009 #include <dvticket/exception.h> 00010 00011 namespace Dv { 00012 namespace Ticket { 00013 00014 class Request; 00015 class Authenticator; 00016 class Ticket; 00017 /** 00018 * A User class for use by Dv::Ticket::Ticket. 00019 * A user is identified by a numeric @a id, and a @a category. 00020 * A user also has a @a name and an uninterpreted @a info string. 00021 * 00022 * The ticket database stores all components of the user-owner 00023 * of the ticket. 00024 * @sa Dv::Ticket::Ticket 00025 */ 00026 class User { 00027 friend class Dv::Ticket::Request; 00028 friend class Dv::Ticket::Authenticator; 00029 friend class Dv::Ticket::Ticket; 00030 public: 00031 /** @return id of this user. */ 00032 int id() const { return id_; } 00033 /** @return name of this user. */ 00034 const std::string& name() const { return name_; } 00035 /** @return category of this user. */ 00036 const std::string& category() const { return category_; } 00037 /** @return extra info on this user. */ 00038 const std::string& info() const { return info_; } 00039 00040 /** @return true iff users have same id and category 00041 * @param user to compare this user with 00042 * @warning name is not taken into account! 00043 */ 00044 bool operator==(const User& user) const { 00045 return id() == user.id() && category() == user.category(); 00046 } 00047 /** Comparison, first on category, then on id. 00048 * @return true iff this user is smaller than user 00049 * @warning name is not taken into account! 00050 */ 00051 bool operator<(const User& user) const; 00052 00053 /** Create XML representation of user. 00054 * @return xml::node representing user 00055 * @code 00056 * <user> 00057 * <id>123</id> 00058 * <category>student</category> 00059 * <name>fred</name> 00060 * <info>Jan Janssens</info> 00061 * </user> 00062 * @endcode 00063 */ 00064 Dv::Xml::Node xml(const std::string& name="user") const; 00065 00066 /** Constructor. 00067 * @param category of user. 00068 * @param id of user. 00069 * @param name of user. 00070 * @param info uninterpreted extra info 00071 */ 00072 User(const std::string& category="anonymous", int id=0, 00073 const std::string& name="anonymous", const std::string& info =""): id_(id), 00074 category_(category), name_(name), info_(info) {} 00075 00076 /** Constructor. 00077 * @param xml_user XML representation of User 00078 * @exception Dv::Ticket::Exception if anything goes wrong 00079 * @sa Dv::Ticket::User::xml 00080 */ 00081 User(Dv::Xml::Node::Ref xml_user) throw (Dv::Ticket::Exception); 00082 private: 00083 00084 /** Id of user, should be unique within the same category. */ 00085 int id_; 00086 /** Category of user. */ 00087 std::string category_; 00088 /** User name (e.g. login name). */ 00089 std::string name_; 00090 /** Extra info */ 00091 std::string info_; 00092 }; 00093 00094 } } 00095 #endif
dvticket-0.7.1 | [24 October, 2003] |