Skip to content

Commit

Permalink
work on include paths and clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Mar 9, 2024
1 parent 610498c commit a2ccd69
Show file tree
Hide file tree
Showing 85 changed files with 5,442 additions and 5,319 deletions.
60 changes: 60 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignEscapedNewlines: Left
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'false'
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: '160'
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
Cpp11BracedListStyle: 'false'
FixNamespaceComments: 'false'
IncludeBlocks: Regroup
IndentAccessModifiers: 'false'
IndentCaseLabels: 'true'
IndentPPDirectives: None
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: None
PointerAlignment: Left
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never
...
8 changes: 3 additions & 5 deletions examples/multiple_problems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

#include <iostream>


int main() {
int main()
{
// Parse the domain
auto domain_parser = loki::DomainParser("data/gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
Expand All @@ -44,6 +43,5 @@ int main() {
the idexing scheme is most likely fragmented per problem.
(In this specific case, it is not fragmented because both problems are structurally equivalent) */


return 0;
}
51 changes: 28 additions & 23 deletions examples/position_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,38 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

#include <cassert>
#include <iostream>

#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

/// @brief Prints an error message when encourtering an And-Condition.
struct TestUnsupportedAndConditionVisitor {
struct TestUnsupportedAndConditionVisitor
{
const loki::Position position;
const loki::PDDLPositionCache& position_cache;
const loki::PDDLErrorHandler& error_handler;

TestUnsupportedAndConditionVisitor(
const loki::Position position_,
const loki::PDDLPositionCache& position_cache_,
const loki::PDDLErrorHandler& error_handler_)
: position(position_)
, position_cache(position_cache_)
, error_handler(error_handler_) { }
TestUnsupportedAndConditionVisitor(const loki::Position position_,
const loki::PDDLPositionCache& position_cache_,
const loki::PDDLErrorHandler& error_handler_) :
position(position_),
position_cache(position_cache_),
error_handler(error_handler_)
{
}

/// @brief For leaf nodes we do not need to do anything
template<typename Node>
void operator()(const Node&) { }
void operator()(const Node&)
{
}

/// @brief For inner nodes we need to recursively call the visitor
void operator()(const loki::pddl::ConditionOrImpl& node) {
for (const auto& child_node : node.get_conditions()) {
void operator()(const loki::pddl::ConditionOrImpl& node)
{
for (const auto& child_node : node.get_conditions())
{
// We call front() to obtain the first occurence.
const auto child_position = position_cache.get<loki::pddl::ConditionImpl>(child_node).front();
std::visit(TestUnsupportedAndConditionVisitor(child_position, position_cache, error_handler), *child_node);
Expand All @@ -51,15 +55,16 @@ struct TestUnsupportedAndConditionVisitor {

/// @brief For the unsupported And-Condition,
/// we print an clang-style error message and throw an exception.
void operator()(const loki::pddl::ConditionAndImpl&) {
void operator()(const loki::pddl::ConditionAndImpl&)
{
std::cout << error_handler(position, "Your awesome error message.") << std::endl;
throw std::runtime_error("Unexpected And-Condition.");
}
};


/// @brief In this example, we show how to print custom error message for unsupported PDDL types.
int main() {
int main()
{
// Parse the domain
auto domain_parser = loki::DomainParser("data/gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
Expand All @@ -68,16 +73,16 @@ int main() {
const loki::PDDLPositionCache& position_cache = domain_parser.get_position_cache();
const loki::PDDLErrorHandler& error_handler = position_cache.get_error_handler();

for (const auto& action : domain->get_actions()) {
for (const auto& action : domain->get_actions())
{
const auto condition = action->get_condition();
if (!condition.has_value()) {
if (!condition.has_value())
{
continue;
}
// We call front() to obtain the first occurence.
auto condition_position = position_cache.get<loki::pddl::ConditionImpl>(condition.value()).front();
std::visit(
TestUnsupportedAndConditionVisitor(condition_position, position_cache, error_handler),
*condition.value());
std::visit(TestUnsupportedAndConditionVisitor(condition_position, position_cache, error_handler), *condition.value());
}

return 0;
Expand Down
7 changes: 3 additions & 4 deletions examples/single_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

#include <iostream>


int main() {
int main()
{
// Parse the domain
auto domain_parser = loki::DomainParser("data/gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
Expand Down
9 changes: 4 additions & 5 deletions examples/undefined_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

#include <iostream>


/// @brief This example illustrates incorrect ownership handling
int main() {
auto domain = loki::pddl::Domain{nullptr};
int main()
{
auto domain = loki::pddl::Domain { nullptr };
{
// Parse the domain
auto domain_parser = loki::DomainParser("data/gripper/domain.pddl");
Expand Down
12 changes: 6 additions & 6 deletions exe/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <loki/domain/parser.hpp>

#include <iostream>
#include <loki/domain/parser.hpp>


int main(int argc, char** argv) {
if (argc < 2) {
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cout << "Usage: interpreter <domain:str>" << std::endl;
return 1;
}
const auto domain_file = std::string{argv[1]};
const auto domain_file = std::string { argv[1] };

// 1. Parse the domain
const auto domain_parser = loki::DomainParser(domain_file);
Expand Down
14 changes: 7 additions & 7 deletions exe/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <loki/domain/parser.hpp>
#include <loki/problem/parser.hpp>

#include <iostream>


int main(int argc, char** argv) {
if (argc < 3) {
int main(int argc, char** argv)
{
if (argc < 3)
{
std::cout << "Usage: interpreter <domain:str> <problem:str>" << std::endl;
return 1;
}
const auto domain_file = std::string{argv[1]};
const auto problem_file = std::string{argv[2]};
const auto domain_file = std::string { argv[1] };
const auto problem_file = std::string { argv[2] };

// 1. Parse the domain
auto domain_parser = loki::DomainParser(domain_file);
Expand Down
37 changes: 14 additions & 23 deletions include/loki/common/ast/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,33 @@
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>

#include <string>


/// @brief Defines types of our parsers.
/// The configuration is relevant when reusing the parsers instantiated by the library.
namespace loki
{
namespace x3 = boost::spirit::x3;

using Position = x3::position_tagged;
using PositionList = std::vector<Position>;

// Our iterator type
typedef std::string::const_iterator iterator_type;
namespace x3 = boost::spirit::x3;

using Position = x3::position_tagged;
using PositionList = std::vector<Position>;

/* X3 error handler utility */
template <typename Iterator>
using error_handler = x3::error_handler<Iterator>;
// Our iterator type
typedef std::string::const_iterator iterator_type;

using error_handler_tag = x3::error_handler_tag;
/* X3 error handler utility */
template<typename Iterator>
using error_handler = x3::error_handler<Iterator>;

typedef error_handler<iterator_type> error_handler_type;
using error_handler_tag = x3::error_handler_tag;

typedef error_handler<iterator_type> error_handler_type;

/* The phrase parse context */
typedef
x3::phrase_parse_context<x3::ascii::space_type>::type phrase_context_type;
/* The phrase parse context */
typedef x3::phrase_parse_context<x3::ascii::space_type>::type phrase_context_type;

/* Combined error handler, pddl, and phrase parse Context */
typedef x3::context<
error_handler_tag,
std::reference_wrapper<error_handler_type>,
phrase_context_type>
context_type;
/* Combined error handler, pddl, and phrase parse Context */
typedef x3::context<error_handler_tag, std::reference_wrapper<error_handler_type>, phrase_context_type> context_type;
}

#endif
Loading

0 comments on commit a2ccd69

Please sign in to comment.