diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/Make/files b/manual_tests/Reader/cpp_src/dictionaryFile/Make/files new file mode 100644 index 0000000..4117b6e --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFile/Make/files @@ -0,0 +1,4 @@ + +dictionaryFile.C + +LIB = ./lib/dictionaryFile \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/Make/options b/manual_tests/Reader/cpp_src/dictionaryFile/Make/options new file mode 100644 index 0000000..47589bc --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFile/Make/options @@ -0,0 +1,4 @@ + +LIB_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.C b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.C new file mode 100644 index 0000000..3207520 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.C @@ -0,0 +1,48 @@ + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" + +#include "dictionaryFile.H" +#include "dictionaryFile_PythonInterface.H" + + +DictionaryFile::DictionaryFile(const char* filepath) +{ + Foam::fileName dictPath(filepath); + Foam::IFstream dictFileStream(dictPath); + mDictPtr = new Foam::dictionary(dictFileStream); +} + +DictionaryFile::~DictionaryFile() +{ + delete mDictPtr; +} + +// void DictionaryFile::printEntry(const char* key) +// { +// Foam::word keyname(key); +// std::cout +// << "dictionaryName : " << mDictPtr->name().toAbsolute() << " " +// << mDictPtr->lookupEntry(keyname, false, false).keyword() +// << std::endl; +// } + +// API FUNCTIONS=============================================================== +void* openDictionaryFile(const char* filepath) +{ + DictionaryFile* dictFile = new DictionaryFile(filepath); + return dictFile; +} + +void closeDictionaryFile(void* dictionaryFile) +{ + DictionaryFile* dictFile = static_cast(dictionaryFile); + delete dictFile; +} + +// void printDictionary(void* dictionaryFile) +// { +// DictionaryFile* dictFile = static_cast(dictionaryFile); +// dictFile->printEntry("key1"); +// } \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.H b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.H new file mode 100644 index 0000000..5217481 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile.H @@ -0,0 +1,15 @@ + +#pragma once + + +class DictionaryFile +{ +public: + Foam::dictionary* mDictPtr; + + DictionaryFile(const char* filepath); + ~DictionaryFile(); + // void* getIterator(); + // void printEntry(const char* key); +}; + diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H new file mode 100644 index 0000000..85c4649 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFile/dictionaryFile_PythonInterface.H @@ -0,0 +1,14 @@ + +#pragma once + + +extern "C" +{ + +void* openDictionaryFile(const char* filepath); +void closeDictionaryFile(void* dictionaryFile); +// void* getIterator(void* dictionaryFile); +// void printDictionary(void* dictionaryFile); +} + + diff --git a/manual_tests/Reader/cpp_src/dictionaryFile/lib/dictionaryFile.so b/manual_tests/Reader/cpp_src/dictionaryFile/lib/dictionaryFile.so new file mode 100644 index 0000000..02e09de Binary files /dev/null and b/manual_tests/Reader/cpp_src/dictionaryFile/lib/dictionaryFile.so differ diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/files b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/files new file mode 100644 index 0000000..b3e0f01 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/files @@ -0,0 +1,4 @@ + +dictionaryFileChecker.C + +EXE = ./bin/dictionaryFileChecker \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep new file mode 100644 index 0000000..d538d41 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.C.dep @@ -0,0 +1,278 @@ +$(OBJECTS_DIR)/dictionaryFileChecker.C.dep: \ +dictionaryFileChecker.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileName.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IFstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionary.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/word.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileNameI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/className.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/entry.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IDLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ITstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Pair.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionaryTemplates.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/string.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Istream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstreamI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/defineDebugSwitch.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyType.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtr.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBase.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/label.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uLabel.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordRe.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntry.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/char.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hasher.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/stringI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IOstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/token.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/debug.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionName.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variable.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyTypeI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtrI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/bool.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBaseI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/labelSpecific.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/error.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Tuple2.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableIO.C \ +$(WM_PROJECT_DIR)/src/OSspecific/POSIX/lnInclude/regExp.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hash.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/InfoProxy.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntryTemplates.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/scalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimString.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/refCount.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/typeInfo.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/runTimeSelectionTables.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionNameI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variableI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/pTraits.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/direction.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int32.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int64.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint32.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint64.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/messageStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/errorManip.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Ostream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObject.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zero.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListLoopM.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/contiguous.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IStringStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OStringStream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/floatScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/longDoubleScalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimStringI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/INew.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstream.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObjectI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zeroI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Swap.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBase.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleFloat.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Scalar.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstreamI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmp.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBaseI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/products.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListIO.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmpI.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.H \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.C \ +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrListIO.C \ + +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileName.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IFstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionary.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/word.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/fileNameI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/className.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/entry.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IDLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ITstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Pair.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/dictionaryTemplates.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/string.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Istream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ISstreamI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/defineDebugSwitch.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyType.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtr.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBase.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/label.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uLabel.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTable.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordRe.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntry.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/char.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hasher.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/stringI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IOstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/token.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DynamicList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/debug.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionName.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variable.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/keyTypeI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/autoPtrI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/bool.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/DLListBaseI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/labelSpecific.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/error.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Tuple2.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/HashTableIO.C : +$(WM_PROJECT_DIR)/src/OSspecific/POSIX/lnInclude/regExp.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/wordReI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/List.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Hash.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/InfoProxy.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/primitiveEntryTemplates.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/scalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimString.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/refCount.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/typeInfo.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/runTimeSelectionTables.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tokenI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/functionNameI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/variableI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ILListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/pTraits.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/direction.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int32.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/int64.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint32.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/uint64.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/messageStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/errorManip.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Ostream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObject.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zero.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListLoopM.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/contiguous.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/ListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/FixedListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IStringStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OStringStream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/floatScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/longDoubleScalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/verbatimStringI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UILListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/INew.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstream.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/nullObjectI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/zeroI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Swap.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBase.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/IndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UIndirectListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/BiIndirectListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/doubleFloat.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/Scalar.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OSstreamI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmp.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/PtrListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/SLListBaseI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/products.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/UPtrListIO.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/tmpI.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.H : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrList.C : +$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/LPtrListIO.C : + diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o new file mode 100644 index 0000000..bc34aea Binary files /dev/null and b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/dictionaryFileChecker.o differ diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files new file mode 100644 index 0000000..386f14a --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/linux64GccDPInt32Opt/files @@ -0,0 +1,4 @@ + +SOURCE += dictionaryFileChecker.C + +EXE = ./bin/dictionaryFileChecker \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/options b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/options new file mode 100644 index 0000000..7f9fcd2 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileChecker/Make/options @@ -0,0 +1,5 @@ + + +EXE_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker b/manual_tests/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker new file mode 100644 index 0000000..468601d Binary files /dev/null and b/manual_tests/Reader/cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker differ diff --git a/manual_tests/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C b/manual_tests/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C new file mode 100644 index 0000000..d08d22f --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileChecker/dictionaryFileChecker.C @@ -0,0 +1,54 @@ + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" + + +Foam::dictionary* dictPtr = nullptr; + + +bool openDictionary(const char* filepath); +void closeDictionary(); + + +int main(int argc, char* argv[]){ + + if( argc != 2 ){ + return 1; + } + + bool isOpen = openDictionary(argv[1]); + closeDictionary(); + + return (isOpen ? 0 : 1); +} + + +bool openDictionary(const char* filepath) +{ + if( dictPtr != nullptr ) + { + closeDictionary(); + } + + Foam::fileName dictPath(filepath); + Foam::IFstream dictFileStream(dictPath); + + if( dictFileStream.closed() or dictFileStream.bad() ) + { + return false; + } + + dictPtr = new Foam::dictionary(dictFileStream); + return true; +} + + +void closeDictionary() +{ + if( dictPtr != nullptr ) + { + delete dictPtr; + dictPtr = nullptr; + } +} \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/files b/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/files new file mode 100644 index 0000000..29166f8 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/files @@ -0,0 +1,3 @@ +dictionaryFileIterator.C + +LIB = ./lib/dictionaryFileIterator \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/options b/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/options new file mode 100644 index 0000000..e11a1db --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileIterator/Make/options @@ -0,0 +1,7 @@ + +EXE_INC = \ + -I../dictionaryFile + +LIB_LIBS = \ + -L$FOAM_LIBBIN \ + -lOpenFOAM \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C new file mode 100644 index 0000000..4e6f2f7 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.C @@ -0,0 +1,374 @@ + +#include +#include + +#include "fileName.H" +#include "IFstream.H" +#include "dictionary.H" +#include "token.H" + +#include "dictionaryFile.H" +#include "dictionaryFileIterator.H" +#include "dictionaryFileIterator_PythonInterface.H" + + +inline DictionaryFileIterator* toDictionaryFileIteratorPtr(void* dictFileItr) +{ + return static_cast(dictFileItr); +} + +// ============================================================================ +// Python Interface Functions +// ============================================================================ +void* createIterator(void* dictFilePtr) +{ + DictionaryFile* dictFile = static_cast(dictFilePtr); + DictionaryFileIterator* itr = new DictionaryFileIterator(dictFile); + return itr; +} + +void deleteIterator(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + delete itr; +} + +bool hasEntry(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->hasEntry(); +} + +bool step(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->step(); +} + +bool stepIn(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->stepIn(); +} + +bool stepOut(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->stepOut(); +} + +const char* getCurrentEntryKeyword(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryKeyword(); +} + +bool isCurrentEntryDict(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->isCurrentEntryDict(); +} + +int getCurrentEntryValueCount(void* dictFileItr) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueCount(); +} + +int getCurrentEntryValueTypeAt(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueTypeAt(index); +} + +const char* getCurrentEntryValueAt_String(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_String(index); +} + +char getCurrentEntryValueAt_Character(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Character(index); +} + +int getCurrentEntryValueAt_Integer(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Integer(index); +} + +float getCurrentEntryValueAt_Float(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Float(index); +} + +double getCurrentEntryValueAt_Double(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_Double(index); +} + +long double getCurrentEntryValueAt_LongDouble(void* dictFileItr, int index) +{ + DictionaryFileIterator* itr = toDictionaryFileIteratorPtr(dictFileItr); + return itr->getCurrentEntryValueAt_LongDouble(index); +} + + + + +// ============================================================================ +// DictionaryFileIterator Functions +// ============================================================================ + +DictionaryFileIterator::DictionaryFileIterator(DictionaryFile* dictFile) +{ + mDictFilePtr = dictFile; + + Foam::dictionary* dictPtr = dictFile->mDictPtr; + mDictStack.push(std::make_pair(dictPtr, dictPtr->begin())); +} + +DictionaryFileIterator::~DictionaryFileIterator() +{ + mDictFilePtr = nullptr; +} + +const Foam::token& DictionaryFileIterator::getCurrentEntryTokenAt(int index) +{ + if( index < 0 or mDictStack.empty() ) + return UNDEFINED_TOKEN; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return UNDEFINED_TOKEN; + + if( currIter().isDict() ) + return UNDEFINED_TOKEN; + + if( index >= currIter().stream().size() ) + return UNDEFINED_TOKEN; + + Foam::tokenList& tokens = currIter().stream(); + return tokens[index]; +} + +bool DictionaryFileIterator::hasEntry() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + return (currIter != currDictPtr->end()); +} + +bool DictionaryFileIterator::step() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + ++currIter; + + if( currIter == currDictPtr->end() ) + return false; + + return true; +} + +bool DictionaryFileIterator::stepIn() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + if( not currIter().isDict() ) + return false; + + Foam::dictionary* subDictPtr = currDictPtr->subDictPtr(currIter().keyword()); + mDictStack.push(std::make_pair(subDictPtr, subDictPtr->begin())); + return true; +} + +bool DictionaryFileIterator::stepOut() +{ + if( mDictStack.empty() ) + return false; + + // to disallow stepping out of root dictionary. + if( mDictStack.size() == 1 ) + return false; + + mDictStack.pop(); + + return true; +} + +const char* DictionaryFileIterator::getCurrentEntryKeyword() +{ + if( mDictStack.empty() ) + return EMPTY_STRING; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return EMPTY_STRING; + + return currIter().keyword().c_str(); +} + +bool DictionaryFileIterator::isCurrentEntryDict() +{ + if( mDictStack.empty() ) + return false; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return false; + + return currIter().isDict(); +} + +int DictionaryFileIterator::getCurrentEntryValueCount() +{ + if( mDictStack.empty() ) + return 0; + + dictInfo& top = mDictStack.top(); + Foam::dictionary* currDictPtr = top.first; + Foam::dictionary::iterator& currIter = top.second; + + if( currIter == currDictPtr->end() ) + return 0; + + if( currIter().isDict() ) + return 0; + + return currIter().stream().size(); +} + +int DictionaryFileIterator::getCurrentEntryValueTypeAt(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + int type = UNDEFINED; + + switch( tkn.type() ) + { + case Foam::token::tokenType::WORD: + type = STRING; + break; + + case Foam::token::tokenType::STRING: + type = STRING; + break; + + case Foam::token::tokenType::VERBATIMSTRING: + type = STRING; + break; + + case Foam::token::tokenType::FUNCTIONNAME: + type = STRING; + break; + + case Foam::token::tokenType::VARIABLE: + type = STRING; + break; + + case Foam::token::tokenType::LABEL: + type = INTEGER; + break; + + case Foam::token::tokenType::FLOAT_SCALAR: + type = FLOAT; + break; + + case Foam::token::tokenType::DOUBLE_SCALAR: + type = DOUBLE; + break; + + case Foam::token::tokenType::LONG_DOUBLE_SCALAR: + type = LONG_DOUBLE; + break; + + case Foam::token::tokenType::PUNCTUATION: + type = PUNCTUATION; + break; + + case Foam::token::tokenType::UNDEFINED: + type = UNDEFINED; + break; + + case Foam::token::tokenType::ERROR: + type = UNDEFINED; + break; + + case Foam::token::tokenType::COMPOUND: + type = UNDEFINED; + break; + } + + return type; +} + +const char* DictionaryFileIterator::getCurrentEntryValueAt_String(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.anyStringToken().c_str(); +} + +char DictionaryFileIterator::getCurrentEntryValueAt_Character(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.pToken(); +} + +int DictionaryFileIterator::getCurrentEntryValueAt_Integer(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.labelToken(); +} + +float DictionaryFileIterator::getCurrentEntryValueAt_Float(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.floatScalarToken(); +} + +double DictionaryFileIterator::getCurrentEntryValueAt_Double(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.doubleScalarToken(); +} + +long double DictionaryFileIterator::getCurrentEntryValueAt_LongDouble(int index) +{ + const Foam::token& tkn = getCurrentEntryTokenAt(index); + return tkn.longDoubleScalarToken(); +} + diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H new file mode 100644 index 0000000..4c8d466 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator.H @@ -0,0 +1,39 @@ + +#pragma once + + +typedef std::pair dictInfo; +const char* EMPTY_STRING = ""; +Foam::token UNDEFINED_TOKEN = Foam::token::undefinedToken; + + +class DictionaryFileIterator +{ +public: + DictionaryFileIterator(DictionaryFile* dictPtr); + ~DictionaryFileIterator(); + + bool hasEntry(); + bool step(); + bool stepIn(); + bool stepOut(); + + const char* getCurrentEntryKeyword(); + bool isCurrentEntryDict(); + int getCurrentEntryValueCount(); + int getCurrentEntryValueTypeAt(int index); + + const char* getCurrentEntryValueAt_String(int index); + char getCurrentEntryValueAt_Character(int index); + int getCurrentEntryValueAt_Integer(int index); + float getCurrentEntryValueAt_Float(int index); + double getCurrentEntryValueAt_Double(int index); + long double getCurrentEntryValueAt_LongDouble(int index); + +private: + DictionaryFile* mDictFilePtr; + std::stack mDictStack; + + const Foam::token& getCurrentEntryTokenAt(int index); +}; + diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H new file mode 100644 index 0000000..0274f79 --- /dev/null +++ b/manual_tests/Reader/cpp_src/dictionaryFileIterator/dictionaryFileIterator_PythonInterface.H @@ -0,0 +1,35 @@ + +extern "C" +{ + +enum ValueType{ + STRING = 0, + INTEGER, + FLOAT, + DOUBLE, + LONG_DOUBLE, + PUNCTUATION, + UNDEFINED, +}; + +void* createIterator(void* dictFilePtr); +void deleteIterator(void* dictFileItr); + +bool hasEntry(void* dictFileItr); +bool step(void* dictFileItr); +bool stepIn(void* dictFileItr); +bool stepOut(void* dictFileItr); + +const char* getCurrentEntryKeyword(void* dictFileItr); +bool isCurrentEntryDict(void* dictFileItr); +int getCurrentEntryValueCount(void* dictFileItr); +int getCurrentEntryValueTypeAt(void* dictFileItr, int index); + +const char* getCurrentEntryValueAt_String(void* dictFileItr, int index); +char getCurrentEntryValueAt_Character(void* dictFileItr, int index); +int getCurrentEntryValueAt_Integer(void* dictFileItr, int index); +float getCurrentEntryValueAt_Float(void* dictFileItr, int index); +double getCurrentEntryValueAt_Double(void* dictFileItr, int index); +long double getCurrentEntryValueAt_LongDouble(void* dictFileItr, int index); + +} \ No newline at end of file diff --git a/manual_tests/Reader/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so b/manual_tests/Reader/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so new file mode 100644 index 0000000..0cd80da Binary files /dev/null and b/manual_tests/Reader/cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so differ diff --git a/manual_tests/Reader/dictionaryFile.py b/manual_tests/Reader/dictionaryFile.py new file mode 100644 index 0000000..89374c2 --- /dev/null +++ b/manual_tests/Reader/dictionaryFile.py @@ -0,0 +1,56 @@ + +import os, errno + +from . import fileUtils +from .sharedLibs import DictionaryFileLib +from .exceptions import ( + InvalidDictionaryFileError, + ClosedDictionaryFileError, +) + + +class DictionaryFile: + def __init__(self, filepath: str, verifyFile: bool = True): + self.filepath = os.path.abspath(filepath) + + if not os.path.isfile(self.filepath): + raise FileNotFoundError( + errno.ENOENT, + os.strerror(errno.ENOENT), + self.filepath + ) + + if verifyFile: + isValid, error = fileUtils.verifyDictionaryFile(self.filepath) + if not isValid: + raise InvalidDictionaryFileError(self.filepath, error) + + self.__codec = 'ascii' + self.__fileptr = DictionaryFileLib.openDictionaryFile( + bytes(self.filepath, self.__codec) + ) + + def close(self): + ''' + Closes the file by deleting the C++ DictionaryFile object from memory. + ''' + if self.__fileptr is None: + raise ClosedDictionaryFileError(self.filepath) + + DictionaryFileLib.closeDictionaryFile(self.__fileptr) + self.__fileptr = None + + def isOpen(self) -> bool: + ''' + Check if file is open or not. + ''' + return self.__fileptr is not None + + def getFilePointer(self) -> int: + ''' + Get the pointer to C++ DictionaryFile object. + ''' + if not self.isOpen(): + raise ClosedDictionaryFileError(self.filepath) + return self.__fileptr + diff --git a/manual_tests/Reader/dictionaryFileIterator.py b/manual_tests/Reader/dictionaryFileIterator.py new file mode 100644 index 0000000..db346cb --- /dev/null +++ b/manual_tests/Reader/dictionaryFileIterator.py @@ -0,0 +1,335 @@ + +from enum import Enum +from pyvnt import ( + KeyData, + PropertyInt, + PropertyFloat, + PropertyString, + ValueProperty +) + +from .exceptions import ( + InvalidTraversalOperation, + ClosedDictionaryFileError, + ClosedDictionaryFileIteratorError, + IteratorOutOfRange, + InvalidPrimitiveEntryOperation, + InvalidDictionaryEntryOperation, +) +from .sharedLibs import DictionaryFileIteratorLib +from .dictionaryFile import DictionaryFile + + +INT_MIN = -99999999 +INT_MAX = 99999999 +CODEC = 'ascii' + + +class ValueType(Enum): + STRING = 0 + INTEGER = 1 + FLOAT = 2 + DOUBLE = 3 + LONG_DOUBLE = 4 + PUNCTUATION = 5 + UNDEFINED = 6 + + +class DictionaryFileIterator: + ''' + A uni-directional, read-only iterator to recursively traverse the OpenFOAM's + dictionary structure. It traverses the structure entry by entry. Dictionary + entries can be stepped in and stepped out of and primitive entries(non + dictionary entries) can be read. + ''' + def __init__(self, file: DictionaryFile): + self.file = file + if not file.isOpen(): + raise ClosedDictionaryFileError(self.file.filepath) + self.__iteratorPtr = DictionaryFileIteratorLib.createIterator( + self.file.getFilePointer() + ) + + def __checkValidity(self): + ''' + Checks if the iterator and file are open or not. + ''' + if not self.file.isOpen(): + raise ClosedDictionaryFileError(self.file.filepath) + if not self.isOpen(): + raise ClosedDictionaryFileIteratorError + + def close(self): + ''' + Closes the iterator. + ''' + if self.__iteratorPtr is None: + raise ClosedDictionaryFileIteratorError + DictionaryFileIteratorLib.deleteIterator(self.__iteratorPtr) + self.__iteratorPtr = None + + def isOpen(self) -> bool: + ''' + Checks if iterator is open or not. + ''' + return self.__iteratorPtr is not None + + def hasEntry(self) -> bool: + ''' + Checks if the iterator is currently pointing to an entry or not. + ''' + self.__checkValidity() + return DictionaryFileIteratorLib.hasEntry(self.__iteratorPtr) + + def step(self): + ''' + Moves the iterator to the next entry in current dictionary. For the last + entry in a dictionary moves the iterator out of range. + Raises an error if called when iterator is out of range. + ''' + self.__checkValidity() + if not self.hasEntry(): + raise IteratorOutOfRange + DictionaryFileIteratorLib.step(self.__iteratorPtr) + + def stepIn(self): + ''' + Steps into a dictionary entry and moves the iterator to first entry in it. + Raises an error if iterator is out of range. + Raises an error if current entry is not a dictionary entry. + ''' + self.__checkValidity() + if not self.hasEntry(): + raise IteratorOutOfRange + + if not self.isCurrentEntryDict(): + raise InvalidPrimitiveEntryOperation + + DictionaryFileIteratorLib.stepIn(self.__iteratorPtr) + + def stepOut(self): + ''' + Steps out from current dictionary and moves the iterator to the entry in + parent dictionary from where step in occured. + Raises an error when stepping out of root dictionary. + ''' + self.__checkValidity() + stepOutOccured = DictionaryFileIteratorLib.stepOut(self.__iteratorPtr) + + if not stepOutOccured: + raise InvalidTraversalOperation( + 'Cannot step out of root dictionary.' + ) + + def getCurrentEntryKeyword(self) -> str: + ''' + Returns a string representing the name of the key of current entry. + Raises an error if the iterator is out of range. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + keyword = str( + DictionaryFileIteratorLib.getCurrentEntryKeyword(self.__iteratorPtr), + CODEC + ) + return keyword + + def isCurrentEntryDict(self) -> bool: + ''' + Checks if current entry is a 'dictionary entry' or a 'primitive entry(non + dictionary entry).' + Raises an error if iterator is out of range. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + return DictionaryFileIteratorLib.isCurrentEntryDict(self.__iteratorPtr) + + def getValues(self) -> list[ValueProperty]: + ''' + Returns a list of 'ValueProperty' objects for the values in current entry. + Raises an error if iterator is out of range. + Raises an error if current entry is not primitive entry. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + if self.isCurrentEntryDict(): + raise InvalidDictionaryEntryOperation + + stack = [[]] + + for index in range(self.__getCurrentEntryValueCount()): + val = self.__getValueAt(index) + if val == '(' or val == '[': + stack.append([]) + elif val == ')': + popped = stack.pop() + # stack[len(stack)-1].append(popped) + elif val == ']': + popped = tuple(stack.pop()) + # stack[len(stack)-1].append(popped) + elif val == ',': + pass + else: + prop = self.__getValuePropertyAt(index) + stack[len(stack)-1].append(prop) + + return stack[0] + + def getRawValues(self) -> list: + ''' + Return list of raw python objects for the values in current entry. + ''' + self.__checkValidity() + return [val.giveVal() for val in self.getValues()] + + def getKeyData(self) -> KeyData: + ''' + Returns 'KeyData' object for the current entry. + Raises an error if iterator is out of range. + Raises an error if current entry is not primitive entry. + ''' + self.__checkValidity() + + if not self.hasEntry(): + raise IteratorOutOfRange + + if self.isCurrentEntryDict(): + raise InvalidDictionaryEntryOperation + + key = self.getCurrentEntryKeyword() + values = self.getValues() + return KeyData(key, *values) + + def __getCurrentEntryValueCount(self) -> int: + ''' + Returns the number of value tokens in the current entry. The tokens also + includes characters like comma(,) and brackets((),[]). + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueCount(self.__iteratorPtr) + + def __getCurrentEntryValueTypeAt(self, index: int) -> ValueType: + ''' + Returns the ValueType of token at a given index in values of an entry. + ''' + valType = ValueType( + DictionaryFileIteratorLib.getCurrentEntryValueTypeAt( + self.__iteratorPtr, + index + ) + ) + return valType + + def __getCurrentEntryValueAt_String(self, index : int) -> str: + ''' + Get token at given index as a 'str'. + The ValueType of this token should be of type 'str'. + ''' + val = DictionaryFileIteratorLib.getCurrentEntryValueAt_String( + self.__iteratorPtr, + index + ) + + return str(val, CODEC) + + def __getCurrentEntryValueAt_Character(self, index : int) -> str: + ''' + Get token at given index as a 'character'. + The ValueType of this token should be of type 'character'. + ''' + val = DictionaryFileIteratorLib.getCurrentEntryValueAt_Character( + self.__iteratorPtr, + index + ) + return str(val, CODEC) + + def __getCurrentEntryValueAt_Integer(self, index : int) -> int: + ''' + Get token at given index as a 'integer'. + The ValueType of this token should be of type 'integer' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_Float(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Float( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_Double(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_Double( + self.__iteratorPtr, + index + ) + + def __getCurrentEntryValueAt_LongDouble(self, index : int) -> float: + ''' + Get token at given index as a 'float'. + The ValueType of this token should be of type 'float' + ''' + return DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble( + self.__iteratorPtr, + index + ) + + def __getValueAt(self, index : int, valType: ValueType = None): + ''' + Returns a python object for value at the given index. + ''' + if valType is None: + valType = self.__getCurrentEntryValueTypeAt(index) + value = None + + if valType == ValueType.STRING: + value = self.__getCurrentEntryValueAt_String(index) + elif valType == ValueType.PUNCTUATION: + value = self.__getCurrentEntryValueAt_Character(index) + elif valType == ValueType.INTEGER: + value = self.__getCurrentEntryValueAt_Integer(index) + elif valType == ValueType.FLOAT: + value = self.__getCurrentEntryValueAt_Float(index) + elif valType == ValueType.DOUBLE: + value = self.__getCurrentEntryValueAt_Double(index) + elif valType == ValueType.LONG_DOUBLE: + value = self.__getCurrentEntryValueAt_LongDouble(index) + + return value + + def __getValuePropertyAt(self, index : int) -> ValueProperty: + ''' + Returns a ValueProperty object for value at the given index. + ''' + valType = self.__getCurrentEntryValueTypeAt(index) + val = self.__getValueAt(index, valType) + + if valType == ValueType.INTEGER: + return PropertyInt(f'val{index+1}', val, INT_MIN, INT_MAX) + + if valType == ValueType.FLOAT or \ + valType == ValueType.DOUBLE or \ + valType == ValueType.LONG_DOUBLE: + return PropertyFloat(f'val{index+1}', val, float('-inf'), float('inf')) + + if valType == ValueType.STRING: + return PropertyString(f'val{index+1}', val) + + return PropertyString(f'val{index+1}', 'Invalid') diff --git a/manual_tests/Reader/exceptions.py b/manual_tests/Reader/exceptions.py new file mode 100644 index 0000000..f060dd2 --- /dev/null +++ b/manual_tests/Reader/exceptions.py @@ -0,0 +1,66 @@ + + +class InvalidDictionaryFileError(Exception): + ''' + Invalid syntax in Dictionary File. + ''' + def __init__(self, filepath: str, openfoamErrorMessage: str): + self.filepath = filepath + self.openfoamErrorMessage = openfoamErrorMessage + + def __str__(self): + return f"Error occured while parsing the file : {self.filepath}\n {self.openfoamErrorMessage}" + + +class InvalidTraversalOperation(Exception): + ''' + Generic Invalid Traversal Operation. + ''' + def __init__(self, msg: str): + self.msg = msg + + def __str__(self): + return self.msg + + +class ClosedDictionaryFileError(Exception): + ''' + Dictionary File closed. + ''' + def __init__(self, filepath: str): + self.filepath = filepath + + def __str__(self): + return f"Cannot operate on a closed file : {self.filepath}" + + +class ClosedDictionaryFileIteratorError(Exception): + ''' + DictionaryFileIterator closed. + ''' + def __str__(self): + return f"Cannot operate with a closed iterator" + + +class IteratorOutOfRange(Exception): + ''' + DictionaryFileIterator is out of range. + ''' + def __str__(self): + return f"Iterator has moved beyond last entry in current dictionary" + + +class InvalidPrimitiveEntryOperation(Exception): + ''' + Invalid operation for a primitive entry. + ''' + def __str__(self): + return f"Invalid operation for primitive entry" + + +class InvalidDictionaryEntryOperation(Exception): + ''' + Invalid operation for a dictionary entry. + ''' + def __str__(self): + return "Invalid operation for dictionary entry" \ No newline at end of file diff --git a/manual_tests/Reader/fileUtils.py b/manual_tests/Reader/fileUtils.py new file mode 100644 index 0000000..3391970 --- /dev/null +++ b/manual_tests/Reader/fileUtils.py @@ -0,0 +1,22 @@ + +import os +import subprocess as sp + + +EXECUTABLE_PATH = os.path.join( + os.path.dirname(__file__), + 'cpp_src/dictionaryFileChecker/bin/dictionaryFileChecker' +) + + +def verifyDictionaryFile(filepath : str) -> tuple[bool, str]: + ''' + Checks if the given file follows the syntax of OpenFOAM's dictionary files. + Uses the custom utility 'dictionaryFileChecker' in a subprocess. The call to + this function is blocking as it waits for the subprocess to exit. + ''' + args = (EXECUTABLE_PATH, filepath) + res = sp.run(args, stdout=sp.PIPE, stderr=sp.STDOUT) + isValid = (res.returncode == 0) and (len(res.stdout) == 0) + output = str(res.stdout, encoding='ascii') + return (isValid, output) diff --git a/manual_tests/Reader/old__init__.py b/manual_tests/Reader/old__init__.py new file mode 100644 index 0000000..5028e7e --- /dev/null +++ b/manual_tests/Reader/old__init__.py @@ -0,0 +1,54 @@ + +import os +from pyvnt.DictionaryElement.foamDS import Foam +from .dictionaryFileIterator import DictionaryFileIterator +from .dictionaryFile import DictionaryFile + + +def read(filepath : str, verifyFile: bool = True) -> Foam: + ''' + Reads dictionary file from the given filepath and returns a node tree + representation of it. + ''' + file = DictionaryFile(filepath, verifyFile) + itr = DictionaryFileIterator(file) + root = _createTree(file.filepath, itr) + itr.close() + file.close() + + return root + + +def _createTree(parentName: str, itr: DictionaryFileIterator) -> Foam: + ''' + Recursively traverse the openfoam's dictionary data structure and create the + node-tree structure. + ''' + data = {} + while itr.hasEntry(): + key = itr.getCurrentEntryKeyword() + value = None + + if itr.isCurrentEntryDict(): + itr.stepIn() + value = _createTree(key, itr) + itr.stepOut() + else: + value = itr.getKeyData() + + data[key] = value + itr.step() + + # create node + children = [val for val in data.values() if isinstance(val,Foam)] + + for key in list(data.keys()): + val = data[key] + if isinstance(val,Foam): + del data[key] + + node = Foam(parentName, children=children, *data.values()) + + return node + + diff --git a/manual_tests/Reader/sharedLibs.py b/manual_tests/Reader/sharedLibs.py new file mode 100644 index 0000000..8fd0991 --- /dev/null +++ b/manual_tests/Reader/sharedLibs.py @@ -0,0 +1,150 @@ + + +import ctypes +import os + + +class DictionaryFileLib: + _libFilePath = os.path.join( + os.path.dirname(__file__), + "cpp_src/dictionaryFile/lib/dictionaryFile.so" + ) + _lib = ctypes.CDLL(_libFilePath) + openDictionaryFile = _lib.openDictionaryFile + closeDictionaryFile = _lib.closeDictionaryFile + +# _function_signature_dict = { +# 'openDictionaryFile' : (ctypes.c_char_p, ctypes.c_void_p), +# 'closeDictionaryFile' : (ctypes.c_void_p, None) +# } + + +# _libs = [DictionaryFileLib] + +# for lib in _libs: +# func_names = [attr for attr in dir(lib) if not attr.startswith('_')] +# print(func_names) +# for func in func_names: +# if func in lib._function_signature_dict: +# argtypes, restype = lib._function_signature_dict[func] +# lib.__dict__[func].argtypes = argtypes +# lib.__dict__[func].restype = restype + + + +DictionaryFileLib.openDictionaryFile.argtypes = [ctypes.c_char_p] +DictionaryFileLib.openDictionaryFile.restype = ctypes.c_void_p + +DictionaryFileLib.closeDictionaryFile.argtypes = [ctypes.c_void_p] +DictionaryFileLib.closeDictionaryFile.restype = None + + + +class DictionaryFileIteratorLib: + _libFilePath = os.path.join( + os.path.dirname(__file__), + "cpp_src/dictionaryFileIterator/lib/dictionaryFileIterator.so" + ) + _lib = ctypes.CDLL(_libFilePath) + createIterator = _lib.createIterator + deleteIterator = _lib.deleteIterator + hasEntry = _lib.hasEntry + step = _lib.step + stepIn = _lib.stepIn + stepOut = _lib.stepOut + getCurrentEntryKeyword = _lib.getCurrentEntryKeyword + isCurrentEntryDict = _lib.isCurrentEntryDict + getCurrentEntryValueCount = _lib.getCurrentEntryValueCount + getCurrentEntryValueTypeAt = _lib.getCurrentEntryValueTypeAt + getCurrentEntryValueAt_String = _lib.getCurrentEntryValueAt_String + getCurrentEntryValueAt_Character = _lib.getCurrentEntryValueAt_Character + getCurrentEntryValueAt_Integer = _lib.getCurrentEntryValueAt_Integer + getCurrentEntryValueAt_Float = _lib.getCurrentEntryValueAt_Float + getCurrentEntryValueAt_Double = _lib.getCurrentEntryValueAt_Double + getCurrentEntryValueAt_LongDouble = _lib.getCurrentEntryValueAt_LongDouble + + +DictionaryFileIteratorLib.createIterator.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.createIterator.restype = ctypes.c_void_p + +DictionaryFileIteratorLib.deleteIterator.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.deleteIterator.restype = None + +DictionaryFileIteratorLib.hasEntry.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.hasEntry.restype = ctypes.c_bool + +DictionaryFileIteratorLib.step.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.step.restype = ctypes.c_bool + +DictionaryFileIteratorLib.stepIn.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.stepIn.restype = ctypes.c_bool + +DictionaryFileIteratorLib.stepOut.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.stepOut.restype = ctypes.c_bool + +DictionaryFileIteratorLib.getCurrentEntryKeyword.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.getCurrentEntryKeyword.restype = ctypes.c_char_p + +DictionaryFileIteratorLib.isCurrentEntryDict.argtypes = [ctypes.c_void_p] +DictionaryFileIteratorLib.isCurrentEntryDict.restype = ctypes.c_bool + + +DictionaryFileIteratorLib.getCurrentEntryValueCount.argtypes = [ + ctypes.c_void_p +] +DictionaryFileIteratorLib.getCurrentEntryValueCount.restype = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueTypeAt.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueTypeAt.restype = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_String.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_String.restype \ + = ctypes.c_char_p + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Character.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Character.restype \ + = ctypes.c_char + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Integer.restype \ + = ctypes.c_int + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Float.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Float.restype \ + = ctypes.c_float + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_Double.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_Double.restype \ + = ctypes.c_double + + +DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble.argtypes = [ + ctypes.c_void_p, + ctypes.c_int +] +DictionaryFileIteratorLib.getCurrentEntryValueAt_LongDouble.restype \ + = ctypes.c_longdouble diff --git a/pyvnt/Reference/basic.py b/pyvnt/Reference/basic.py index 4b34408..9525d2d 100755 --- a/pyvnt/Reference/basic.py +++ b/pyvnt/Reference/basic.py @@ -74,6 +74,36 @@ def giveVal(self): def __repr__(self): return f"PropertyInt(name = {self._ValueProperty__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" + def __add__(self, other): + return self.__default + other._PropertyFloat__default + + def __sub__(self, other): + return self.__default - other._PropertyFloat__default + + def __mul__(self, other): + return self.__default * other._PropertyFloat__default + + def __truediv__(self, other): + return self.__default / other._PropertyFloat__default + + def __gt__(self, other): + return self.__default > other._PropertyFloat__default + + def __lt__(self, other): + return self.__default < other._PropertyFloat__default + + def __le__(self, other): + return self.__default <= other._PropertyFloat__default + + def __ge__(self, other): + return self.__default >= other._PropertyFloat__default + + def __eq__(self, other): + return self.__default == other._PropertyFloat__default + + def __ne__(self, other): + return self.__default != other._PropertyFloat__default + def writeOut(self, file): ''' Function to write the object to a file @@ -81,6 +111,7 @@ def writeOut(self, file): file.write(f"{self.__default}") + class PropertyFloat(ValueProperty): ''' Property class to store float values @@ -134,6 +165,36 @@ def giveVal(self): def __repr__(self): return f"PropertyFloat(name = {self._ValueProperty__name}, default = {self.__default}, minimum = {self.__minimum}, maximum = {self.__maximum})" + def __add__(self, other): + return self.__default + other._PropertyFloat__default + + def __sub__(self, other): + return self.__default - other._PropertyFloat__default + + def __mul__(self, other): + return self.__default * other._PropertyFloat__default + + def __truediv__(self, other): + return self.__default / other._PropertyFloat__default + + def __gt__(self, other): + return self.__default > other._PropertyFloat__default + + def __lt__(self, other): + return self.__default < other._PropertyFloat__default + + def __le__(self, other): + return self.__default <= other._PropertyFloat__default + + def __ge__(self, other): + return self.__default >= other._PropertyFloat__default + + def __eq__(self, other): + return self.__default == other._PropertyFloat__default + + def __ne__(self, other): + return self.__default != other._PropertyFloat__default + def writeOut(self, file): ''' Function to write the object to a file @@ -141,6 +202,7 @@ def writeOut(self, file): file.write(f"{self.__default}") + class PropertyString(ValueProperty): # for testing purposes only, to be scrapped ''' Property class to store string values @@ -193,7 +255,7 @@ class EnumProp(ValueProperty): ''' - __slots__ = ('_EnumProp__items', '_EnumProp__default') + __slots__ = ('_ValueProperty__name', '_EnumProp__items', '_EnumProp__default') def __init__(self, name: str, items: {str}, default: str): super(EnumProp, self).__init__() diff --git a/pyvnt/Reference/errorClasses.py b/pyvnt/Reference/errorClasses.py index f1e3bda..da9fc5f 100755 --- a/pyvnt/Reference/errorClasses.py +++ b/pyvnt/Reference/errorClasses.py @@ -63,3 +63,40 @@ def __init__(self): def __str__(self): return f"Given range is invalid" + +class InvalidTupleError(TypeError): + def __init__(self, item): + self.item = item + + def __str__(self): + return f"{self.item} not an tuple type" + +class SizeError(Exception): + def __init__(self, size: int): + self.size = size + + def __str__(self): + return f"Size of values should be {self.size}" + +class NoPlaceholdersError(Exception): + def __init__(self, msg: str): + self.msg = msg + + def __str__(self): + return f"{self.msg}" + +class NoValueError(Exception): + def __init__(self, msg: str): + self.msg = msg + + def __str__(self): + return f"{self.msg}" + +class KeyRepeatError(Exception): + def __init__(self, key: str): + self.key = key + + def __str__(self): + return f"{self.key} Already exists" + + diff --git a/pyvnt/Reference/list.py b/pyvnt/Reference/list.py new file mode 100644 index 0000000..5b115b2 --- /dev/null +++ b/pyvnt/Reference/list.py @@ -0,0 +1,108 @@ +from pyvnt.Reference.basic import * +from pyvnt.Reference.errorClasses import SizeError, NoPlaceholdersError, NoValueError, KeyRepeatError +import warnings + +class PropertyList(ValueProperty): + ''' + A property that holds a list of values. + + Constructor Parameters: + name: The name of the property. + size: The size of the list. + values: The values of the list. + default: The default value of the list. + + Class constructor can be called in the following ways: + PropertyList(name, size, values) + PropertyList(name, values) + PropertyList(name, size, default) + + ''' + + __slots__ = ['_ValuePorperty__name', '_PropertyList__values'] + + def __init__(self, name: int, size: int = None, values: [ValueProperty] = [], default: ValueProperty = None): + super().__init__(name, default) + self.setProperties(name, size, values, default) + + + def setProperties(self, name: int, size: int, values: [ValueProperty], default: ValueProperty = None): + ''' + Sets the values of the list. + ''' + self._ValueProperty__name = name + + if size and values != []: + if default: + warnings.warn("Default value will be ignored") + else: + pass + + if size != len(values): + raise SizeError(size) + else: + self._PropertyList__values = values + + elif not size and values != []: + if default: + warnings.warn("Default value will be ignored") + else: + pass + + self._PropertyList__values = values + + elif size and values == []: + if default: + warnings.warn("Default value will be ignored") + else: + pass + + if not default: + raise NoPlaceholdersError("No default value") + else: + self._PropertyList__values = [default] * size + + else: + raise NoValueError("No values given for list construction") + + def getItem(self, index: int): + ''' + Returns the value at the given index. + ''' + return self._PropertyList__values[index] + + def append_value(self, val: ValueProperty): + ''' + Appends the value to the list. + ''' + self._PropertyList__values.append(val) + + def append_uniq_value(self, val: ValueProperty): + ''' + Appends the value to the list if it is not already present. + ''' + if val not in self._PropertyList__values: + self._PropertyList__values.append(val) + else: + raise KeyRepeatError(val) + + def __repr__(self): + return f"{self._ValueProperty__name}: {self._PropertyList__values}" + + def size(self): + ''' + Returns the size of the list. + ''' + return len(self._PropertyList__values) + + def giveVal(self): + ''' + Returns the list. + ''' + return self._PropertyList__values + + def __eq__(self, other): + return self._PropertyList__values == other.giveVal() + + + diff --git a/pyvnt/Reference/tensor.py b/pyvnt/Reference/tensor.py new file mode 100644 index 0000000..f6b3161 --- /dev/null +++ b/pyvnt/Reference/tensor.py @@ -0,0 +1,211 @@ +from pyvnt.Reference.basic import * +from pyvnt.Reference.errorClasses import InvalidTupleError +from pyvnt.Reference.vector import PropertyVector +import numpy as np + +class PropertyTensor(ValueProperty): + ''' + A property that holds a tensor value. + + Tensor is stored in the following manner: + [[xx, xy, xz], + [yx, yy, yz], + [zx, zy, zz]] + + Constructor Parameters: + name: The name of the property. + value: list + ''' + + __slots__ = ('_PropertyTensor__name', '_PropertyTensor__values') + + def instance_restricted(self): + pass + + def __init__(self, name, value: [PropertyFloat]): + super(PropertyTensor, self).__init__() + + inputs = [] + + for i in range(3): + for j in range(3): + inputs.append((i, j, value[i*3+j])) + self.setProperties(name, *inputs) + + # TODO: Implement matrix operations for tensors, refer to the OpenFOAM team for details + + # TODO: Change the way input is taken in this method, refer Matlab's matrix slicing --done + def setProperties(self, name: str, *args: (int, int, PropertyFloat)) -> None: + ''' + Function to edit the values stored in the object + + Parameters: + name: The name of the property. + *args: The values of the tensor in the form of tuples. + + The tuples should be in the form of (i, j, PropertyFloat) where i and j are the indices of the tensor in 1-based indexing. + In order to set the value for an entire row or column, set the index to 0 for the row or column respectively. + + Example: + To set the value of the entire row 1 to 5, the tuple should be (1, 0, PropertyFloat(name, 5)) + To set the value of the entire column 2 to 5, the tuple should be (0, 2, PropertyFloat(name, 5)) + To set the value of the element at row 1 and column 2 to 5, the tuple should be (1, 2, PropertyFloat(name, 5)) + + ''' + self._ValueProperty__name = name + + inputs = list(args) + self.__values = [[0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + + for t in inputs: + if len(t) != 3 or type(t[0]) != int or type(t[1]) != int or type(t[2]) != PropertyFloat: + raise InvalidTupleError(t) + else: + if t[0] == 0 and t[1] == 0: + val = t[2] + self.__values = [[val, val, val], + [val, val, val], + [val, val, val]] + elif t[0] == 0: + for i in range(3): + self.__values[i][t[1]-1] = t[2] + elif t[1] == 0: + for i in range(3): + self.__values[t[0]-1][i] = t[2] + elif t[0] != 0 and t[1] != 0: + self.__values[t[0]-1][t[1]-1] = t[2] + else: + raise InvalidTupleError(t) + + def xx(self) -> PropertyFloat: + ''' + Returns the xx value of the tensor + ''' + return self.__values[0][0] + + def xy(self) -> PropertyFloat: + ''' + Returns the xy value of the tensor + ''' + return self.__values[0][1] + + def xz(self) -> PropertyFloat: + ''' + Returns the xz value of the tensor + ''' + return self.__values[0][2] + + def yx(self) -> PropertyFloat: + ''' + Returns the yx value of the tensor + ''' + return self.__values[1][0] + + def yy(self) -> PropertyFloat: + ''' + Returns the yy value of the tensor + ''' + return self.__values[1][1] + + def yz(self) -> PropertyFloat: + ''' + Returns the yz value of the tensor + ''' + return self.__values[1][2] + + def zx(self) -> PropertyFloat: + ''' + Returns the zx value of the tensor + ''' + return self.__values[2][0] + + def zy(self) -> PropertyFloat: + ''' + Returns the zy value of the tensor + ''' + return self.__values[2][1] + + def zz(self) -> PropertyFloat: + ''' + Returns the zz value of the tensor + ''' + return self.__values[2][2] + + def row(self, r: int) -> PropertyVector: + ''' + Returns the row vector of the tensor + + Parameters: + r: The row number of the tensor + ''' + return PropertyVector(self._ValueProperty__name + "_row", self.__values[r][0], self.__values[r][1], self.__values[r][2]) + + def col(self, c: int) -> PropertyVector: + ''' + Returns the column vector of the tensor + + Parameters: + c: The column number of the tensor + ''' + return PropertyVector(self._ValueProperty__name + "_col", self.__values[0][c], self.__values[1][c], self.__values[2][c]) + + def diag(self) -> PropertyVector: + ''' + Returns the diagonal vector of the tensor + ''' + return PropertyVector(self._ValueProperty__name + "_diag", self.__values[0][0], self.__values[1][1], self.__values[2][2]) + + def T(self) -> PropertyTensor: + ''' + Return non-Hermitian transpose of the tensor + ''' + return PropertyTensor(self._ValueProperty__name + "_T", [self.__values[0][0], self.__values[1][0], self.__values[2][0], + self.__values[0][1], self.__values[1][1], self.__values[2][1], + self.__values[0][2], self.__values[1][2], self.__values[2][2]]) + + def inv(self) -> PropertyTensor: + ''' + Returns the inverse of the tensor + ''' + ar = np.array([[self.xx().giveVal(), self.xy().giveVal(), self.xz().giveVal()], + [self.yx().giveVal(), self.yy().giveVal(), self.yz().giveVal()], + [self.zx().giveVal(), self.zy().giveVal(), self.zz().giveVal()]]) + + res = np.linalg.inv(ar) + + return PropertyTensor(self._ValueProperty__name + "_inv", [res[0][0], res[0][1], res[0][2], + res[1][0], res[1][1], res[1][2], + res[2][0], res[2][1], res[2][2]]) + + def inner(self, t: PropertyTensor) -> PropertyTensor: + ''' + Returns the inner product of the tensor with another tensor + ''' + return PropertyTensor(self._ValueProperty__name + "_inner", [self.xx()*t.xx() + self.xy()*t.yx() + self.xz()*t.zx(), + self.xx()*t.xy() + self.xy()*t.yy() + self.xz()*t.zy(), + self.xx()*t.xz() + self.xy()*t.yz() + self.xz()*t.zz(), + + self.yx()*t.xx() + self.yy()*t.yx() + self.yz()*t.zx(), + self.yx()*t.xy() + self.yy()*t.yy() + self.yz()*t.zy(), + self.yx()*t.xz() + self.yy()*t.yz() + self.yz()*t.zz(), + + self.zx()*t.xx() + self.zy()*t.yx() + self.zz()*t.zx(), + self.zx()*t.xy() + self.zy()*t.yy() + self.zz()*t.zy(), + self.zx()*t.xz() + self.zy()*t.yz() + self.zz()*t.zz()]) + + def schur(self, t: PropertyTensor) -> PropertyTensor: + ''' + Returns the Schur product of the tensor with another tensor + ''' + return PropertyTensor(self._ValueProperty__name + "_schur", [self.xx()*t.xx(), self.xy()*t.xy(), self.xz()*t.xz(), + self.yx()*t.yx(), self.yy()*t.yy(), self.yz()*t.yz(), + self.zx()*t.zx(), self.zy()*t.zy(), self.zz()*t.zz()]) + + def __repr__(self): + return f"PropertyTensor(name = {self._ValueProperty__name}, xx = {self.xx()}, xy = {self.xy()}, xz = {self.xz()}, yx = {self.yx()}, yy = {self.yy()}, yz = {self.yz()}, zx = {self.zx()}, zy = {self.zy()}, zz = {self.zz()})" + + + + \ No newline at end of file diff --git a/pyvnt/Reference/vector.py b/pyvnt/Reference/vector.py new file mode 100644 index 0000000..5757ded --- /dev/null +++ b/pyvnt/Reference/vector.py @@ -0,0 +1,86 @@ +from pyvnt.Reference.basic import * + +class PropertyVector(ValueProperty): + ''' + Property Class to store vector values + + Constructor Parameters: + name: Name of the property of which vector value is to be stored + x: PropertyFloat object to store x value of the vector + y: PropertyFloat object to store y value of the vector + z: PropertyFloat object to store z value of the vector + ''' + + __slots__ = ('_PropertyVector__name', '_PropertyVector__x', '_PropertyVector__y', '_PropertyVector__z') + + def instance_restricted(self): + pass + + # TODO: Confirm about the format exoected from a vector + def __init__(self, name: str, x: PropertyFloat, y: PropertyFloat, z: PropertyFloat): + super(PropertyVector, self).__init__() + self.setProperties(name, x, y, z) + + def setProperties(self, name: str = None, x: PropertyFloat = None, y: PropertyFloat = None, z: PropertyFloat = None) -> None: + ''' + Function to edit the values stored in the object + + Parameters: + name: Name of the property of which vector value is to be stored + x: PropertyFloat object to store x value of the vector + y: PropertyFloat object to store y value of the vector + z: PropertyFloat object to store z value of the vector + ''' + if name: + self._ValueProperty__name = name + + if x: + self.__x = x + + if y: + self.__y = y + + if z: + self.__z = z + + def x(self) -> float: + ''' + Returns the x value of the vector + ''' + + return self.__x.giveVal() + + def y(self) -> float: + ''' + Returns the y value of the vector + ''' + return self.__y.giveVal() + + def z(self) -> float: + ''' + Returns the z value of the vector + ''' + return self.__z.giveVal() + + def magnitude(self) -> float: + ''' + Returns the magnitude of the vector + ''' + return math.sqrt(self.__x.giveVal()**2 + self.__y.giveVal()**2 + self.__z.giveVal()**2) + + def normalise(self, tol: PropertyFloat) -> PropertyVector: + ''' + Normalises the vector + + Parameters: + tol: The tolerance value for the normalisation. If the magnitude of the vector is less than the tolerance, the vector is set to 0. + ''' + s = self.magnitude() + if s < tol.giveVal(): + self.setProperties(self.__name, PropertyFloat(self.__name + "_x", 0), PropertyFloat(self.__name + "_y", 0), PropertyFloat(self.__name + "_z", 0)) + else: + self.setProperties(self.__name, PropertyFloat(self.__name + "_x", self.__x.giveVal()/s), PropertyFloat(self.__name + "_y", self.__y.giveVal()/s), PropertyFloat(self.__name + "_z", self.__z.giveVal()/s)) + return self + + def __repr__(self): + return f"PropertyVector(name = {self.__name}, x = {self.__x.giveVal()}, y = {self.__y.giveVal()}, z = {self.__z.giveVal()})" \ No newline at end of file