1 : // -*- C++ -*-
2 : #include <wibble/mixin.h>
3 : #include <string>
4 :
5 : #ifndef EPT_TOKEN_H
6 : #define EPT_TOKEN_H
7 :
8 : namespace ept {
9 :
10 9994 : struct Token : wibble::mixin::Comparable< Token > {
11 : std::string _id; // formatted as package[_version]
12 0 : std::string id() const { return _id; }
13 :
14 9755 : Token() : _id( "" ) {}
15 8 : Token( std::string s ) : _id( s ) {}
16 :
17 1831 : std::string version() const {
18 : return _id.find( '_' ) == std::string::npos ? "" :
19 1831 : std::string( _id, _id.find( '_' ) + 1, _id.size() );
20 : }
21 :
22 7883 : std::string package() const {
23 : return std::string( _id, 0,
24 : _id.find( '_' ) == std::string::npos ?
25 7883 : _id.size() : _id.find( '_' ) );
26 : }
27 :
28 : bool isDesktop() const {
29 : return std::string( _id, 0, 8 ) == "desktop:";
30 : }
31 :
32 : std::string desktop() const {
33 : return isDesktop() ? std::string( _id, 8, _id.size() ) : "";
34 : }
35 :
36 17 : bool hasVersion() const {
37 17 : return version() != "";
38 : }
39 :
40 1 : bool valid() const {
41 1 : return _id != "";
42 : }
43 :
44 58 : bool operator<=( const Token &o ) const {
45 58 : return _id <= o._id;
46 : }
47 : };
48 :
49 : }
50 :
51 0 : inline std::ostream &operator<<( std::ostream &o, const ept::Token &t ) {
52 0 : return o << t.id();
53 : }
54 :
55 : #endif
|