Bladeren bron

working example

sfxsfl 8 maanden geleden
bovenliggende
commit
0bff4f8f28
22 gewijzigde bestanden met toevoegingen van 158 en 175 verwijderingen
  1. BIN
      chat-GPT example/.vs/chat-GPT example/CopilotIndices/17.13.444.19527/CodeChunks.db
  2. BIN
      chat-GPT example/.vs/chat-GPT example/CopilotIndices/17.13.444.19527/SemanticSymbols.db
  3. BIN
      chat-GPT example/.vs/chat-GPT example/FileContentIndex/81748264-9c44-4c28-981b-4af18cb29a33.vsidx
  4. BIN
      chat-GPT example/.vs/chat-GPT example/FileContentIndex/a6070dc6-c722-45ea-99a0-67824f067d14.vsidx
  5. BIN
      chat-GPT example/.vs/chat-GPT example/copilot-chat/48988cf4/sessions/3b3c5cbc-2b2d-458f-8a92-2b258d874c2c
  6. BIN
      chat-GPT example/.vs/chat-GPT example/v17/.suo
  7. BIN
      chat-GPT example/.vs/chat-GPT example/v17/Browse.VC.db
  8. 3 3
      chat-GPT example/.vs/chat-GPT example/v17/DocumentLayout.backup.json
  9. 5 5
      chat-GPT example/.vs/chat-GPT example/v17/DocumentLayout.json
  10. BIN
      chat-GPT example/.vs/chat-GPT example/v17/ipch/AutoPCH/c982d1dbad2476cb/CHAT-GPT EXAMPLE.ipch
  11. 133 149
      chat-GPT example/chat-GPT example/chat-GPT example.cpp
  12. 1 0
      chat-GPT example/chat-GPT example/chat-GPT example.vcxproj
  13. 14 0
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.Build.CppClean.log
  14. BIN
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.ilk
  15. 2 18
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.log
  16. BIN
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.obj
  17. BIN
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.tlog/CL.command.1.tlog
  18. BIN
      chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.tlog/CL.read.1.tlog
  19. BIN
      chat-GPT example/chat-GPT example/x64/Debug/vc143.idb
  20. BIN
      chat-GPT example/chat-GPT example/x64/Debug/vc143.pdb
  21. BIN
      chat-GPT example/x64/Debug/chat-GPT example.exe
  22. BIN
      chat-GPT example/x64/Debug/chat-GPT example.pdb

BIN
chat-GPT example/.vs/chat-GPT example/CopilotIndices/17.13.444.19527/CodeChunks.db


BIN
chat-GPT example/.vs/chat-GPT example/CopilotIndices/17.13.444.19527/SemanticSymbols.db


BIN
chat-GPT example/.vs/chat-GPT example/FileContentIndex/81748264-9c44-4c28-981b-4af18cb29a33.vsidx


BIN
chat-GPT example/.vs/chat-GPT example/FileContentIndex/a6070dc6-c722-45ea-99a0-67824f067d14.vsidx


BIN
chat-GPT example/.vs/chat-GPT example/copilot-chat/48988cf4/sessions/3b3c5cbc-2b2d-458f-8a92-2b258d874c2c


BIN
chat-GPT example/.vs/chat-GPT example/v17/.suo


BIN
chat-GPT example/.vs/chat-GPT example/v17/Browse.VC.db


+ 3 - 3
chat-GPT example/.vs/chat-GPT example/v17/DocumentLayout.backup.json

@@ -9,11 +9,11 @@
   ],
   "DocumentGroupContainers": [
     {
-      "Orientation": 0,
+      "Orientation": 1,
       "VerticalTabListWidth": 256,
       "DocumentGroups": [
         {
-          "DockedWidth": 200,
+          "DockedHeight": 200,
           "SelectedChildIndex": 0,
           "Children": [
             {
@@ -24,7 +24,7 @@
               "RelativeDocumentMoniker": "chat-GPT example\\chat-GPT example.cpp",
               "ToolTip": "C:\\Users\\sfreunde\\source\\repos\\chat-GPT example\\chat-GPT example\\chat-GPT example.cpp*",
               "RelativeToolTip": "chat-GPT example\\chat-GPT example.cpp*",
-              "ViewState": "AgIAAJ0BAAAAAAAAAAAAAMkBAAAAAAAAAAAAAA==",
+              "ViewState": "AgIAADEAAAAAAAAAAAAYwEYAAAAQAAAAAAAAAA==",
               "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
               "WhenOpened": "2025-04-29T16:07:37.419Z",
               "EditorCaption": ""

+ 5 - 5
chat-GPT example/.vs/chat-GPT example/v17/DocumentLayout.json

@@ -9,11 +9,11 @@
   ],
   "DocumentGroupContainers": [
     {
-      "Orientation": 0,
+      "Orientation": 1,
       "VerticalTabListWidth": 256,
       "DocumentGroups": [
         {
-          "DockedWidth": 200,
+          "DockedHeight": 200,
           "SelectedChildIndex": 0,
           "Children": [
             {
@@ -22,9 +22,9 @@
               "Title": "chat-GPT example.cpp",
               "DocumentMoniker": "C:\\Users\\sfreunde\\source\\repos\\chat-GPT example\\chat-GPT example\\chat-GPT example.cpp",
               "RelativeDocumentMoniker": "chat-GPT example\\chat-GPT example.cpp",
-              "ToolTip": "C:\\Users\\sfreunde\\source\\repos\\chat-GPT example\\chat-GPT example\\chat-GPT example.cpp",
-              "RelativeToolTip": "chat-GPT example\\chat-GPT example.cpp",
-              "ViewState": "AgIAAJ0BAAAAAAAAAAAAAL8BAAA4AAAAAAAAAA==",
+              "ToolTip": "C:\\Users\\sfreunde\\source\\repos\\chat-GPT example\\chat-GPT example\\chat-GPT example.cpp*",
+              "RelativeToolTip": "chat-GPT example\\chat-GPT example.cpp*",
+              "ViewState": "AgIAADEAAAAAAAAAAAAYwEUAAAAJAAAAAAAAAA==",
               "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
               "WhenOpened": "2025-04-29T16:07:37.419Z",
               "EditorCaption": ""

BIN
chat-GPT example/.vs/chat-GPT example/v17/ipch/AutoPCH/c982d1dbad2476cb/CHAT-GPT EXAMPLE.ipch


+ 133 - 149
chat-GPT example/chat-GPT example/chat-GPT example.cpp

@@ -4,6 +4,139 @@
 #include <functional>
 #include <unordered_map>
 #include <vector>
+#include <sstream>
+#include <type_traits>
+#include <variant>
+
+
+// Enum for Event Types
+enum class EventType {
+    Click,
+    Hover,
+    KeyPress
+};
+
+// Utility function to convert various types to a string
+template <typename T>
+std::string toString(const T& value) {
+    if constexpr (std::is_same_v<T, const char*> || std::is_same_v<T, char*>) {
+        return std::string(value);
+    }
+    else if constexpr (std::is_same_v<T, bool>) {
+        return value ? "true" : "false";
+    }
+    else {
+        std::ostringstream oss;
+        oss << value;
+        return oss.str();
+    }
+}
+
+// Specialization for void
+inline std::string toString() {
+    return "void";
+}
+
+// EventManager class to manage event handlers
+class EventManager {
+public:
+
+    // Add a handler for a specific event type (void return type)
+    void addHandler(EventType type, const std::function<void()>& handler) {
+        auto& handlersForType = handlers[static_cast<int>(type)];
+        handlersForType.push_back(handler);
+    }
+
+    // Add a handler for a specific event type (non-void return type)
+// Add a handler for a specific event type
+    template <typename ReturnType>
+    void addHandler(EventType type, const std::function<ReturnType()>& handler) {
+        auto& handlersForType = handlers[static_cast<int>(type)];
+        handlersForType.push_back(handler);
+    }
+
+
+    // Emit an event of a specific type
+    template <typename ReturnType, typename = typename std::enable_if<!std::is_same<ReturnType, void>::value>::type>
+    ReturnType emit(EventType type) {
+        auto it = handlers.find(static_cast<int>(type));
+        if (it != handlers.end()) {
+            for (const auto& callback : it->second) {
+                // Check the type of the callback and invoke it
+                if (auto func = std::get_if<std::function<ReturnType()>>(&callback)) {
+                    return (*func)(); // Call the callback and return the result
+                }
+            }
+        }
+    }
+
+    // Emit an event of a specific type
+    void emit(EventType type) {
+        auto it = handlers.find(static_cast<int>(type));
+        if (it != handlers.end()) {
+            for (const auto& callback : it->second) {
+                // Check the type of the callback and invoke it
+                if (auto func = std::get_if<std::function<void()>>(&callback)) {
+                    (*func)(); // Call the callback and return the result
+                }
+            }
+        }
+        return; // Explicit return for clarity
+    }
+
+
+private:
+
+    // Define a variant type for supported callback return types
+    using CallbackVariant = std::variant<
+        std::function<void()>,
+        std::function<int()>,
+        std::function<bool()>,
+        std::function<std::string()>,
+        std::function<const char* ()>>;
+
+    // Update the handlers map to use the variant
+    std::unordered_map<int, std::vector<CallbackVariant>> handlers;
+    // std::unordered_map<int, std::vector<std::function<std::string()>>> handlers; // Map of event type to handlers
+
+};
+
+int main() {
+    EventManager eventManager;
+
+    // Add handlers for different event types with various return types
+    eventManager.addHandler(EventType::Click, []() {
+        std::cout << "Click event triggered!" << std::endl;
+        });
+
+    eventManager.addHandler<const char*>(EventType::Hover, []() -> const char* {
+        return "Hover event triggered!";
+        });
+
+    eventManager.addHandler<bool>(EventType::KeyPress, []() -> bool {
+        return true;
+        });
+
+    eventManager.addHandler<int>(EventType::Click, []() -> int {
+        return 42;
+        });
+
+    // Emit events
+    std::cout << "Emitting Click event:" << std::endl;
+    eventManager.emit(EventType::Click);
+
+    std::cout << "Emitting Hover event:" << std::endl;
+    // eventManager.emit<const char*>(EventType::Hover);
+    const char* hoverResult = eventManager.emit<const char*>(EventType::Hover);
+    std::cout << "Hover event result: " << hoverResult << std::endl;
+
+    std::cout << "Emitting KeyPress event:" << std::endl;
+    bool KeyPressResult = eventManager.emit<bool>(EventType::KeyPress);
+    std::cout << "KeyPress event result: " << KeyPressResult << std::endl;
+
+    return 0;
+}
+
 
 #if 0
 
@@ -306,152 +439,3 @@ int main() {
 
 #endif
 
-
-#include <iostream>
-#include <functional>
-#include <unordered_map>
-#include <vector>
-#include <sstream>
-#include <type_traits>
-
-// Enum for Event Types
-enum class EventType {
-    Click,
-    Hover,
-    KeyPress
-};
-
-// Utility function to convert various types to a string
-template <typename T>
-std::string toString(const T& value) {
-    if constexpr (std::is_same_v<T, const char*> || std::is_same_v<T, char*>) {
-        return std::string(value);
-    }
-    else if constexpr (std::is_same_v<T, bool>) {
-        return value ? "true" : "false";
-    }
-    else {
-        std::ostringstream oss;
-        oss << value;
-        return oss.str();
-    }
-}
-
-// Specialization for void
-inline std::string toString() {
-    return "void";
-}
-
-// EventManager class to manage event handlers
-class EventManager {
-public:
-
-    // Add a handler for a specific event type (void return type)
-    void addHandler(EventType type, const std::function<void()>& handler) {
-        auto& handlersForType = handlers[static_cast<int>(type)];
-        handlersForType.push_back([handler]() ->std::string {
-            handler();
-            return "";
-            });
-    }
-
-    // Add a handler for a specific event type (non-void return type)
-    template <typename ReturnType >
-    void addHandler(EventType type, const std::function<ReturnType()>& handler) {
-        auto& handlersForType = handlers[static_cast<int>(type)];
-        handlersForType.push_back([handler]() -> std::string {
-            ReturnType result = handler(); // Call the handler
-            return toString(result);
-            });
-    }
-
-
-    // Emit an event of a specific type
-    template <typename ReturnType, typename = typename std::enable_if<!std::is_same<ReturnType, void>::value>::type>
-    ReturnType emit(EventType type) {
-        auto it = handlers.find(static_cast<int>(type));
-        if (it != handlers.end()) {
-            for (const auto& handler : it->second) {
-                std::string result = handler(); // Call each handler and get the result
-                auto handlerResult = handler(); // Call each handler and get the result
-                // ReturnType result = handler(); // Call each handler and get the result
-
-            // Convert handlerResult to ReturnType if necessary
-                if constexpr (std::is_same<ReturnType, const char*>::value) {
-                    // Convert std::string to const char*
-                    return static_cast<ReturnType>(handlerResult.c_str());
-                }
-                else if constexpr (std::is_same<ReturnType, std::string>::value) {
-                    return static_cast<ReturnType>(handlerResult);
-                }
-                else if constexpr (std::is_same<ReturnType, int>::value) {
-                    return static_cast<ReturnType>(std::stoi(handlerResult));
-                }
-                else if constexpr (std::is_same<ReturnType, bool>::value) {
-                    return static_cast<ReturnType>(handlerResult == "true");
-                }
-                else {
-                    throw std::runtime_error("Unsupported ReturnType");
-                }
-            }
-
-        }
-
-        // Return default value for non-void types if no handler is found
-        if (!std::is_same<ReturnType, void>::value) {
-            return ReturnType();
-        }
-    }
-
-    // Emit an event of a specific type
-// Emit an event of a specific type
-    void emit(EventType type) {
-        auto it = handlers.find(static_cast<int>(type));
-        if (it != handlers.end()) {
-            for (const auto& handler : it->second) {
-                handler(); // Call each handler
-            }
-        }
-        return; // Explicit return for clarity
-    }
-
-
-private:
-    std::unordered_map<int, std::vector<std::function<std::string()>>> handlers; // Map of event type to handlers
-};
-
-int main() {
-    EventManager eventManager;
-
-    // Add handlers for different event types with various return types
-    eventManager.addHandler(EventType::Click, []() {
-        std::cout << "Click event triggered!" << std::endl;
-        });
-
-    eventManager.addHandler<const char*>(EventType::Hover, []() -> const char* {
-        return "Hover event triggered!";
-        });
-
-    eventManager.addHandler<bool>(EventType::KeyPress, []() -> bool {
-        return true;
-        });
-
-    eventManager.addHandler<int>(EventType::Click, []() -> int {
-        return 42;
-        });
-
-    // Emit events
-    std::cout << "Emitting Click event:" << std::endl;
-    eventManager.emit(EventType::Click);
-
-    std::cout << "Emitting Hover event:" << std::endl;
-    // eventManager.emit<const char*>(EventType::Hover);
-    const char* hoverResult = eventManager.emit<const char*>(EventType::Hover);
-    std::cout << "Hover event result: " << hoverResult << std::endl;
-
-    std::cout << "Emitting KeyPress event:" << std::endl;
-    eventManager.emit<bool>(EventType::KeyPress);
-
-    return 0;
-}
-

+ 1 - 0
chat-GPT example/chat-GPT example/chat-GPT example.vcxproj

@@ -104,6 +104,7 @@
       <SDLCheck>true</SDLCheck>
       <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <ConformanceMode>true</ConformanceMode>
+      <LanguageStandard>stdcpp17</LanguageStandard>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>

+ 14 - 0
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.Build.CppClean.log

@@ -0,0 +1,14 @@
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\vc143.pdb
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\vc143.idb
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.obj
+c:\users\sfreunde\source\repos\chat-gpt example\x64\debug\chat-gpt example.exe
+c:\users\sfreunde\source\repos\chat-gpt example\x64\debug\chat-gpt example.pdb
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.ilk
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\cl.command.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\cl.items.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\cl.read.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\cl.write.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\link.command.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\link.read.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\link.secondary.1.tlog
+c:\users\sfreunde\source\repos\chat-gpt example\chat-gpt example\x64\debug\chat-gpt example.tlog\link.write.1.tlog

BIN
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.ilk


+ 2 - 18
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.log

@@ -1,20 +1,4 @@
   chat-GPT example.cpp
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(327,5): warning C4984: 'if constexpr' is a C++17 language extension
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(330,10): warning C4984: 'if constexpr' is a C++17 language extension
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(380,17): warning C4984: 'if constexpr' is a C++17 language extension
-      C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(371,16):
-      This diagnostic occurred in the compiler generated function 'ReturnType EventManager::emit(EventType)'
-  
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(384,22): warning C4984: 'if constexpr' is a C++17 language extension
-      C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(371,16):
-      This diagnostic occurred in the compiler generated function 'ReturnType EventManager::emit(EventType)'
-  
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(387,22): warning C4984: 'if constexpr' is a C++17 language extension
-      C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(371,16):
-      This diagnostic occurred in the compiler generated function 'ReturnType EventManager::emit(EventType)'
-  
-C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(390,22): warning C4984: 'if constexpr' is a C++17 language extension
-      C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(371,16):
-      This diagnostic occurred in the compiler generated function 'ReturnType EventManager::emit(EventType)'
-  
+C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(71,1): warning C4715: 'EventManager::emit<char const *,void>': not all control paths return a value
+C:\Users\sfreunde\source\repos\chat-GPT example\chat-GPT example\chat-GPT example.cpp(71,1): warning C4715: 'EventManager::emit<bool,void>': not all control paths return a value
   chat-GPT example.vcxproj -> C:\Users\sfreunde\source\repos\chat-GPT example\x64\Debug\chat-GPT example.exe

BIN
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.obj


BIN
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.tlog/CL.command.1.tlog


BIN
chat-GPT example/chat-GPT example/x64/Debug/chat-GPT example.tlog/CL.read.1.tlog


BIN
chat-GPT example/chat-GPT example/x64/Debug/vc143.idb


BIN
chat-GPT example/chat-GPT example/x64/Debug/vc143.pdb


BIN
chat-GPT example/x64/Debug/chat-GPT example.exe


BIN
chat-GPT example/x64/Debug/chat-GPT example.pdb