• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

token.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include <wibble/mixin.h>
00003 #include <string>
00004 
00005 #ifndef EPT_TOKEN_H
00006 #define EPT_TOKEN_H
00007 
00008 namespace ept {
00009 
00010 struct Token : wibble::mixin::Comparable< Token > {
00011     std::string _id; // formatted as package[_version]
00012     std::string id() const { return _id; }
00013 
00014     Token() : _id( "" ) {}
00015     Token( std::string s ) : _id( s ) {}
00016 
00017     std::string version() const {
00018         return _id.find( '_' ) == std::string::npos ? "" :
00019             std::string( _id, _id.find( '_' ) + 1, _id.size() );
00020     }
00021 
00022     std::string package() const {
00023         return std::string( _id, 0,
00024                             _id.find( '_' ) == std::string::npos ?
00025                             _id.size() : _id.find( '_' ) );
00026     }
00027 
00028     bool isDesktop() const {
00029         return std::string( _id, 0, 8 ) == "desktop:";
00030     }
00031 
00032     std::string desktop() const {
00033         return isDesktop() ? std::string( _id, 8, _id.size() ) : "";
00034     }
00035 
00036     bool hasVersion() const {
00037         return version() != "";
00038     }
00039 
00040     bool valid() const {
00041         return _id != "";
00042     }
00043 
00044     bool operator<=( const Token &o ) const {
00045         return _id <= o._id;
00046     }
00047 };
00048 
00049 }
00050 
00051 inline std::ostream &operator<<( std::ostream &o, const ept::Token &t ) {
00052     return o << t.id();
00053 }
00054 
00055 #endif

Generated on Wed Oct 27 2010 12:43:31 for libept by  doxygen 1.7.1