Commit cd419d46 authored by Ilya Prokhorov's avatar Ilya Prokhorov

NotNull shared pointer implementation

parent 454bd1cb
......@@ -16,11 +16,6 @@ using namespace std;
namespace FlameSteelCore {
namespace Utils {
void throwRuntimeException(string error) {
cout << error << endl;
throw runtime_error(error);
};
int RandomInt(int maximalInt) {
if (maximalInt == 0) {
......
......@@ -19,7 +19,11 @@ namespace Utils {
int RandomInt(int maximalInt);
bool RandomBool();
shared_ptr<string> localizedString(shared_ptr<string> key);
void throwRuntimeException(string error);
template <typename T>
void throwRuntimeException(T errorText) {
throw runtime_error(errorText);
};
};
};
......
......@@ -33,7 +33,32 @@ private:
};
template <typename T, typename... Args>
shared_ptr<SharedNotNullPointer<T> >
MakeSharedNotNullPointer(Args&&... args) {
auto rawSharedPointer = make_shared<T>(forward<Args>(args)...);
auto sharedNotNullPointer = make_shared<SharedNotNullPointer<T> >(rawSharedPointer);
return sharedNotNullPointer;
};
namespace Shortcuts {
template <typename T>
using NotNull = shared_ptr<SharedNotNullPointer<T> >;
template <typename T, typename... Args>
shared_ptr<SharedNotNullPointer<T> >
make(Args&&... args) {
return MakeSharedNotNullPointer<T>(forward<Args>(args)...);
};
};
};
};
#endif
\ No newline at end of file
#include "FSCUtils.h"
namespace FlameSteelCore {
namespace Utils {
void throwRuntimeException(char *errorText) {
throwRuntimeException(string(errorText));
};
};
};
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment