diff options
author | Enrico Zini <enrico@enricozini.org> | 2009-09-29 15:08:02 +0100 |
---|---|---|
committer | Enrico Zini <enrico@enricozini.org> | 2009-09-29 15:08:02 +0100 |
commit | 006621455482edd8abf46a05292120745f99f7ec (patch) | |
tree | ff1318ccc409a3dd0519035ce2949ac8a48e969e /ept/token.h | |
download | libept-006621455482edd8abf46a05292120745f99f7ec.tar.gz |
Initial import
Diffstat (limited to 'ept/token.h')
-rw-r--r-- | ept/token.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ept/token.h b/ept/token.h new file mode 100644 index 0000000..ecacc16 --- /dev/null +++ b/ept/token.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +#include <wibble/mixin.h> +#include <string> + +#ifndef EPT_TOKEN_H +#define EPT_TOKEN_H + +namespace ept { + +struct Token : wibble::mixin::Comparable< Token > { + std::string _id; // formatted as package[_version] + std::string id() const { return _id; } + + Token() : _id( "" ) {} + Token( std::string s ) : _id( s ) {} + + std::string version() const { + return _id.find( '_' ) == std::string::npos ? "" : + std::string( _id, _id.find( '_' ) + 1, _id.size() ); + } + + std::string package() const { + return std::string( _id, 0, + _id.find( '_' ) == std::string::npos ? + _id.size() : _id.find( '_' ) ); + } + + bool isDesktop() const { + return std::string( _id, 0, 8 ) == "desktop:"; + } + + std::string desktop() const { + return isDesktop() ? std::string( _id, 8, _id.size() ) : ""; + } + + bool hasVersion() const { + return version() != ""; + } + + bool valid() const { + return _id != ""; + } + + bool operator<=( const Token &o ) const { + return _id <= o._id; + } +}; + +} + +inline std::ostream &operator<<( std::ostream &o, const ept::Token &t ) { + return o << t.id(); +} + +#endif |