Add project files.

This commit is contained in:
edwar
2023-11-13 20:00:22 +00:00
parent 4ffae760f7
commit 35a5d5c173
5 changed files with 1284 additions and 0 deletions

518
DataTypes.cpp Normal file
View File

@@ -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 <HasToString T>
std::ostream& operator<<(std::ostream& os, T& v) {
os << v.ToString();
return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec) {
return printVector(os, vec);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, FastList<T>& vec) {
os << vec.ToString();
return os;
}
/*
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<T>>& vec)
{
return printVector(os, vec);
}
*/
// Base case: Overload for a 1-dimensional vector
template <typename T>
std::ostream& printVector(std::ostream& os, std::vector<T>& 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 <class T>
std::ostream& printVector(std::ostream& os, std::vector< std::vector<T>>& 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<std::string> 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<enumPlusPlusItem>(); // {};
// 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 <typename W>
bool library123::ArgVal::IsString(const W& value)
{
return std::is_same<W, std::string>::value || std::is_same<W, std::string_view>::value;
}
/*
template <typename W>
typename std::enable_if<library123::ArgVal::IsAllowedType<W>::value, void>::type
std::string ToString(const W& arg)
{
// method 0
if (HasMethodToString<W>::value) { return arg.to_string(); };
// method 1: fail
// return std::to_string(value);
// method 2
std::ostream oss;
oss << arg;
return oss.str();
}
*/
/*
template<Stringable S>
std::string library123::ArgVal::ToString(S s)
{
return std::to_string(s);
}
template<Stringable S>
std::string library123::ArgVal::ToString(std::vector<S> 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 <typename W>
std::string library123::ArgVal::ToString(const W& arg)
{
// method 0
if (HasMethodToString<W>::value) { return arg.to_string(); };
// method 1: fail
// return std::to_string(value);
// method 2
std::ostream oss;
oss << arg;
return oss.str();
}
template <typename W>
std::string library123::ArgVal::ToString(const std::vector<W>& 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 <typename Y>
Y library123::ArgVal::ExtractValue(const Y& arg)
{
if (std::is_pointer<Y>::value) { return *arg; };
return arg;
}
template <typename Z>
std::string library123::ArgVal::ErrorHole(const std::vector<Z>& v)
{
return "";
}
template <typename Z1, typename Z2>
std::string library123::ArgVal::ErrorHole2(const std::vector<Z1>& v1, const std::vector<Z2>& v2)
{
return "";
}
/*
template<typename T, typename U, typename V>
std::string library123::ArgVal::ErrorMessage(T name, U var, V typeExpected0, V valueExpected, int sizeExpected, bool attrNotVar)
{
return std::string("");
}
*/
template<typename T, typename U>
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<typename T, typename U>
std::string library123::ArgVal::ErrorMessage(std::string varName, std::string funcName, std::vector<T>& var, std::string typeExpected, std::vector<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();
}
// 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<typename T, typename U>
std::string library123::ArgVal::ErrorMessage(std::string varName, std::string funcName, const FastList<T>& var, std::string typeExpected, const FastList<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();
}
// 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<double> v0 = { 0.0, 1.0, 2.0 };
std::vector<int> v1 = { 0, 1, 3 };
std::vector<std::vector<double>> v2(3, std::vector<double>(2, 0)); // = { v0; v0; v0 };
std::vector<std::vector<std::vector<double>>> v3(3, std::vector<std::vector<double>>(3, std::vector<double>(3, 0))); // = { v0; v0; v0 };
std::vector<std::vector<std::vector<std::vector<std::vector<double>>>>> v5(5, std::vector<std::vector< std::vector<std::vector<double>>>>(5, std::vector<std::vector<std::vector<double>>>(5, std::vector<std::vector<double>>(5, std::vector<double>(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<eWoman>(0));
std::cout << "nEWoman = " << nEWoman << std::endl;
for (int i = 0; i < nEWoman; i++)
{
eWoman ew = static_cast<eWoman>(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<int> ai = { 1, 2, 3 };
// std::cout << "ai: " << ai[-1] << " " << ai[-2] << std::endl; // error - negative indices not allowed
// test FastList::Default
FastList<int> tmp = FastList<int>::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<library123::test_1> vt1 = FastList<library123::test_1>::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<library123::test_1> 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<int> 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;
}

569
DataTypes.h Normal file
View File

@@ -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 <pch.h>
// external
#include <iostream>
#include <list>
#include <vector>
#include <sstream>
#include <stdexcept>
#include <format>
#include <type_traits>
#include <string>
#include <cstddef>
#include <concepts>
#include <ostream>
// TEMPLATE OBJECTS
template<typename W>
concept Stringable = requires(W w)
{
{ std::to_string(w) } -> std::convertible_to<std::string>;
} ||
requires(W w)
{
{ w } -> std::convertible_to<std::string>;
} ||
requires(W w)
{
{ w.ToString() } -> std::convertible_to<std::string>;
};
template<typename W>
concept HasToString = requires(W w)
{
{ w.ToString() } -> std::convertible_to<std::string>;
};
template<Stringable T>
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<T>::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<T>& operator=(FastList<T> original)
{
// if (this == &original) { return *this; }
size_t n = original.Size();
FastList<T> 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<T> original)
{
size_t n = original.Size();
FastList<T> duplicate;
this->aList = std::list<T>();
this->index = std::vector<typename std::list<T>::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<T>::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<T>::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<T> tmpList;
// std::vector<typename std::list<T>::iterator> tmpI;
// std::list<T>::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<typename std::list<T>::iterator> Index()
auto Index()
{
return this->index;
}
bool operator==(FastList<T> 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<typename std::list<T>::iterator> index;
static FastList<T> Default(int nElem, T vDefault)
{
nElem = std::max(0, nElem);
FastList<T> v;
if (nElem > 0)
{
for (int i = 0; i < nElem; i++)
{
v.PushBack(vDefault);
}
}
return v;
}
private:
std::list<T> aList;
std::vector<typename std::list<T>::iterator> index;
};
// Base case
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec);
template <typename T>
std::ostream& operator<<(std::ostream& os, FastList<T>& vec);
/*
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<T>>& vec);
*/
// Base case: Overload for a 0-dimensional vector element
template <typename T>
std::ostream& printVector(std::ostream& os, T& var) {
os << var;
return os;
}
// Base case: Overload for a 1-dimensional vector
template <typename T>
std::ostream& printVector(std::ostream& os, std::vector<T>& vec);
// Recursive case: Overload for n-dimensional vectors
template <class T>
std::ostream& printVector(std::ostream& os, std::vector< std::vector<T>>& vec);
// Overload the equality operator (==) for std::vector
template <typename T, typename U>
bool areVectorsEqual(const std::vector<T>& v1, const std::vector<U>& v2) { return false; }
template <typename T>
bool areVectorsEqual(const std::vector<T>& v1, const std::vector<T>& 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 <typename T>
bool areVectorsEqual(const std::vector<std::vector<T>>& v1, const std::vector<std::vector<T>>& 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 <typename T>
bool operator==(const std::vector<T>& v1, const std::vector<T>& v2)
{
return areVectorsEqual(v1, v2);
}
template <typename T>
bool operator==(const std::vector<std::vector<T>>& v1, const std::vector<std::vector<T>>& v2)
{
return areVectorsEqual(v1, v2);
}
template <typename T, typename U>
bool operator==(const std::vector<T>& v1, const std::vector<U>& v2)
{
return false;
}
enum PointerType
{
NEXT,
PREVIOUS
};
template<typename T>
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<typename T>
//class LinkedList
//{
//public:
// LinkedList() : head(nullptr), tail(nullptr) {};
// LinkedList(LinkedListNode<T>* 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<T> nodeNext = *this->head;
// LinkedListNode<T> 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<T>* head;
// LinkedListNode<T>* 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<std::string> 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<enumPlusPlusItem> enums;
int iStart;
};
enum eWoman
{
NIPPLE,
VAGINA,
BREAST
};
// template <typename T, typename U, typename V, typename W>
static class ArgVal // <T, U, V, W>
{
public:
template <typename W>
static bool IsString(const W& value);
/*
template <typename W>
struct IsAllowedType : std::false_type {};
template <>
struct IsAllowedType<int> : std::true_type {};
template <>
struct IsAllowedType<float> : std::true_type {};
template <>
struct IsAllowedType<double> : std::true_type {};
template <>
struct IsAllowedType<char> : std::true_type {};
template <>
struct IsAllowedType<bool> : std::true_type {};
template <>
struct IsAllowedType<void> : std::true_type {};
template <>
struct IsAllowedType<enumPlusPlus> : std::true_type {};
template <>
struct IsAllowedType<enumPlusPlusItem> : std::true_type {};
template <typename W>
typename std::enable_if<IsAllowedType<W>::value, void>::type
static std::string ToString(const W& arg);
*/
/*
template <typename W>
static std::string ToString(const std::vector<W>& arg);
*/
/*
template<Stringable S>
static std::string ToString(S s);
template<Stringable S>
static std::string ToString(std::vector<S> s);
*/
template <typename X>
struct IsPointer {
static constexpr bool value = false;
};
template <typename X>
struct IsPointer <X*> {
static constexpr bool value = true;
};
template <typename Y>
static Y ExtractValue(const Y& value);
template <typename Z>
static std::string ErrorHole(const std::vector<Z>& v);
template <typename Z1, typename Z2>
static std::string ErrorHole2(const std::vector<Z1>& v1, const std::vector<Z2>& v2);
template <typename T, typename U>
static std::string ErrorMessage(std::string varName, std::string funcName, T& var, std::string typeExpected, U& valueExpected, bool attrNotVar = false);
template <typename T, typename U>
static std::string ErrorMessage(std::string varName, std::string funcName, std::vector<T>& var, std::string typeExpected, std::vector<U>& valueExpected, bool attrNotVar = false);
template <typename T, typename U>
static std::string ErrorMessage(std::string varName, std::string funcName, const FastList<T>& var, std::string typeExpected, const FastList<U>& valueExpected, bool attrNotVar = false);
static void ThrowError(std::string errorMsg, bool raiseNotThrow = false);
static int main();
};
template <typename T>
struct HasMethodToString
{
template <typename U>
static std::true_type test(decltype(&U::to_string)*);
template <typename U>
static std::false_type test(...);
static constexpr bool value = decltype(test<T>(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<int> aList1;
std::vector<typename std::list<int>::iterator> aIndex1;
test_10()
{
std::list<int> aList1 = std::list<int>();
std::vector<typename std::list<int>::iterator> aIndex1 = std::vector<typename std::list<int>::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

31
library_cpp.sln Normal file
View File

@@ -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

139
library_cpp.vcxproj Normal file
View File

@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{6dd87860-e42c-4f71-8b30-12ff5200cf8c}</ProjectGuid>
<RootNamespace>librarycpp</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DataTypes.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DataTypes.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DataTypes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DataTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>