-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge submodule contents for libpotassco/master
- Loading branch information
Showing
58 changed files
with
26,147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
sudo: false | ||
language: cpp | ||
matrix: | ||
include: | ||
- os: linux | ||
compiler: gcc | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
- george-edison55-precise-backports | ||
packages: | ||
- g++-4.9 | ||
- cmake | ||
- cmake-data | ||
env: | ||
- COMPILER='g++-4.9' | ||
- os: linux | ||
compiler: gcc | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
- george-edison55-precise-backports | ||
packages: | ||
- g++-5 | ||
- cmake | ||
- cmake-data | ||
env: | ||
- COMPILER='g++-5' | ||
- os: osx | ||
osx_image: xcode8 | ||
env: | ||
- COMPILER='clang++' | ||
|
||
install: | ||
- export CMAKE=cmake | ||
- export CXX=$COMPILER | ||
- $CMAKE --version | ||
- $CXX --version | ||
script: | ||
- mkdir $CXX && cd $CXX | ||
- $CMAKE -DCMAKE_CXX_COMPILER=$CXX -DLIB_POTASSCO_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra" ../ | ||
- make -j3 && make test CTEST_OUTPUT_ON_FAILURE=1 | ||
- $CMAKE -DCMAKE_CXX_COMPILER=$CXX -DLIB_POTASSCO_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Wextra" ../ | ||
- make -j3 && make test CTEST_OUTPUT_ON_FAILURE=1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(LIB_POTASSCO VERSION 1.0 LANGUAGES CXX) | ||
if (POLICY CMP0063) | ||
cmake_policy(SET CMP0063 NEW) | ||
endif() | ||
# enable folders in IDEs like Visual Studio | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
||
option(LIB_POTASSCO_BUILD_TESTS "whether or not to build tests" OFF) | ||
option(LIB_POTASSCO_BUILD_APP "whether or not to build lpconvert tool" ON) | ||
option(LIB_POTASSCO_INSTALL_LIB "whether or not to install libpotassco" OFF) | ||
set(include_dest "include/potassco-${LIB_POTASSCO_VERSION}") | ||
set(library_dest "lib/potassco-${LIB_POTASSCO_VERSION}") | ||
|
||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
message(STATUS "No build type selected - using 'Release'") | ||
set(CMAKE_BUILD_TYPE "Release") | ||
endif() | ||
|
||
if (NOT MSVC) | ||
if (NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
endif() | ||
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
else() | ||
set(VC_RELEASE_LINK_OPTIONS /LTCG) | ||
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}") | ||
SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}") | ||
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}") | ||
SET(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}") | ||
endif() | ||
|
||
add_subdirectory(src) | ||
if(LIB_POTASSCO_BUILD_TESTS) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() | ||
if(LIB_POTASSCO_BUILD_APP) | ||
add_subdirectory(app) | ||
endif() | ||
|
||
# optional doc target | ||
find_package(Doxygen) | ||
if(DOXYGEN_FOUND) | ||
set(doxyfile "${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile") | ||
add_custom_target(doc_potassco | ||
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/doc" | ||
COMMENT "Generating documentation..." | ||
VERBATIM) | ||
set_target_properties(doc_potassco PROPERTIES FOLDER doc) | ||
endif() | ||
|
||
# export | ||
configure_file(cmake/potassco-config-version.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/potassco-config-version.cmake | ||
@ONLY) | ||
if(LIB_POTASSCO_INSTALL_LIB) | ||
install(FILES cmake/potassco-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/potassco-config-version.cmake DESTINATION "${library_dest}") | ||
install(EXPORT potassco DESTINATION "${library_dest}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
libpotassco | ||
|
||
Copyright (c) 2015-2017 Benjamin Kaufmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# libpotassco | ||
|
||
[![Build Status master](https://badges.herokuapp.com/travis/potassco/libpotassco?branch=master&label=master)](https://travis-ci.org/potassco/libpotassco?branch=master) | ||
|
||
libpotassco is a small C++ utility library used by various potassco projects | ||
that mostly provides functions and types for | ||
- parsing, writing, and converting logic programs in [aspif][aspif] and smodels format, | ||
- passing information between a grounder and a solver, | ||
- defining and parsing command-line options and for creating command-line applications. | ||
|
||
Furthermore, it comes with the tool `lpconvert` that converts either between aspif and smodels format | ||
or to a human-readable text format. | ||
|
||
libpotassco is part of the potassco project. For further information please visit: | ||
|
||
http://potassco.org/ | ||
|
||
## Installation | ||
|
||
The preferred way to build libpotassco is to use [CMake][cmake] | ||
version 3.1 or later. | ||
|
||
The following options can be used to configure the build: | ||
|
||
LIB_POTASSCO_BUILD_APP : whether or not to build the lpconvert tool | ||
LIB_POTASSCO_BUILD_TESTS: whether or not to build unit tests | ||
|
||
For example, to build libpotassco in release mode in directory `<dir>`: | ||
|
||
cmake -H. -B<dir> | ||
cmake --build <dir> | ||
|
||
The following options can be used to configure the installation: | ||
|
||
CMAKE_INSTALL_PREFIX : install path prefix | ||
LIB_POTASSCO_INSTALL_LIB: whether or not to install libpotassco | ||
|
||
For example, to install lpconvert and libpotassco under `/home/<usr>`: | ||
|
||
cmake -H. -B<dir> -DCMAKE_INSTALL_PREFIX=/home/<usr> -DLIB_POTASSCO_INSTALL_LIB=ON | ||
cmake --build <dir> --target install | ||
|
||
To use libpotassco in a cmake-based project either: | ||
|
||
- Place the library inside your project, e.g. using [git submodules](http://git-scm.com/docs/git-submodule). | ||
- Call `add_subdirectory(<path_to_libpotassco>)`. | ||
|
||
or, if libpotassco is installed in `CMAKE_PREFIX_PATH`: | ||
- Call `find_package(potassco <major>.<minor> CONFIG)`. | ||
|
||
Finally, call `target_link_libraries(your_target PUBLIC potassco)` to link to the potassco library. | ||
|
||
## Documentation | ||
Source code documentation can be generated with [Doxygen][doxygen]. | ||
Either explicitly: | ||
|
||
cd doc/ | ||
doxygen | ||
|
||
or via the `doc_potassco` target when using cmake. | ||
|
||
[aspif]: http://www.cs.uni-potsdam.de/wv/pdfformat/gekakaosscwa16b.pdf "Aspif specification" | ||
[cmake]: https://cmake.org/ | ||
[doxygen]: http://www.stack.nl/~dimitri/doxygen/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_executable(lpconvert lpconvert.cpp) | ||
target_link_libraries(lpconvert libpotassco) | ||
set_target_properties(lpconvert PROPERTIES FOLDER exe) | ||
|
||
install(TARGETS lpconvert EXPORT lpconvert DESTINATION "bin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// | ||
// Copyright (c) 2015-2017 Benjamin Kaufmann | ||
// | ||
// This file is part of Potassco. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to | ||
// deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
// sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
// IN THE SOFTWARE. | ||
// | ||
|
||
#include <potassco/aspif.h> | ||
#include <potassco/aspif_text.h> | ||
#include <potassco/convert.h> | ||
#include <potassco/application.h> | ||
#include <potassco/program_opts/typed_value.h> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <cctype> | ||
#include <cstdlib> | ||
|
||
using namespace Potassco::ProgramOptions; | ||
|
||
class LpConvert : public Potassco::Application { | ||
public: | ||
virtual const char* getName() const { return "lpconvert"; } | ||
virtual const char* getVersion() const { return "1.0.0"; } | ||
virtual PosOption getPositional() const { return &positional; } | ||
virtual const char* getUsage() const { | ||
return | ||
"[options] [<file>]\n" | ||
"Convert program in <file> or standard input"; | ||
} | ||
virtual void initOptions(OptionContext& root); | ||
virtual void validateOptions(const OptionContext&, const ParsedOptions&, const ParsedValues&) {} | ||
virtual void setup() {} | ||
virtual void run(); | ||
virtual void printVersion() { | ||
Potassco::Application::printVersion(); | ||
printf("libpotassco version %s\n", LIB_POTASSCO_VERSION); | ||
printf("Copyright (C) Benjamin Kaufmann\n"); | ||
printf("License: The MIT License <https://opensource.org/licenses/MIT>\n"); | ||
fflush(stdout); | ||
} | ||
private: | ||
static bool positional(const std::string&, std::string& optOut) { | ||
optOut = "input"; | ||
return true; | ||
} | ||
static int error(int line, const char* what) { | ||
fprintf(stderr, "*** ERROR: In line %d: %s\n", line, what); | ||
static_cast<LpConvert*>(Application::getInstance())->exit(EXIT_FAILURE); | ||
return EXIT_FAILURE; | ||
} | ||
std::string input_; | ||
std::string output_; | ||
bool potassco_; | ||
bool filter_; | ||
bool text_; | ||
}; | ||
|
||
void LpConvert::initOptions(OptionContext& root) { | ||
OptionGroup convert("Conversion Options"); | ||
convert.addOptions() | ||
("input,i,@2", storeTo(input_), "Input file") | ||
("potassco,p", flag(potassco_ = false), "Enable potassco extensions") | ||
("filter,f" , flag(filter_ = false), "Hide converted potassco predicates") | ||
("output,o" , storeTo(output_)->arg("<file>"), "Write output to <file> (default: stdout)") | ||
("text,t" , flag(text_ = false), "Convert to ground text format") | ||
; | ||
root.add(convert); | ||
} | ||
void LpConvert::run() { | ||
std::ifstream iFile; | ||
std::ofstream oFile; | ||
if (!input_.empty() && input_ != "-") { | ||
iFile.open(input_.c_str()); | ||
POTASSCO_EXPECT(iFile.is_open(), "Could not open input file!"); | ||
} | ||
if (!output_.empty() && output_ != "-") { | ||
POTASSCO_EXPECT(input_ != output_, "Input and output must be different!"); | ||
oFile.open(output_.c_str()); | ||
POTASSCO_EXPECT(oFile.is_open(), "Could not open output file!"); | ||
} | ||
std::istream& in = iFile.is_open() ? iFile : std::cin; | ||
std::ostream& os = oFile.is_open() ? oFile : std::cout; | ||
Potassco::AspifTextOutput text(os); | ||
POTASSCO_EXPECT(in.peek() == 'a' || std::isdigit(in.peek()), "Unrecognized input format!"); | ||
if (in.peek() == 'a') { | ||
Potassco::SmodelsOutput writer(os, potassco_, 0); | ||
Potassco::SmodelsConvert smodels(writer, potassco_); | ||
Potassco::readAspif(in, !text_ ? static_cast<Potassco::AbstractProgram&>(smodels) : text, &error); | ||
} | ||
else { | ||
Potassco::AspifOutput aspif(os); | ||
Potassco::SmodelsInput::Options opts; | ||
if (potassco_) { | ||
opts.enableClaspExt().convertEdges().convertHeuristic(); | ||
if (filter_) { opts.dropConverted(); } | ||
} | ||
Potassco::readSmodels(in, !text_? static_cast<Potassco::AbstractProgram&>(aspif) : text, &error, opts); | ||
} | ||
iFile.close(); | ||
oFile.close(); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
LpConvert app; | ||
return app.main(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Note: Adapted from Jonathan Müller's blog post on supporting CMake install: | ||
# https://foonathan.github.io/blog/2016/03/03/cmake-install.html | ||
# | ||
# checks version: major must match, minor must be less than or equal | ||
|
||
set(PACKAGE_VERSION @LIB_POTASSCO_VERSION@) | ||
|
||
if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@LIB_POTASSCO_VERSION_MAJOR@") | ||
if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL "@LIB_POTASSCO_VERSION_MINOR@") | ||
set(PACKAGE_VERSION_EXACT TRUE) | ||
elseif(NOT ("@LIB_POTASSCO_VERSION_MAJOR@" EQUAL 0) | ||
AND "${PACKAGE_FIND_VERSION_MINOR}" LESS "@LIB_POTASSCO_VERSION_MINOR@") | ||
set(PACKAGE_VERSION_COMPATIBLE TRUE) | ||
else() | ||
set(PACKAGE_VERSION_UNSUITABLE TRUE) | ||
endif() | ||
else() | ||
set(PACKAGE_VERSION_UNSUITABLE TRUE) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/potassco.cmake") | ||
|
Oops, something went wrong.