LicenseSpring C++ SDK
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
13namespace LicenseSpring
14{
21{
22public:
24 LicenseID() = default;
25
27 LicenseID(const LicenseID &) = default;
28
32 bool isEmpty() const;
33
38 bool isValid() const;
39
42 const std::string &id() const;
43
47 const std::string &key() const;
48
52 const std::string &user() const;
53
57 const std::string &password() const;
58
63 uint64_t serverId() const;
64
67 void setPassword(const std::string &password);
68
71 void trim();
72
80 static LicenseID fromKey(const std::string &licenseKey, bool needTrim = true);
81
88 static LicenseID fromKey(const char *licenseKey);
89
99 const std::string &user, const std::string &password = std::string(), bool needTrim = true);
100
108 static LicenseID fromUser(const char *user, const char *password = nullptr);
109
119 static LicenseID fromUser(const std::string &user, uint64_t serverId,
120 const std::string &password = std::string(), bool needTrim = true);
121
130 static LicenseID fromUser(const char *user, uint64_t serverId, const char *password = nullptr);
131
132private:
133 std::string m_key;
134 std::string m_user;
135 std::string m_password;
136 uint64_t m_serverId;
137};
138} // namespace LicenseSpring
139
140#ifdef _MSC_VER
141#pragma warning(pop)
142#endif
143
144#endif // LS_LICENSE_ID_H
#define LS_API
Definition: APIDef.h:23
Class that represents License identifier.
Definition: LicenseID.h:21
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 & password() const
Returns user password or empty string, if password is not set.
const std::string & user() const
Returns user identifier or empty string, if user is not set (for example in case of key-based product...
static LicenseID fromUser(const char *user, uint64_t serverId, const char *password=nullptr)
Constructs LicenseID with given user credentials.
const std::string & id() const
Returns license key or user identifier, depending of what is present.
const std::string & key() const
Returns license key or empty string, if key is not set (for example in case of user-based product).
static LicenseID fromUser(const std::string &user, uint64_t serverId, const std::string &password=std::string(), bool needTrim=true)
Constructs LicenseID with given user credentials.
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.
uint64_t serverId() const
Returns server-side license id, or 0 if license is key-based.