LicenseSpring C++ SDK  7.27.0
Easily add Software Licensing to your application
LicenseID.h
Go to the documentation of this file.
1 #ifndef LS_LICENSE_ID_H
2 #define LS_LICENSE_ID_H
3 
4 #ifdef _MSC_VER
5 #pragma once
6 #pragma warning( push )
7 #pragma warning( disable : 4251 )
8 #endif
9 
10 #include <string>
11 #include "APIDef.h"
12 
13 namespace LicenseSpring
14 {
19  {
20  public:
22  LicenseID() = default;
23 
25  LicenseID( const LicenseID& ) = default;
26 
30  bool isEmpty() const;
31 
35  bool isValid() const;
36 
39  const std::string& id() const;
40 
43  const std::string& key() const;
44 
47  const std::string& user() const;
48 
52  const std::string& password() const;
53 
56  void setPassword( const std::string& password );
57 
59  void trim();
60 
67  static LicenseID fromKey( const std::string& licenseKey, bool needTrim = true );
68 
74  static LicenseID fromKey( const char* licenseKey );
75 
83  static LicenseID fromUser( const std::string& user, const std::string& password = std::string(),
84  bool needTrim = true );
85 
92  static LicenseID fromUser( const char* user, const char* password = nullptr );
93 
94  private:
95  std::string m_key;
96  std::string m_user;
97  std::string m_password;
98  };
99 }
100 
101 #ifdef _MSC_VER
102 #pragma warning( pop )
103 #endif
104 
105 #endif // LS_LICENSE_ID_H
#define LS_API
Macros that expands to dllexport, dllimport or nothing on non Windows platforms or in case of static ...
Definition: APIDef.h:22
Class that represents License identifier.
Definition: LicenseID.h:19
bool isEmpty() const
Checks if LicenseID is empty.
static LicenseID fromUser(const std::string &user, const std::string &password=std::string(), bool needTrim=true)
Constructs LicenseID with given user credentials.
void trim()
Remove trailing whitespaces from the end and beginning of ID (key or user and password).
const std::string & key() const
Returns license key or empty string, if key is not set (for example in case of user-based product).
const std::string & user() const
Returns user identifier or empty string, if user is not set (for example in case of key-based product...
const std::string & id() const
Returns license key or user identifier, depending of what is present.
LicenseID()=default
Default constructor, constructs invalid (empty) LicenseID.
static LicenseID fromUser(const char *user, const char *password=nullptr)
Constructs LicenseID with given user credentials.
bool isValid() const
Checks if LicenseID is valid.
static LicenseID fromKey(const char *licenseKey)
Constructs LicenseID with given license key.
LicenseID(const LicenseID &)=default
Default copy constructor.
void setPassword(const std::string &password)
Sets user password accordingly to provided string.
static LicenseID fromKey(const std::string &licenseKey, bool needTrim=true)
Constructs LicenseID with given license key.
const std::string & password() const
Returns user password or empty string, if password is not set.