From 0e22614cd2f6cccead88b32ff8d317523c9ed3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Mon, 28 Aug 2023 17:47:41 +0200 Subject: [PATCH] [Core] Minor clean up source files --- kratos/sources/code_location.cpp | 310 +++++++++--------- kratos/sources/communicator.cpp | 9 +- .../bounding_volume_tree.cpp | 18 +- 3 files changed, 168 insertions(+), 169 deletions(-) rename kratos/{sources => spatial_containers}/bounding_volume_tree.cpp (94%) diff --git a/kratos/sources/code_location.cpp b/kratos/sources/code_location.cpp index 94c84662b2bc..0ee9e73dc807 100644 --- a/kratos/sources/code_location.cpp +++ b/kratos/sources/code_location.cpp @@ -4,181 +4,165 @@ // _|\_\_| \__,_|\__|\___/ ____/ // Multi-Physics // -// License: BSD License -// Kratos default license: kratos/license.txt +// License: BSD License +// Kratos default license: kratos/license.txt // -// Main authors: Author1 Pooyan Dadvand +// Main authors: Pooyan Dadvand // -// - // System includes - // External includes - // Project includes #include "includes/code_location.h" #include "includes/checks.h" - namespace Kratos { - CodeLocation::CodeLocation() : - mFileName("Unknown"), mFunctionName("Unknown"), mLineNumber(0) {} - - CodeLocation::CodeLocation(std::string const& FileName, std::string const& FunctionName, std::size_t LineNumber) : - mFileName(FileName), mFunctionName(FunctionName), mLineNumber(LineNumber) {} - - const std::string& CodeLocation::GetFileName() const { - return mFileName; - } - - const std::string& CodeLocation::GetFunctionName() const { - return mFunctionName; - } - - int CodeLocation::GetLineNumber() const { - return mLineNumber; - } - - std::string CodeLocation::CleanFileName() const - { - std::string clean_file_name(mFileName); - ReplaceAll(clean_file_name, "\\", "/"); - - std::size_t kratos_root_position = clean_file_name.rfind("/applications/"); - if (kratos_root_position != std::string::npos) { - clean_file_name.erase(0, kratos_root_position+1); - return clean_file_name; - } - - - if (kratos_root_position == std::string::npos) - kratos_root_position = clean_file_name.rfind("/kratos/"); - if (kratos_root_position != std::string::npos) - clean_file_name.erase(0, kratos_root_position + 1 ); - return clean_file_name; - } - - std::string CodeLocation::CleanFunctionName() const - { - std::string clean_function_name(mFunctionName); - - // Applying filters. Note that The sequence is important - // NOTE: Please add new fliters at the end of the list!! - RemoveNamespace(clean_function_name, "Kratos"); - RemoveNamespace(clean_function_name, "std"); - ReduceTemplateArgumentsToFirstN(clean_function_name, "ublas::vector", 1); - ReduceTemplateArgumentsToFirstN(clean_function_name, "ublas::matrix", 1); - ReduceTemplateArgumentsToFirstN(clean_function_name, "iterators::indirect_iterator", 1); - ReduceTemplateArgumentsToFirstN(clean_function_name, "PointerVectorSet", 1); - ReduceTemplateArgumentsToFirstN(clean_function_name, "basic_string", 1); - ReplaceAll(clean_function_name, "__int64", "int"); - ReplaceAll(clean_function_name, "basic_string", "string"); - ReduceTemplateArgumentsToFirstN(clean_function_name, "compressed_matrix", 0); - ReplaceAll(clean_function_name, "ublas::vector", "Vector"); - ReplaceAll(clean_function_name, "ublas::DenseMatrix", "Matrix"); - ReduceTemplateArgumentsToFirstN(clean_function_name, "ResidualBasedBlockBuilderAndSolver", 1); - ReduceTemplateArgumentsToFirstN(clean_function_name, "ResidualBasedLinearStrategy", 1); - ReplaceAll(clean_function_name, "Dof", "Dof"); - ReplaceAll(clean_function_name, "Node", "Node"); - - - - return clean_function_name; - } - - void CodeLocation::RemoveNamespace(std::string& FunctionName, const std::string& Namespace) - { - std::string namespace_string = Namespace + "::"; - ReplaceAll(FunctionName, namespace_string, ""); - - } - - void CodeLocation::ReduceTemplateArgumentsToFirstN(std::string& FunctionName, const std::string& TemplateName, std::size_t NumberOfArgumentsToKeep) - { - std::size_t start_position = 0; - while ((start_position = FunctionName.find(TemplateName, start_position)) != std::string::npos) { - start_position += TemplateName.size(); - std::size_t template_position = GetNextPositionSkippingWhiteSpaces(FunctionName, start_position); - //if (FunctionName[template_position] == '<') // It is not a template - // continue; - std::string::iterator arguments_iterator = FunctionName.begin() + template_position; - std::size_t number_of_open_pranthesis = 0; - std::size_t number_of_open_templates = 1; - arguments_iterator++; - std::size_t number_of_arguments = 0; - if (*arguments_iterator != '>') - number_of_arguments = 1; - std::size_t replace_position = std::string::npos; - if ((number_of_arguments > NumberOfArgumentsToKeep)) - replace_position = arguments_iterator - FunctionName.begin(); - while (arguments_iterator != FunctionName.end() && number_of_open_templates > 0) - { - if (*arguments_iterator == '<') - number_of_open_templates++; - else if (*arguments_iterator == '>') - number_of_open_templates--; - else if (*arguments_iterator == '(') - number_of_open_pranthesis++; - else if (*arguments_iterator == ')') - number_of_open_pranthesis--; - else if (*arguments_iterator == ',') - { - if (number_of_open_pranthesis == 0 && number_of_open_templates == 1) - number_of_arguments++; - //else - // std::cout << "number_of_open_pranthesis " << number_of_open_pranthesis << "number_of_open_templates" << number_of_open_templates << std::endl; - if ((number_of_arguments > NumberOfArgumentsToKeep) && (replace_position == std::string::npos)) - replace_position = arguments_iterator - FunctionName.begin() + 1; - } - //std::cout << *arguments_iterator; - arguments_iterator++; - - } - if (replace_position != std::string::npos) - { - std::size_t replace_size = arguments_iterator - FunctionName.begin() - 1 - replace_position; - FunctionName.replace(replace_position, replace_size, "..."); - - } - //std::cout << number_of_arguments << " arguments " << std::endl; - } - } - - - - void CodeLocation::ReplaceAll(std::string& ThisString, const std::string& FromString, const std::string& ToString) - { - std::size_t start_position = 0; - while ((start_position = ThisString.find(FromString, start_position)) != std::string::npos) - { - ThisString.replace(start_position, FromString.length(), ToString); - start_position += ToString.length(); // ... - } - - } - - std::size_t CodeLocation::GetNextPositionSkippingWhiteSpaces(std::string const& ThisString, std::size_t Position) - { - char c = ThisString[Position]; - while (IsWhiteSpace(c)) - c = ThisString[++Position]; - return Position; - } - - bool CodeLocation::IsWhiteSpace(char C) - { - return ((C == ' ') || (C == '\t') || (C == '\r') || (C == '\n')); - } - - std::ostream & operator <<(std::ostream& rOStream, - const CodeLocation& Location) - { - rOStream << Location.CleanFileName() << ":" << Location.GetLineNumber() << ": " << Location.CleanFunctionName(); - return rOStream; - } +CodeLocation::CodeLocation() : + mFileName("Unknown"), mFunctionName("Unknown"), mLineNumber(0) {} + +CodeLocation::CodeLocation(std::string const& FileName, std::string const& FunctionName, std::size_t LineNumber) : + mFileName(FileName), mFunctionName(FunctionName), mLineNumber(LineNumber) {} + +const std::string& CodeLocation::GetFileName() const { + return mFileName; +} + +const std::string& CodeLocation::GetFunctionName() const { + return mFunctionName; +} + +int CodeLocation::GetLineNumber() const { + return mLineNumber; +} + +std::string CodeLocation::CleanFileName() const +{ + std::string clean_file_name(mFileName); + ReplaceAll(clean_file_name, "\\", "/"); + + std::size_t kratos_root_position = clean_file_name.rfind("/applications/"); + if (kratos_root_position != std::string::npos) { + clean_file_name.erase(0, kratos_root_position+1); + return clean_file_name; + } + + if (kratos_root_position == std::string::npos) + kratos_root_position = clean_file_name.rfind("/kratos/"); + if (kratos_root_position != std::string::npos) + clean_file_name.erase(0, kratos_root_position + 1 ); + return clean_file_name; +} + +std::string CodeLocation::CleanFunctionName() const +{ + std::string clean_function_name(mFunctionName); + + // Applying filters. Note that The sequence is important + // NOTE: Please add new fliters at the end of the list!! + RemoveNamespace(clean_function_name, "Kratos"); + RemoveNamespace(clean_function_name, "std"); + ReduceTemplateArgumentsToFirstN(clean_function_name, "ublas::vector", 1); + ReduceTemplateArgumentsToFirstN(clean_function_name, "ublas::matrix", 1); + ReduceTemplateArgumentsToFirstN(clean_function_name, "iterators::indirect_iterator", 1); + ReduceTemplateArgumentsToFirstN(clean_function_name, "PointerVectorSet", 1); + ReduceTemplateArgumentsToFirstN(clean_function_name, "basic_string", 1); + ReplaceAll(clean_function_name, "__int64", "int"); + ReplaceAll(clean_function_name, "basic_string", "string"); + ReduceTemplateArgumentsToFirstN(clean_function_name, "compressed_matrix", 0); + ReplaceAll(clean_function_name, "ublas::vector", "Vector"); + ReplaceAll(clean_function_name, "ublas::DenseMatrix", "Matrix"); + ReduceTemplateArgumentsToFirstN(clean_function_name, "ResidualBasedBlockBuilderAndSolver", 1); + ReduceTemplateArgumentsToFirstN(clean_function_name, "ResidualBasedLinearStrategy", 1); + ReplaceAll(clean_function_name, "Dof", "Dof"); + ReplaceAll(clean_function_name, "Node", "Node"); + + return clean_function_name; +} + +void CodeLocation::RemoveNamespace(std::string& FunctionName, const std::string& Namespace) +{ + std::string namespace_string = Namespace + "::"; + ReplaceAll(FunctionName, namespace_string, ""); + +} + +void CodeLocation::ReduceTemplateArgumentsToFirstN(std::string& FunctionName, const std::string& TemplateName, std::size_t NumberOfArgumentsToKeep) +{ + std::size_t start_position = 0; + while ((start_position = FunctionName.find(TemplateName, start_position)) != std::string::npos) { + start_position += TemplateName.size(); + std::size_t template_position = GetNextPositionSkippingWhiteSpaces(FunctionName, start_position); + //if (FunctionName[template_position] == '<') // It is not a template + // continue; + std::string::iterator arguments_iterator = FunctionName.begin() + template_position; + std::size_t number_of_open_parenthesis = 0; + std::size_t number_of_open_templates = 1; + arguments_iterator++; + std::size_t number_of_arguments = 0; + if (*arguments_iterator != '>') + number_of_arguments = 1; + std::size_t replace_position = std::string::npos; + if ((number_of_arguments > NumberOfArgumentsToKeep)) + replace_position = arguments_iterator - FunctionName.begin(); + while (arguments_iterator != FunctionName.end() && number_of_open_templates > 0) { + if (*arguments_iterator == '<') + number_of_open_templates++; + else if (*arguments_iterator == '>') + number_of_open_templates--; + else if (*arguments_iterator == '(') + number_of_open_parenthesis++; + else if (*arguments_iterator == ')') + number_of_open_parenthesis--; + else if (*arguments_iterator == ',') + { + if (number_of_open_parenthesis == 0 && number_of_open_templates == 1) + number_of_arguments++; + if ((number_of_arguments > NumberOfArgumentsToKeep) && (replace_position == std::string::npos)) + replace_position = arguments_iterator - FunctionName.begin() + 1; + } + arguments_iterator++; + + } + if (replace_position != std::string::npos) { + std::size_t replace_size = arguments_iterator - FunctionName.begin() - 1 - replace_position; + FunctionName.replace(replace_position, replace_size, "..."); + + } + } +} + +void CodeLocation::ReplaceAll(std::string& ThisString, const std::string& FromString, const std::string& ToString) +{ + std::size_t start_position = 0; + while ((start_position = ThisString.find(FromString, start_position)) != std::string::npos) + { + ThisString.replace(start_position, FromString.length(), ToString); + start_position += ToString.length(); // ... + } + +} + +std::size_t CodeLocation::GetNextPositionSkippingWhiteSpaces(std::string const& ThisString, std::size_t Position) +{ + char c = ThisString[Position]; + while (IsWhiteSpace(c)) + c = ThisString[++Position]; + return Position; +} + +bool CodeLocation::IsWhiteSpace(char C) +{ + return ((C == ' ') || (C == '\t') || (C == '\r') || (C == '\n')); +} + +std::ostream & operator <<(std::ostream& rOStream, + const CodeLocation& Location) +{ + rOStream << Location.CleanFileName() << ":" << Location.GetLineNumber() << ": " << Location.CleanFunctionName(); + return rOStream; +} } // namespace Kratos. diff --git a/kratos/sources/communicator.cpp b/kratos/sources/communicator.cpp index 1bc092853e60..344a1f84bfe8 100644 --- a/kratos/sources/communicator.cpp +++ b/kratos/sources/communicator.cpp @@ -4,14 +4,19 @@ // _|\_\_| \__,_|\__|\___/ ____/ // Multi-Physics // -// License: BSD License -// Kratos default license: kratos/license.txt +// License: BSD License +// Kratos default license: kratos/license.txt // // Main authors: Pooyan Dadvand // Riccardo Rossi // // +// System includes + +// External includes + +// Project includes #include "includes/communicator.h" #include "includes/data_communicator.h" #include "includes/parallel_environment.h" diff --git a/kratos/sources/bounding_volume_tree.cpp b/kratos/spatial_containers/bounding_volume_tree.cpp similarity index 94% rename from kratos/sources/bounding_volume_tree.cpp rename to kratos/spatial_containers/bounding_volume_tree.cpp index 75d8c70e663b..b84b27a47ff6 100644 --- a/kratos/sources/bounding_volume_tree.cpp +++ b/kratos/spatial_containers/bounding_volume_tree.cpp @@ -1,11 +1,21 @@ // -// Project Name: Kratos -// Last Modified by: $Author: hbui $ -// Date: $Date: 1 Oct 2015 $ -// Revision: $Revision: 1.0 $ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics // +// License: BSD License +// Kratos default license: kratos/license.txt // +// Main authors: hbui +// + +// System includes + +// External includes +// Project includes #include "spatial_containers/bounding_volume_tree.h" namespace Kratos