Skip to content

Commit 18cc21a

Browse files
author
qucals
committed
Updated to 0.0.7
- Fixed the recommendations of the static analyzer - The problem of not compiling on windows has not yet been solved - Added Optional type
1 parent 4bb530f commit 18cc21a

15 files changed

Lines changed: 189 additions & 85 deletions

.github/workflows/windows.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ jobs:
2222
with:
2323
submodules: true
2424

25-
# - name: Install vcpkg and deps
26-
# run: |
27-
# cd ..
28-
# git clone ${{ env.VCPKG_GIT }}
29-
# cd vcpkg
30-
# git checkout --force 2020.01
31-
# .\bootstrap-vcpkg.bat
32-
# .\vcpkg.exe install curl
33-
# cd ${{ github.workspace }}
34-
35-
# - name: Configure VKAPI Library CMake
36-
# run: cmake -B ${{ env.CMAKE_BUILD_DIR }} -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} /../vcpkg/scripts/buildsystems/vcpkg.cmake
37-
3825
- name: Install deps
3926
uses: crazy-max/ghaction-chocolatey@v1
4027
with:

include/BotBase.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
* Contains the class for working with vkbot.
33
* @file BotBase.hpp
44
* @author qucals
5-
* @version 0.0.6 19/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_BOTBASE_HPP
119
#define VKAPI_BOTBASE_HPP
1210

13-
#include <ClientBase.hpp>
11+
#include "ClientBase.hpp"
1412

1513
namespace vk
1614
{
@@ -162,6 +160,7 @@ class BotBase : public ClientBase
162160
*
163161
* @retval a string (URL) of this method.
164162
*/
163+
_VKAPI_COMPLEXITY_FUNCTION
165164
_VKAPI_STATIC std::string MethodToString(METHODS method);
166165

167166
/**
@@ -194,7 +193,7 @@ class BotBase : public ClientBase
194193
*
195194
* @retval the answer of your request in JsonType.
196195
*/
197-
auto SendRequestAsync(METHODS method, const JsonType& parametersData);
196+
auto SendRequestAsync(METHODS method, const JsonType& parametersData) -> std::future<JsonType>;
198197

199198
/**
200199
* @brief The function witch calls private function for sending a request in asynchronous mode.
@@ -204,7 +203,7 @@ class BotBase : public ClientBase
204203
*
205204
* @retval the answer of your request in JsonType.
206205
*/
207-
auto SendRequestAsync(const std::string& method, const JsonType& parametersData);
206+
auto SendRequestAsync(const std::string& method, const JsonType& parametersData) -> std::future<JsonType>;
208207

209208
#endif // __CPLUSPLUS_OVER_11
210209

@@ -227,6 +226,7 @@ class BotBase : public ClientBase
227226
*
228227
* @retval the type of event in enum (EVENTS).
229228
*/
229+
_VKAPI_COMPLEXITY_FUNCTION
230230
_VKAPI_STATIC EVENTS GetTypeEvent(const std::string& typeEvent);
231231

232232
private:

include/ClientBase.hpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,50 @@
22
* Contains general objects for working with VK API.
33
* @file ClientBase.hpp
44
* @author qucals
5-
* @version 0.0.6 19/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_CLIENTBASE_HPP
119
#define VKAPI_CLIENTBASE_HPP
1210

13-
#include <Config.hpp>
11+
#include "Config.hpp"
1412

15-
#include <Request.hpp> // Request
16-
#include <Utilities.hpp> // ConvertStrToUrlCode
17-
#include <Exceptions.hpp> // already_connected, not_connected, empty_argument
18-
#include <Defines.hpp>
13+
#include "Request.hpp" // Request
14+
#include "Utilities.hpp" // ConvertStrToUrlCode
15+
#include "Exceptions.hpp" // already_connected, not_connected, empty_argument
16+
#include "Defines.hpp"
1917

2018
#ifdef __VKAPI_VERSION_ADDED_OPTIONAL
2119
#if __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL
22-
#include <Optional.hpp>
20+
#include "Optional.hpp"
2321
#endif // __VKAPI_COMPILED_VERSION >= __VKAPI_VERSION_ADDED_OPTIONAL
2422
#endif // __VKAPI_VERSION_ADDED_OPTIONAL
2523

2624
#include <iostream> // cout, endl
2725
#include <random> // rand
2826
#include <set> // set
2927
#include <string> // string
28+
#include <iterator> // begin, end
3029

3130
#ifdef __CPLUSPLUS_OVER_11
3231
#include <future> // async, future
3332
#endif // __CPLUSPLUS_OVER_11
3433

35-
#include <nlohmann/json.hpp> // nlohmann::json
34+
#include "nlohmann/json.hpp" // nlohmann::json
3635

3736
namespace vk
3837
{
3938

4039
namespace base
4140
{
4241

43-
#ifdef __VKAPI_VERSION_ADDED_OPTIONAL
44-
#if __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL
45-
typedef nlohmann::json JsonType;
46-
#endif // __VKAPI_COMPILED_VERSION < __VKAPI_VERSION_ADDED_OPTIONAL
47-
#else
42+
#ifndef VKAPI_OPTIONAL_HPP
4843
typedef nlohmann::json JsonType;
49-
#endif // __VKAPI_VERSION_ADDED_OPTIONAL
44+
45+
typedef long long int IdType;
46+
typedef unsigned long long UIdType;
47+
typedef bool IndicatorType;
48+
#endif // VKAPI_OPTIONAL_HPP
5049

5150
#define VKAPI_INVALID_REQUEST "invalid_request"
5251
#define VKAPI_NEED_CAPTCHA "need_captcha"

include/Config.hpp.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
* Contains information about the project's version.
33
* @file Config.hpp
44
* @author qucals
5-
* @version @VKAPI_MAJOR_VERSION@.@VKAPI_MINOR_VERSION@.@VKAPI_PATCH_VERSION@ 18/08/21
5+
* @version @VKAPI_MAJOR_VERSION@.@VKAPI_MINOR_VERSION@.@VKAPI_PATCH_VERSION@ 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_CONFIG_HPP_IN
119
#define VKAPI_CONFIG_HPP_IN
1210

include/Defines.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
* Contains general defines about the language.
33
* @file Defines.hpp
44
* @author qucals
5-
* @version 0.0.6 20/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_DEFINES_HPP
119
#define VKAPI_DEFINES_HPP
1210

13-
#include <Config.hpp>
11+
#include "Config.hpp"
1412

1513
#ifndef _VKAPI_NO_IMPL
1614
#define _VKAPI_NO_IMPL
@@ -87,15 +85,19 @@
8785
#define _VKAPI_INLINE inline
8886
#endif // _VKAPI_INLINE
8987

88+
#ifndef _VKAPI_UNUSED
89+
#define _VKAPI_UNUSED(x) (void)(x)
90+
#endif // _VKAPI_UNUSED
91+
9092
#if defined(_MSC_VER)
91-
#define __DISABLE_WARNING_PUSH __pragma(warning( push ))
92-
#define __DISABLE_WARNING_POP __pragma(warning( pop ))
93-
#define __DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber ))
93+
#define __DISABLE_WARNING_PUSH __pragma(warning(push))
94+
#define __DISABLE_WARNING_POP __pragma(warning(pop))
95+
#define __DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber))
9496
#elif defined(__GNUC__) || defined(__clang__)
9597
#define __DO_PRAGMA(X) _Pragma(#X)
96-
#define __DISABLE_WARNING_PUSH __DO_PRAGMA(GCC diagnostic push)
97-
#define __DISABLE_WARNING_POP __DO_PRAGMA(GCC diagnostic pop)
98-
#define __DISABLE_WARNING(warningName) __DO_PRAGMA(ide diagnostic ignored #warningName)
98+
#define __DISABLE_WARNING_PUSH __DO_PRAGMA("GCC diagnostic push")
99+
#define __DISABLE_WARNING_POP __DO_PRAGMA("GCC diagnostic pop")
100+
#define __DISABLE_WARNING(warningName) __DO_PRAGMA("GCC diagnostic ignored \"#warningName\"")
99101
#else
100102
#define __DISABLE_WARNING_PUSH
101103
#define __DISABLE_WARNING_POP
@@ -106,4 +108,7 @@
106108
#define __VKAPI_VERSION_ADDED_OPTIONAL __VKAPI_VERSION_NUM(0, 0, 7)
107109
#endif // __VKAPI_VERSION_ADDED_OPTIONAL
108110

111+
// TODO(#14): Write defines for disable complexity warnings
112+
#define _VKAPI_COMPLEXITY_FUNCTION
113+
109114
#endif //VKAPI_DEFINES_HPP

include/Exceptions.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
* Contains exceptions and information about them of this library.
33
* @file Exceptions.hpp
44
* @author qucals
5-
* @version 0.0.6 19/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_EXCEPTIONS_HPP
119
#define VKAPI_EXCEPTIONS_HPP
1210

11+
#include <string>
1312
#include <exception>
1413

15-
#include <Defines.hpp>
14+
#include "Defines.hpp"
1615

1716
namespace vk
1817
{

include/Optional.hpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* Describes optional class.
3+
* @file Optional.hpp
4+
* @author qucals
5+
* @version 0.0.7 24/08/21
6+
*/
7+
8+
#ifndef VKAPI_OPTIONAL_HPP
9+
#define VKAPI_OPTIONAL_HPP
10+
11+
#include <vector>
12+
13+
#include "Defines.hpp"
14+
#include "nlohmann/json.hpp"
15+
16+
namespace vk
17+
{
18+
19+
namespace base
20+
{
21+
22+
#if defined(__CPLUSPLUS_OVER_17)
23+
24+
#include <optional>
25+
26+
template<typename T>
27+
class Optional : public std::optional<T>
28+
{};
29+
30+
#else
31+
32+
template<typename _Type>
33+
class BasicOptional
34+
{
35+
public:
36+
#if defined(__CPLUSPLUS_OVER_11)
37+
typedef _Type&& _RValue_Type;
38+
typedef const _Type& _ConstRef_Type;
39+
#else
40+
typedef const _Type& _RValue_Type;
41+
typedef const _Type& _ConstRef_Type;
42+
#endif // defined(__CPLUSPLUS_OVER_14)
43+
44+
BasicOptional()
45+
: m_isSet(false)
46+
{}
47+
48+
_VKAPI_EXPLICIT BasicOptional(_RValue_Type val)
49+
: m_val(_VKAPI_MOVE(val))
50+
, m_isSet(true)
51+
{}
52+
53+
void Set(_ConstRef_Type val)
54+
{
55+
m_val = val;
56+
m_isSet = true;
57+
}
58+
59+
const _Type& Get() const& _VKAPI_NOEXCEPT
60+
{ return m_val; }
61+
62+
void Clear()
63+
{
64+
m_val = _Type();
65+
m_isSet = false;
66+
}
67+
68+
bool Empty()
69+
{ return !m_isSet; }
70+
71+
BasicOptional& operator=(_ConstRef_Type val)
72+
{
73+
m_val = val;
74+
m_isSet = true;
75+
return *this;
76+
}
77+
78+
_VKAPI_EXPLICIT operator _Type() const
79+
{
80+
return m_val;
81+
}
82+
83+
bool operator==(const bool& val) const
84+
{ return m_isSet == val; }
85+
86+
private:
87+
_Type m_val;
88+
bool m_isSet;
89+
};
90+
91+
template<typename T>
92+
class Optional : public BasicOptional<T>
93+
{};
94+
95+
#endif // defined(__CPLUSPLUS_OVER_17)
96+
97+
typedef long long int IdType;
98+
typedef unsigned long long UIdType;
99+
typedef bool IndicatorType;
100+
101+
typedef nlohmann::json JsonType;
102+
103+
typedef Optional<IdType> Opt_IdType;
104+
typedef Optional<UIdType> Opt_UIdType;
105+
typedef Optional<const std::string&> Opt_StrType;
106+
typedef Optional<float> Opt_FloatType;
107+
typedef Optional<const JsonType&> Opt_JsonType;
108+
typedef Optional<const std::vector<IdType>&> Opt_IdArrayType;
109+
typedef Optional<IndicatorType> Opt_IndicatorType;
110+
111+
} // namespace base
112+
113+
} // namespace vk
114+
115+
#endif //VKAPI_OPTIONAL_HPP

include/Request.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
* Describes the class for working with CURL.
33
* @file Request.hpp
44
* @author qucals
5-
* @version 0.0.6 19/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_REQUEST_HPP
119
#define VKAPI_REQUEST_HPP
1210

13-
#include <Defines.hpp>
14-
#include <Utilities.hpp> // ConvertStrToUrlCode
11+
#include "Defines.hpp"
12+
#include "Utilities.hpp" // ConvertStrToUrlCode
1513

1614
#include <curl/curl.h> // curl
1715
#include <string> // string

include/UserBase.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
* Describes the class for working with VK account.
33
* @file UserBase.hpp
44
* @author qucals
5-
* @version 0.0.6 19/08/21
5+
* @version 0.0.7 24/08/21
66
*/
77

8-
#pragma once
9-
108
#ifndef VKAPI_USERBASE_HPP
119
#define VKAPI_USERBASE_HPP
1210

13-
#include <ClientBase.hpp>
11+
#include "ClientBase.hpp"
1412

1513
namespace vk
1614
{
@@ -486,6 +484,7 @@ class UserBase : public ClientBase
486484
*
487485
* @retval a string of this method in URL format.
488486
*/
487+
_VKAPI_COMPLEXITY_FUNCTION
489488
_VKAPI_STATIC std::string MethodToString(METHODS method);
490489

491490
/**

0 commit comments

Comments
 (0)