diff --git a/DataTypes.cpp b/DataTypes.cpp new file mode 100644 index 0000000..be35151 --- /dev/null +++ b/DataTypes.cpp @@ -0,0 +1,518 @@ +/* +DataTypes.cpp : This file contains supplemental generic data types. + +author: Edward Middleton-Smith + +project: Shared +technology: Libraries +feature: Data Types +*/ + +// COMMENTS: +// METHODS + // FUNCTION + // VARIABLE DECLARATION + INSTANTIATION + // ARGUMENT VALIDATION + // METHODS + // RETURNS +// CLASS METHODS: + // FUNCTION + // VARIABLE & ATTRIBUTE DECLARATION + INSTANTIATION + // ARGUMENT VALIDATION + // METHODS + // RETURNS + +// INCLUDES +// internal +// #include "pch.h" +#include "DataTypes.h" + +// Templates +template +std::ostream& operator<<(std::ostream& os, T& v) { + os << v.ToString(); + return os; +} +template +std::ostream& operator<<(std::ostream& os, std::vector& vec) { + return printVector(os, vec); +} +template +std::ostream& operator<<(std::ostream& os, FastList& vec) { + os << vec.ToString(); + return os; +} +/* +template +std::ostream& operator<<(std::ostream& os, const std::vector>& vec) +{ + return printVector(os, vec); +} +*/ +// Base case: Overload for a 1-dimensional vector +template +std::ostream& printVector(std::ostream& os, std::vector& vec) { + os << "["; + for (size_t i = 0; i < vec.size(); ++i) { + os << vec[i]; + // printVector(os, vec[i]); + if (i < vec.size() - 1) { + os << ", "; + } + } + os << "]"; + return os; +} +// Recursive case: Overload for n-dimensional vectors +template +std::ostream& printVector(std::ostream& os, std::vector< std::vector>& vec) { + os << "["; + for (size_t i = 0; i < vec.size(); ++i) { + // Recursively call the printVector function for sub-vectors + // os << printVector(vec[i]); + // os << printVector(vec.at(i)); + printVector(os, vec[i]); + if (i < vec.size() - 1) { + os << ", "; + } + } + os << "]"; + return os; +} + +// LinkedListNode + +// LinkedList + +// + +library123::enumPlusPlusItem::enumPlusPlusItem(std::string name, int index) : name(name), index(index) { }; +std::string library123::enumPlusPlusItem::Name() { return this->name; }; +int library123::enumPlusPlusItem::Index() { return this->index; }; +std::string library123::enumPlusPlusItem::to_string() +{ + return std::format("Name: {}, Value: {}", this->name, this->index); +} +library123::enumPlusPlus::enumPlusPlus(std::vector enumNames, int iStart) +{ + // FUNCTION + // Constructor for enumPlusPlus + // ARGUMENT VALIDATION + if (enumNames.size() == 0) { library123::ArgVal::ThrowError("Error: no names provided to enum.", true); }; + // ATTRIBUTE DECLARATION + INSTANTIATION + this->iStart = iStart; + this->enums = std::vector(); // {}; + // METHODS + for (int i = iStart; i < iStart + enumNames.size(); i++) + { + this->enums.push_back(enumPlusPlusItem(enumNames.at(i), i)); + } +} +std::string library123::enumPlusPlus::to_string() +{ + // FUNCTION + // Convert enumPlusPlus object to string representation + // VARIABLE DECLARATION + INSTANTIATION + std::ostringstream oss; + oss << "["; + int sz = this->Size(); + // METHODS + if (sz > 0) + { + for (int i = 0; i < sz; i++) + { + oss << ((i == 0) ? "" : ", ") << this->enums.at(i).to_string(); + } + } + oss << "]"; + // RETURNS + return oss.str(); +} +int library123::enumPlusPlus::IStart() { return this->iStart; }; +int library123::enumPlusPlus::Size() { return this->enums.size(); }; +library123::enumPlusPlusItem library123::enumPlusPlus::GetBy(int index, bool suppressErrors) +{ + // FUNCTION + // Get enumPlusPlusItem by index + // ARGUMENT VALIDATION + if (index < 0 || index >= this->Size()) + { + library123::ArgVal::ThrowError("Error: Invalid index.", suppressErrors); + return library123::enumPlusPlusItem("Error", 0); + } + // RETURNS + return this->enums.at(index); +} +library123::enumPlusPlusItem library123::enumPlusPlus::GetBy(std::string name, bool suppressErrors) +{ + // FUNCTION + // Find enumPlusPlusItem by name + // VARIABLE DECLARATION + INSTANTIATION + int sz = this->Size(); + // ARGUMENT VALIDATION + if (sz == 0) + { + library123::ArgVal::ThrowError("Error: Invalid index.", suppressErrors); + return library123::enumPlusPlusItem("Error", 0); + } + // METHODS + for (int i = 0; i < sz; i++) + { + library123::enumPlusPlusItem item = this->enums.at(i); + if (item.Name() == name) + { + return item; + } + } + // RETURNS + library123::ArgVal::ThrowError("Error: enumPlusPlusItem not found by name.", suppressErrors); + return library123::enumPlusPlusItem("Error", 0); +} + + +template +bool library123::ArgVal::IsString(const W& value) +{ + return std::is_same::value || std::is_same::value; +} + +/* +template +typename std::enable_if::value, void>::type +std::string ToString(const W& arg) +{ + // method 0 + if (HasMethodToString::value) { return arg.to_string(); }; + + // method 1: fail + // return std::to_string(value); + + // method 2 + std::ostream oss; + oss << arg; + return oss.str(); +} +*/ +/* +template +std::string library123::ArgVal::ToString(S s) +{ + return std::to_string(s); +} +template +std::string library123::ArgVal::ToString(std::vector s) +{ + // method 2 + std::ostream oss; + int sz = s.size(); + oss << "["; + for (int i = 0; i < sz; i++) + { + oss << library123::ArgVal::ToString(s.at(i)); + if (i < sz - 1) { oss << ", "; }; + } + oss << "]"; + return oss.str(); +} +*/ + +/* +template +std::string library123::ArgVal::ToString(const W& arg) +{ + // method 0 + if (HasMethodToString::value) { return arg.to_string(); }; + + // method 1: fail + // return std::to_string(value); + + // method 2 + std::ostream oss; + oss << arg; + return oss.str(); +} + +template +std::string library123::ArgVal::ToString(const std::vector& value) +{ + + // method 2 + std::ostream oss; + int sz = value.size(); + oss << "["; + for (int i = 0; i < sz; i++) + { + oss << library123::ArgVal::ToString(value.at(i)); + if (i < sz - 1) { oss << ", "; }; + } + oss << "]"; + return oss.str(); +} +*/ +template +Y library123::ArgVal::ExtractValue(const Y& arg) +{ + if (std::is_pointer::value) { return *arg; }; + return arg; +} + +template +std::string library123::ArgVal::ErrorHole(const std::vector& v) +{ + return ""; +} + +template +std::string library123::ArgVal::ErrorHole2(const std::vector& v1, const std::vector& v2) +{ + return ""; +} + +/* +template +std::string library123::ArgVal::ErrorMessage(T name, U var, V typeExpected0, V valueExpected, int sizeExpected, bool attrNotVar) +{ + return std::string(""); +} +*/ + + +template +std::string library123::ArgVal::ErrorMessage(std::string varName, std::string funcName, T& var, std::string typeExpected, U& valueExpected, bool attrNotVar) +{ + // FUNCTION + // Generate error message string + // VARIABLE DECLARATION + // VARIABLE INSTANTIATION + std::string attrVar = attrNotVar ? "attribute" : "variable"; + std::string type = typeid(var).name(); + std::ostringstream ret; + // METHODS + // type name + size_t found = type.find("["); + std::string typeName = type.substr(0, found - 1); + size_t foundExpected = typeExpected.find("["); + std::string typeNameExpected = typeExpected.substr(0, foundExpected - 1); + if (typeName != typeNameExpected) + { + // return std::format("Error: Invalid {} {} {} data type.\nMethod: {}\nActual type: {}", typeNameExpected, attrVar, varName, funcName, typeName); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << " data type.\nMethod: " << funcName << "\nActual type: " << typeName; + return ret.str(); + } + // value - default +// RETURNS + // return std::format("Error: Invalid {} {} {}{}.\nMethod: {}Expected: {}.\nActual: {}.", typeNameExpected, attrVar, varName, (var == valueExpected) ? "" : " value", funcName, valueExpected, var); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << (var == valueExpected ? "" : " value") << ".\nMethod: " << funcName << "\nExpected: " << valueExpected << "\nActual: " << var; + return ret.str(); +} + +template +std::string library123::ArgVal::ErrorMessage(std::string varName, std::string funcName, std::vector& var, std::string typeExpected, std::vector& valueExpected, bool attrNotVar) +{ + // FUNCTION + // Generate error message string + // VARIABLE DECLARATION + // VARIABLE INSTANTIATION + std::string attrVar = attrNotVar ? "attribute" : "variable"; + std::string type = typeid(var).name(); + std::ostringstream ret; + // METHODS + // type name + size_t found = type.find("["); + std::string typeName = type.substr(0, found - 1); + size_t foundExpected = typeExpected.find("["); + std::string typeNameExpected = typeExpected.substr(0, foundExpected - 1); + if (typeName != typeNameExpected) + { + // return std::format("Error: Invalid {} {} {} data type.\nMethod: {}\nActual type: {}", typeNameExpected, attrVar, varName, funcName, typeName); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << " data type.\nMethod: " << funcName << "\nActual type: " << typeName; + return ret.str(); + } + // RETURNS + // return std::format("Error: Invalid {} {} {}{}.\nMethod: {}Expected: {}.\nActual: {}.", typeNameExpected, attrVar, varName, " value", funcName, valueExpectedStr, valueActualStr); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << (var == valueExpected ? "" : " value") << ".\nMethod: " << funcName << "\nExpected: "; + ret << valueExpected; + ret << "\nActual: "; + ret << var; + return ret.str(); +} + +template +std::string library123::ArgVal::ErrorMessage(std::string varName, std::string funcName, const FastList& var, std::string typeExpected, const FastList& valueExpected, bool attrNotVar) +{ + // FUNCTION + // Generate error message string + // VARIABLE DECLARATION + // VARIABLE INSTANTIATION + std::string attrVar = attrNotVar ? "attribute" : "variable"; + std::string type = typeid(var).name(); + std::ostringstream ret; + // METHODS + // type name + size_t found = type.find("["); + std::string typeName = type.substr(0, found - 1); + size_t foundExpected = typeExpected.find("["); + std::string typeNameExpected = typeExpected.substr(0, foundExpected - 1); + if (typeName != typeNameExpected) + { + // return std::format("Error: Invalid {} {} {} data type.\nMethod: {}\nActual type: {}", typeNameExpected, attrVar, varName, funcName, typeName); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << " data type.\nMethod: " << funcName << "\nActual type: " << typeName; + return ret.str(); + } + // RETURNS + // return std::format("Error: Invalid {} {} {}{}.\nMethod: {}Expected: {}.\nActual: {}.", typeNameExpected, attrVar, varName, " value", funcName, valueExpectedStr, valueActualStr); + ret << "Error: Invalid " << typeNameExpected << " " << attrVar << " " << varName << (var == valueExpected ? "" : " value") << ".\nMethod: " << funcName << "\nExpected: "; + /* + ret << valueExpected; + ret << "\nActual: "; + ret << var; + */ + ret << valueExpected << "\nActual: " << var; + return ret.str(); +} + +void library123::ArgVal::ThrowError(std::string errorMsg, bool raiseNotThrow) +{ +// FUNCTION +// Report error to console and break programme where necessary +// RETURNS + std::cerr << errorMsg << std::endl; + if (!raiseNotThrow) { throw std::runtime_error(""); } + return; +} + +int library123::ArgVal::main() +{ + std::string fName = "ArgumentValidation\\library123::ArgVal::main"; + int var = 69; + int val = 6; + std::string name = "v0"; + std::string typeExpected = typeid(val).name(); + std::string err_msg = library123::ArgVal::ErrorMessage(name, fName, var, typeExpected, val); + std::cerr << err_msg << std::endl; + err_msg = library123::ArgVal::ErrorMessage("name", fName, var, typeExpected, val); + std::cerr << err_msg << std::endl; + std::vector v0 = { 0.0, 1.0, 2.0 }; + std::vector v1 = { 0, 1, 3 }; + std::vector> v2(3, std::vector(2, 0)); // = { v0; v0; v0 }; + std::vector>> v3(3, std::vector>(3, std::vector(3, 0))); // = { v0; v0; v0 }; + std::vector>>>> v5(5, std::vector>>>(5, std::vector>>(5, std::vector>(5, std::vector(5, 0))))); // = { v0; v0; v0 }; + std::cout << library123::ArgVal::ErrorHole2(v0, v1) << std::endl; + typeExpected = typeid(v2).name(); + std::cout << "type expected: " << typeExpected << std::endl; + err_msg = library123::ArgVal::ErrorMessage(name, fName, v0, typeExpected, v1); + // std::string valueActualStr = library123::ArgVal::ToString(var); + // err_msg = library123::ArgVal::ErrorHole(v0); + std::cerr << err_msg << std::endl; + err_msg = library123::ArgVal::ErrorMessage("v2", fName, v2, typeExpected, v2); + std::cerr << err_msg << std::endl; + err_msg = library123::ArgVal::ErrorMessage("v5", fName, v5, typeExpected, v5); + std::cerr << err_msg << std::endl; + // valueActualStr = library123::ArgVal::ToString(v2); + /* + std::ostream o0; + o0 << v0; + std::cerr << o0.str() << std::endl; + std::ostream o1; + o1 << v2; + std::cerr << o1.str() << std::endl; + std::ostream o2; + o2 << v3; + std::cerr << o2.str() << std::endl; + std::ostream o3; + o3 << v5; + std::cerr << o3.str() << std::endl; + + // throw std::runtime_error(err_msg); + // std::string sName = var.tostring(); + int nEWoman = sizeof(eWoman); // / sizeof(static_cast(0)); + std::cout << "nEWoman = " << nEWoman << std::endl; + for (int i = 0; i < nEWoman; i++) + { + eWoman ew = static_cast(i); + std::cout << std::to_string(ew) << std::endl; + } + // enumPlusPlus + enumPlusPlus eWoman2 = enumPlusPlus({ "" }); + std::cout << eWoman2.to_string() << std::endl; + enumPlusPlus eWoman3 = enumPlusPlus({ "but cheese", "nipple stains"}); + std::cout << eWoman3.to_string() << std::endl; + std::cout << eWoman3.GetBy("but cheese").Name() << std::endl; + */ + return 0; +} +enum etest +{ + _1, + _2, + _3 +}; +struct stest +{ + int id; + std::string name; + etest eTest; + stest(int id, std::string name, etest eTest) : id(id), name(name), eTest(eTest) {}; +}; + +int main() +{ + // test nullptrs + int* test = nullptr; + std::cout << (!test) << std::endl; + std::cout << (true) << std::endl; + // test enums + PointerType p = PointerType(NEXT); + std::cout << p << std::endl; + p = PointerType(PREVIOUS); + std::cout << p << std::endl; + std::cout << p << std::endl; + // test std::Vector + std::vector ai = { 1, 2, 3 }; + // std::cout << "ai: " << ai[-1] << " " << ai[-2] << std::endl; // error - negative indices not allowed + // test FastList::Default + FastList tmp = FastList::Default(5, 69); + std::ostringstream oss; + oss << tmp; + std::cout << oss.str() << std::endl; + // test FastList ToString + library123::test_1 test2 = library123::test_1(); // test1:: + FastList vt1 = FastList::Default(10, test2); + std::cout << test2.ToString() << std::endl; + oss = std::ostringstream(); + oss << vt1; + std::cout << oss.str() << std::endl; + int test_3 = tmp[3]; + std::cout << "test_3 = " << test_3 << std::endl; + library123::test_1 test_4 = vt1[7]; + std::cout << "test_4 = " << test_4.ToString() << std::endl; + // test duplicate FastList + FastList vt2 = vt1; + // vt2.Copy(vt1); + vt1.Remove(0); + // std::cout << "vt2 = " << vt2.ToString() << std::endl; // fail + // test struct to string + /* + stest tester = stest(1, "nudes", etest::_3); + std::cout << tester << std::endl; + oss = std::ostream(); + oss << tester; + std::cout << oss.str() << std::endl; + */ + // test date + std::time_t nowtime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + std::cout << "nowtime = " << nowtime << std::endl; + // test int 2 + int quantity = (nowtime % 2 == 0) ? 9 : 19; + std::vector nugs; + for (int i = 0; i < quantity; i++) + { + nugs.push_back(i); + } + oss = std::ostringstream(); + oss << "nugs = "; + oss << nugs; + std::cout << oss.str() << std::endl; + const int pi = 3; + return 0; +} \ No newline at end of file diff --git a/DataTypes.h b/DataTypes.h new file mode 100644 index 0000000..8c3e3cf --- /dev/null +++ b/DataTypes.h @@ -0,0 +1,569 @@ +#pragma once +/* +card.h : This is the header file for DataTypes.cpp + +author: Edward Middleton-Smith + +project: Shared +technology: Libraries +feature: Data Types header file +*/ + +#ifndef DATA_TYPES_H +#define DATA_TYPES_H + +// IMPORTS +// internal +// #include +// external +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// TEMPLATE OBJECTS +template +concept Stringable = requires(W w) +{ + { std::to_string(w) } -> std::convertible_to; +} || + requires(W w) +{ + { w } -> std::convertible_to; +} || + requires(W w) +{ + { w.ToString() } -> std::convertible_to; +}; +template +concept HasToString = requires(W w) +{ + { w.ToString() } -> std::convertible_to; +}; + +template +class FastList +{ +public: + FastList() {}; + void PushBack(T item) + { + this->aList.push_back(item); + this->index.push_back(std::prev(this->aList.end())); + } + // T* GetItem(int index) + // std::list::iterator GetItem(int index) + const T& operator[](std::size_t i) const + { + return *index[i]; + // method 1 + /* + int szList = this->index.size(); + if (szList == 0) { return nullptr; }; + index = std::max(0, std::min(szList - 1, index)); + return this->index[index]; + */ + } + T& operator[](std::size_t i) + { + return *index[i]; + } + /* + FastList& operator=(FastList original) + { + // if (this == &original) { return *this; } + size_t n = original.Size(); + FastList duplicate; + this.aList = duplicate.aList; + this.index = duplicate.index; + if (n == 0) { return duplicate; } + for (size_t i = 0; i < n; i++) + { + this->PushBack(original[i]); + } + return &this; + } + */ + void Copy(FastList original) + { + size_t n = original.Size(); + FastList duplicate; + this->aList = std::list(); + this->index = std::vector::iterator>(); + /* + this->aList = duplicate->aList; + this->index = duplicate->index; + */ + if (n == 0) { return; } + for (size_t i = 0; i < n; i++) + { + this->PushBack(original[i]); + } + } + void Insert(T item, int i) + { + int szList = this->index.size(); + i = std::max(0, std::min(szList - 1, i)); + // std::list::iterator middle = std::next(this->aList.begin(), index); + auto middle = std::next(this->aList.begin(), i); + this->aList.insert(middle, item); + this->index.insert(i, item); + } + void Remove(int i) + { + int szList = this->index.size(); + if (i < -szList || i >= szList) { return; }; + if (i < 0) + { + i = szList + i; + } + // std::list::iterator middle = std::next(this->aList.begin(), index); + auto middle = std::next(this->aList.begin(), i); + this->aList.erase(middle); + // this->index.erase(i); + // this->index.erase() + } + std::string ToString() + { + std::ostringstream oss; + oss << "FastList" << std::endl; + int szList = this->index.size(); + if (szList > 0) + { + oss << "Items:" << std::endl; + for (int i = 0; i < szList; i++) + { + // oss << &this->GetItem(i) << std::endl; + oss << *index[i] << std::endl; + } + } + return oss.str(); + } + void Swap(int i1, int i2) + { + int nCard = this->index.size(); + i1 = std::min(std::max(0, i1), nCard); + i2 = std::min(std::max(0, i2), nCard); + // std::swap(this->aList[i1], this->aList[i2]); + // std::swap(this->index[i1], this->index[i2]); + // std::list tmpList; + // std::vector::iterator> tmpI; + // std::list::iterator tmpI = this->index.at(i1); + /* + T* tmp1 = this->GetItem(i1); + T* tmp2 = this->GetItem(i2); + */ + T tmp1 = *this->index[i1]; + T tmp2 = *this->index[i2]; + this->Remove(i1); + this->Insert(tmp2, i1); + this->Remove(i2); + this->Insert(tmp1, i2); + } + std::size_t Size() const + { + return this->index.size(); + } + // std::vector::iterator> Index() + auto Index() + { + return this->index; + } + bool operator==(FastList fl2) + { + int n1 = this->Size(); + int n2 = fl2.Size(); + if (n1 != n2) { return false; } + for (int i = 0; i < n1; i++) + { + if (this[i] != fl2[i]) { return false; } + } + return true; + } + // std::vector::iterator> index; + static FastList Default(int nElem, T vDefault) + { + nElem = std::max(0, nElem); + FastList v; + if (nElem > 0) + { + for (int i = 0; i < nElem; i++) + { + v.PushBack(vDefault); + } + } + return v; + } +private: + std::list aList; + std::vector::iterator> index; +}; + + +// Base case +template +std::ostream& operator<<(std::ostream& os, std::vector& vec); +template +std::ostream& operator<<(std::ostream& os, FastList& vec); +/* +template +std::ostream& operator<<(std::ostream& os, const std::vector>& vec); +*/ +// Base case: Overload for a 0-dimensional vector element +template +std::ostream& printVector(std::ostream& os, T& var) { + os << var; + return os; +} +// Base case: Overload for a 1-dimensional vector +template +std::ostream& printVector(std::ostream& os, std::vector& vec); +// Recursive case: Overload for n-dimensional vectors +template +std::ostream& printVector(std::ostream& os, std::vector< std::vector>& vec); + +// Overload the equality operator (==) for std::vector +template +bool areVectorsEqual(const std::vector& v1, const std::vector& v2) { return false; } +template +bool areVectorsEqual(const std::vector& v1, const std::vector& v2) +{ + if (v1.size() != v2.size()) + { + return false; // Vectors have different sizes, so they can't be equal. + } + for (size_t i = 0; i < v1.size(); ++i) + { + auto i1 = v1[i]; + auto i2 = v2[i]; + if (!(i1 == i2)) + // if (!(v1[i] == v2[i])) + // if (!(v1.at(i) == v2.at(i))) + { + return false; // Elements at the same index are different, so vectors are not equal. + } + } + return true; // All elements are equal, so vectors are equal. +} +template +bool areVectorsEqual(const std::vector>& v1, const std::vector>& v2) +{ + if (v1.size() != v2.size()) + { + return false; // Vectors have different sizes, so they can't be equal. + } + for (size_t i = 0; i < v1.size(); ++i) + { + /* + auto i1 = v1[i]; + auto i2 = v2[i]; + if (!(i1 == i2)) + */ + if (!areVectorsEqual(v1[i], v2[i])) + // if (!(v1[i] == v2[i])) + // if (!(v1.at(i) == v2.at(i))) + { + return false; // Elements at the same index are different, so vectors are not equal. + } + } + return true; // All elements are equal, so vectors are equal. +} +template +bool operator==(const std::vector& v1, const std::vector& v2) +{ + return areVectorsEqual(v1, v2); +} +template +bool operator==(const std::vector>& v1, const std::vector>& v2) +{ + return areVectorsEqual(v1, v2); +} +template +bool operator==(const std::vector& v1, const std::vector& v2) +{ + return false; +} + + +enum PointerType +{ + NEXT, + PREVIOUS +}; + + +template +class LinkedListNode +{ +public: + LinkedListNode(T node, T* nodeNext, T* nodePrev) + { + this->node = node; + this->nodeNext = nodeNext; + this->nodePrev = nodePrev; + } + void SetNode(T node) + { + this->node = node; + } + void SetPointer(T* ptr, PointerType ptrType) + { + if (ptrType == PointerType(NEXT)) + { + this->nodeNext = ptrType; + } + else + { + this->nodePrev = ptrType; + } + } + LinkedListNode* GetPointer(PointerType ptrType) + { + if (ptrType == PointerType(NEXT)) + { + return &this->nodeNext; + } + else + { + return &this->nodePrev; + } + } +private: + T node; + T* nodeNext; + T* nodePrev; +}; + + +//template +//class LinkedList +//{ +//public: +// LinkedList() : head(nullptr), tail(nullptr) {}; +// LinkedList(LinkedListNode* head) : head(head) {}; +// void PushBack(T node) +// { +// if (!head) +// { +// this->head = &node; +// this->tail = &node; +// this->length++; +// return; +// } +// if (typeid(head) != typeid(node)) +// { +// lib::ArgVal::ThrowError(lib::ArgVal::ErrorMessage("node", "LinkedList.PushBack", node, typeid(head).name(), tail, true)); +// } +// this->tail->SetPointer(&node, PointerType(NEXT)); +// this->tail = &node; +// this->length++; +// return; +// } +// void Insert(T node, int index) +// { +// if (!head) +// { +// this->head = &node; +// this->tail = &node; +// this->length++; +// return; +// } +// if (typeid(head) != typeid(node)) +// { +// lib::ArgVal::ThrowError(lib::ArgVal::ErrorMessage("node", "LinkedList.Insert", node, typeid(head).name(), tail, true)); +// } +// if (index <= 0) +// { +// this->head->SetPointer(&node, PointerType(PREVIOUS)); +// this->head = &node; +// this->length++; +// return; +// } +// if (index >= this->length) +// { +// this->tail->SetPointer(&node, PointerType(NEXT)); +// this->tail = &node; +// this->length++; +// return; +// } +// LinkedListNode nodeNext = *this->head; +// LinkedListNode nodePrev; +// for (int n = 1; n < index; n++) +// { +// nodePrev = nodeNext; +// nodeNext = *nodePrev->GetPointer(PointerType(NEXT)); +// } +// nodePrev.SetPointer(&node, PointerType(NEXT)); +// nodeNext.SetPointer(&node, PointerType(PREVIOUS)); +// this->length++; +// } +//private: +// LinkedListNode* head; +// LinkedListNode* tail; +// int length = 0; +//}; + + +// NAMESPACE OBJECTS +namespace library123 +{ + struct enumPlusPlusItem + { + public: + enumPlusPlusItem(std::string name, int index); + std::string Name(); + int Index(); + std::string to_string(); + private: + std::string name; + int index; + }; + struct enumPlusPlus + { + public: + enumPlusPlus(std::vector enumNames, int iStart = 0); // , std::string name = "" + std::string to_string(); + int IStart(); + int Size(); + enumPlusPlusItem GetBy(int index, bool suppressErrors = false); + enumPlusPlusItem GetBy(std::string name, bool suppressErrors = false); + private: + std::string name; + std::vector enums; + int iStart; + }; + enum eWoman + { + NIPPLE, + VAGINA, + BREAST + }; + // template + static class ArgVal // + { + public: + template + static bool IsString(const W& value); + /* + template + struct IsAllowedType : std::false_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + template <> + struct IsAllowedType : std::true_type {}; + + template + typename std::enable_if::value, void>::type + static std::string ToString(const W& arg); + */ + /* + template + static std::string ToString(const std::vector& arg); + */ + /* + template + static std::string ToString(S s); + template + static std::string ToString(std::vector s); + */ + + template + struct IsPointer { + static constexpr bool value = false; + }; + template + struct IsPointer { + static constexpr bool value = true; + }; + + template + static Y ExtractValue(const Y& value); + + template + static std::string ErrorHole(const std::vector& v); + template + static std::string ErrorHole2(const std::vector& v1, const std::vector& v2); + + + template + static std::string ErrorMessage(std::string varName, std::string funcName, T& var, std::string typeExpected, U& valueExpected, bool attrNotVar = false); + template + static std::string ErrorMessage(std::string varName, std::string funcName, std::vector& var, std::string typeExpected, std::vector& valueExpected, bool attrNotVar = false); + template + static std::string ErrorMessage(std::string varName, std::string funcName, const FastList& var, std::string typeExpected, const FastList& valueExpected, bool attrNotVar = false); + + static void ThrowError(std::string errorMsg, bool raiseNotThrow = false); + static int main(); + }; + + template + struct HasMethodToString + { + template + static std::true_type test(decltype(&U::to_string)*); + + template + static std::false_type test(...); + + static constexpr bool value = decltype(test(nullptr))::value; + }; + + class test_1 + { + public: + int nudes; + std::string name; + test_1() + { + this->nudes = 1; + this->name = "Tierney"; + } + std::string ToString() { + std::ostringstream oss; + oss << "test_1" << std::endl; + oss << "name: " << this->name << std::endl; + oss << "nudes: " << this->nudes << std::endl; + return oss.str(); + } + }; + + class test_10 + { + public: + std::list aList1; + std::vector::iterator> aIndex1; + test_10() + { + std::list aList1 = std::list(); + std::vector::iterator> aIndex1 = std::vector::iterator>(); + } + std::string ToString() { + std::ostringstream oss; + oss << "test_1" << std::endl; + // oss << "name: " << this->aList1 << std::endl; + // oss << "nudes: " << this->aIndex1 << std::endl; + return oss.str(); + } + }; +} + +#endif DATA_TYPES_H \ No newline at end of file diff --git a/library_cpp.sln b/library_cpp.sln new file mode 100644 index 0000000..0838f95 --- /dev/null +++ b/library_cpp.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33424.131 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "library_cpp", "library_cpp.vcxproj", "{6DD87860-E42C-4F71-8B30-12FF5200CF8C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Debug|x64.ActiveCfg = Debug|x64 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Debug|x64.Build.0 = Debug|x64 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Debug|x86.ActiveCfg = Debug|Win32 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Debug|x86.Build.0 = Debug|Win32 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Release|x64.ActiveCfg = Release|x64 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Release|x64.Build.0 = Release|x64 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Release|x86.ActiveCfg = Release|Win32 + {6DD87860-E42C-4F71-8B30-12FF5200CF8C}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A71AFAA4-6C4E-4879-9DCB-BE1B90C8CA96} + EndGlobalSection +EndGlobal diff --git a/library_cpp.vcxproj b/library_cpp.vcxproj new file mode 100644 index 0000000..974d29a --- /dev/null +++ b/library_cpp.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {6dd87860-e42c-4f71-8b30-12ff5200cf8c} + librarycpp + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/library_cpp.vcxproj.filters b/library_cpp.vcxproj.filters new file mode 100644 index 0000000..1e6f527 --- /dev/null +++ b/library_cpp.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file