Михаил Капелько преди 6 месеца
родител
ревизия
d7fa9ec0fb
променени са 5 файла, в които са добавени 39 реда и са изтрити 37 реда
  1. +0
    -1
      v4/ctx.h
  2. +13
    -6
      v4/ctx_test2.cpp
  3. +3
    -1
      v4/gen-C++
  4. +20
    -27
      v4/memory_Context.cpp
  5. +3
    -2
      v4/memory_Context.h

+ 0
- 1
v4/ctx.h Целия файл

@@ -1,7 +1,6 @@
#include <list>
#include <queue>
#include <string>
#include "any.h"

#ifndef ctx_HEADER
#define ctx_HEADER


+ 13
- 6
v4/ctx_test2.cpp Целия файл

@@ -1,18 +1,18 @@
#include <string>
#include "ctx.h"
#include "memory_Context.h"

#include <iostream>

std::string s(const char *str) {
return std::string(str);
}

std::string ctx_test_Controller_executeFunctions_set() {
auto c = memory_createContext();
ctx_Controller<memory_Context> ctrl(c);
// Disable automatic invocation of executeFunctions.
ctrl.isProcessingQueue = true;
std::cout << "01\n";
ctrl.set("input", "123");
std::cout << "input: '" << ctrl.context.input << "'" << std::endl;
std::cout << "02\n";
ctrl.set("input", s("123"));

auto processInput = [](memory_Context c) -> memory_Context {
if (c.recentField == "input") {
@@ -29,7 +29,14 @@ std::string ctx_test_Controller_executeFunctions_set() {
ctrl.executeFunctions();
// Apply 'outputHelp'.
ctrl.executeFunctions();
std::cout << "input: '" << ctrl.context.input << "'" << std::endl;
std::cout
<< "input: '"
<< ctrl.context.input
<< "'"
<< ((ctrl.context.input == "123") ? "1" : "0")
<< " "
<< ((ctrl.context.outputHelp == "Checked") ? "1" : "0")
<< std::endl;
if (
ctrl.context.input == "123" &&
ctrl.context.outputHelp == "Checked"


+ 3
- 1
v4/gen-C++ Целия файл

@@ -1,4 +1,6 @@
c++ -o test_memory_C++ -std=c++11 -I. \
#c++ -o test_memory_C++ -std=c++11 -I. \
#c++ -o test_memory_C++ -std=c++17 -I. \
c++ -o test_memory_C++ -std=c++20 -I. \
memory.cpp \
memory_Context.cpp \
memory_test.cpp \


+ 20
- 27
v4/memory_Context.cpp Целия файл

@@ -1,10 +1,9 @@
#include <utility>
#include "any.h"
#include <any>
#include "memory_Context.h"

#include <iostream>

libany::any memory_Context::field(const std::string &fieldName) {
std::any memory_Context::field(const std::string &fieldName) {
if (fieldName == "didLaunch") {
return didLaunch;
} else if (fieldName == "exit") {
@@ -42,47 +41,41 @@ libany::any memory_Context::field(const std::string &fieldName) {
return victory;
}

void memory_Context::setField(const std::string &fieldName, libany::any value) {
void memory_Context::setField(const std::string &fieldName, std::any value) {
if (fieldName == "didLaunch") {
didLaunch = libany::any_cast<bool>(value);
didLaunch = std::any_cast<bool>(value);
} else if (fieldName == "exit") {
exit = libany::any_cast<bool>(value);
exit = std::any_cast<bool>(value);
} else if (fieldName == "hiddenItems") {
hiddenItems = libany::any_cast<std::vector<int> >(value);
hiddenItems = std::any_cast<std::vector<int> >(value);
} else if (fieldName == "input") {
std::cout << "memory_Context-01\n";
try {
input = libany::any_cast<std::string>(value);
} catch (libany::bad_any_cast &e) {
std::cout << "memory_Context-01 exception/type: " << e.what() << ", " << value.type().name() << std::endl;
}
std::cout << "memory_Context-02\n";
input = std::any_cast<std::string>(value);
} else if (fieldName == "mismatchedItems") {
mismatchedItems = libany::any_cast<std::vector<int> >(value);
mismatchedItems = std::any_cast<std::vector<int> >(value);
} else if (fieldName == "outputGoOn") {
outputGoOn = libany::any_cast<std::string>(value);
outputGoOn = std::any_cast<std::string>(value);
} else if (fieldName == "outputGreeting") {
outputGreeting = libany::any_cast<std::string>(value);
outputGreeting = std::any_cast<std::string>(value);
} else if (fieldName == "outputHelp") {
outputHelp = libany::any_cast<std::string>(value);
outputHelp = std::any_cast<std::string>(value);
} else if (fieldName == "outputMatchedItems") {
outputMatchedItems = libany::any_cast<std::string>(value);
outputMatchedItems = std::any_cast<std::string>(value);
} else if (fieldName == "outputMismatchedItems") {
outputMismatchedItems = libany::any_cast<std::string>(value);
outputMismatchedItems = std::any_cast<std::string>(value);
} else if (fieldName == "outputPromptSelection") {
outputPromptSelection = libany::any_cast<std::string>(value);
outputPromptSelection = std::any_cast<std::string>(value);
} else if (fieldName == "outputVictory") {
outputVictory = libany::any_cast<std::string>(value);
outputVictory = std::any_cast<std::string>(value);
} else if (fieldName == "playfieldItems") {
playfieldItems = libany::any_cast<std::map<int, int> >(value);
playfieldItems = std::any_cast<std::map<int, int> >(value);
} else if (fieldName == "playfieldSize") {
playfieldSize = libany::any_cast<int>(value);
playfieldSize = std::any_cast<int>(value);
} else if (fieldName == "selectedId") {
selectedId = libany::any_cast<int>(value);
selectedId = std::any_cast<int>(value);
} else if (fieldName == "selectedItems") {
selectedItems = libany::any_cast<std::vector<int> >(value);
selectedItems = std::any_cast<std::vector<int> >(value);
} else if (fieldName == "victory") {
victory = libany::any_cast<bool>(value);
victory = std::any_cast<bool>(value);
}
}



+ 3
- 2
v4/memory_Context.h Целия файл

@@ -1,3 +1,4 @@
#include <any>
#include <map>
#include <string>
#include <vector>
@@ -26,8 +27,8 @@ struct memory_Context {
std::vector<int> selectedItems;
bool victory = false;

libany::any field(const std::string &fieldName);
void setField(const std::string &fieldName, libany::any value);
std::any field(const std::string &fieldName);
void setField(const std::string &fieldName, std::any value);
};

memory_Context memory_createContext();


Loading…
Отказ
Запис