Initial Commit (This Dick)

This commit is contained in:
2024-07-30 00:17:51 -04:00
commit f26dae5fd0
7 changed files with 131 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

41
CMakeLists.txt Normal file
View File

@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.18...3.28)
project(Property
VERSION 1.0
LANGUAGES CXX
)
# Prevent dummies from cluttering the source dir
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-Source builds are not allowed")
endif()
# MODERN C++
set(CMAKE_CXX_STANDARD 20)
# Maybe required Windows compat flag?
if (WIN32)
set(CMAKE_CXX_FLAGS "-municode")
endif()
file(GLOB_RECURSE Property_HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE Property_SRC "src/*.c" "src/*.cpp")
if (UNIX)
add_library(Property SHARED ${Property_SRC})
endif()
if (WIN32)
add_library(Property STATIC ${Property_SRC})
endif()
target_include_directories(Property PUBLIC "include")
set_target_properties(Property PROPERTIES LINKER_LANGUAGE CXX)
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
install(FILES ${Property_HEADERS} DESTINATION include/${PROJECT_NAME})
add_executable(PropertyDemo main.cpp)
target_link_libraries(PropertyDemo Property)

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 7/29/24.
//
#ifndef PROPERTY_OBFUSCATEDPROPERTY_HPP
#define PROPERTY_OBFUSCATEDPROPERTY_HPP
#endif //PROPERTY_OBFUSCATEDPROPERTY_HPP

19
include/Property.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
template <typename T>
class Property
{
private:
protected:
T prop;
public:
virtual ~Property() = default;
virtual T& operator= (const T& f) { return prop = f;}
virtual const T& operator() () const { return prop;}
virtual explicit operator const T& () const { return prop;}
[[nodiscard]] T Get() const { return prop;}
T& Get() { return prop; }
void Set(const T& new_val) { prop = new_val;}
};

49
main.cpp Normal file
View File

@@ -0,0 +1,49 @@
/// Property
/// A C#-style Property, which encapsulates any type, and allows for a custom getter and setter.
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
/// Special Thanks to William Tomasine II and Maxine Hayes.
/// (c) 2024 Redacted Software
/// This work is dedicated to the public domain.
/// @file main.cpp
/// @desc Demonstration of Property class syntax and usage.
/// @edit 2024-07-30
#include <iostream>
#include <Property.hpp>
// TODO: Come up with non-contrived usage samples (i.e. how might you **actually** use this class).
// TODO: Implement ReAC::ObfusData as a derived Property.
// TODO: (Maybe borrow form above and create ObfuscatedProperty here?)
// TODO: More obfuscation techniques.
// TODO: ThreadSafeProperty
// TODO: ManagedProperty? (wraps smart pointers.)
class SampleObject
{
public:
Property<float> SimpleValue;
class : public Property<float> { public:
// TODO: Simplify custom getter and setter syntax, if at all possible.
operator float const & () const override {
/* Custom getter logic */ return prop;
}
float & operator = (const float& f) override {
/* custom setter logic */ return prop = f;
}
} CustomProp;
};
int main() {
SampleObject my_obj;
float amount = my_obj.CustomProp;
float amount2 = my_obj.SimpleValue.Get();
my_obj.CustomProp = 420.f;
my_obj.CustomProp.Get() = 69.69f;
my_obj.CustomProp.Set(666.f);
return 0;
}

View File

@@ -0,0 +1,3 @@
//
// Created by dawsh on 7/29/24.
//

3
src/Property.cpp Normal file
View File

@@ -0,0 +1,3 @@
#include <Property.hpp>