├── src ├── cpp │ ├── tests │ │ ├── settings.xml │ │ ├── settings1.xml │ │ ├── settings2.xml │ │ ├── Makefile │ │ └── libparam_test.cpp │ ├── .gitignore │ ├── osx │ │ └── FSEventsFileSystemWatcher.hpp │ ├── windows │ │ └── Win32FileSystemWatcher.hpp │ ├── Makefile │ ├── FileSystemWatcher.hpp │ ├── FileSystemWatcher.cpp │ ├── linux │ │ └── InotifyFileSystemWatcher.hpp │ ├── rapidxml-1.13 │ │ ├── license.txt │ │ ├── rapidxml_utils.hpp │ │ ├── rapidxml_iterators.hpp │ │ └── rapidxml_print.hpp │ ├── paramtuner.h │ ├── paramtuner.cpp │ └── doxygen.conf ├── java │ ├── .gitignore │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ ├── settings_n.xml │ │ │ │ └── settings_o.xml │ │ │ └── java │ │ │ │ └── fr │ │ │ │ └── univ_lille1 │ │ │ │ └── libparamtuner │ │ │ │ └── ParamTunerTest.java │ │ └── main │ │ │ └── java │ │ │ └── fr │ │ │ └── univ_lille1 │ │ │ └── libparamtuner │ │ │ ├── parameters │ │ │ ├── BooleanParameter.java │ │ │ ├── FloatParameter.java │ │ │ ├── IntegerParameter.java │ │ │ ├── StringParameter.java │ │ │ ├── Type.java │ │ │ ├── Parameter.java │ │ │ └── ParameterFile.java │ │ │ ├── FileWatcher.java │ │ │ └── ParamTuner.java │ └── pom.xml └── gui │ ├── src │ └── main │ │ ├── resources │ │ └── icon.png │ │ ├── deploy │ │ └── package │ │ │ ├── ParamTunerGUI.png │ │ │ ├── macosx │ │ │ └── ParamTunerGUI.icns │ │ │ └── windows │ │ │ └── ParamTunerGUI.ico │ │ └── java │ │ └── fr │ │ └── univ_lille1 │ │ └── libparamtuner │ │ └── gui │ │ ├── AtomicUtils.java │ │ ├── Main.java │ │ ├── parameters_panel │ │ ├── BooleanParameterPanel.java │ │ ├── StringParameterPanel.java │ │ ├── FloatParameterPanel.java │ │ ├── IntegerParameterPanel.java │ │ └── ParameterPanel.java │ │ ├── FXDialogUtils.java │ │ └── MainFrame.java │ ├── .gitignore │ ├── settings.xml │ └── pom.xml ├── examples ├── java │ └── square │ │ ├── .gitignore │ │ ├── settings.xml │ │ ├── Makefile │ │ └── Square.java └── cpp │ ├── console │ ├── .gitignore │ ├── settings.xml │ ├── Makefile │ └── console.cpp │ ├── .gitignore │ ├── Qt │ ├── Qtdemo.pro │ ├── main.cpp │ ├── settings.xml │ ├── MyCanvas.h │ └── MyCanvas.cpp │ └── glut │ ├── settings.xml │ ├── Makefile │ ├── glut_without_lib.cpp │ └── glut_with_lib.cpp ├── homebrew ├── settings.xml ├── prepareHomebrewArchive ├── simpletest.cpp └── Makefile ├── .gitignore ├── COPYING ├── Readme.md └── LICENSE /src/cpp/tests/settings.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/cpp/tests/settings1.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/cpp/tests/settings2.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/java/square/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.jar 3 | 4 | -------------------------------------------------------------------------------- /examples/cpp/console/.gitignore: -------------------------------------------------------------------------------- 1 | # Executable 2 | console 3 | -------------------------------------------------------------------------------- /examples/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | *.o 3 | *.a 4 | *.exe 5 | -------------------------------------------------------------------------------- /src/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | *.o 3 | 4 | # Executables 5 | *.so* 6 | *.a 7 | *.exe 8 | -------------------------------------------------------------------------------- /src/cpp/tests/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | g++ libparam_test.cpp -o libparam_test -L../ -lparamtuner -lgtest -lpthread -g 3 | -------------------------------------------------------------------------------- /src/java/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Maven 3 | /target/ 4 | 5 | # Eclipse projects 6 | .settings 7 | .classpath 8 | .project 9 | -------------------------------------------------------------------------------- /src/gui/src/main/resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/gui/src/main/resources/icon.png -------------------------------------------------------------------------------- /src/cpp/osx/FSEventsFileSystemWatcher.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/cpp/osx/FSEventsFileSystemWatcher.hpp -------------------------------------------------------------------------------- /src/cpp/windows/Win32FileSystemWatcher.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/cpp/windows/Win32FileSystemWatcher.hpp -------------------------------------------------------------------------------- /src/gui/src/main/deploy/package/ParamTunerGUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/gui/src/main/deploy/package/ParamTunerGUI.png -------------------------------------------------------------------------------- /src/gui/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Maven 3 | /target/ 4 | dependency-reduced-pom.xml 5 | 6 | # Eclipse projects 7 | .settings 8 | .classpath 9 | .project 10 | -------------------------------------------------------------------------------- /src/gui/src/main/deploy/package/macosx/ParamTunerGUI.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/gui/src/main/deploy/package/macosx/ParamTunerGUI.icns -------------------------------------------------------------------------------- /src/gui/src/main/deploy/package/windows/ParamTunerGUI.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casiez/libparamtuner/HEAD/src/gui/src/main/deploy/package/windows/ParamTunerGUI.ico -------------------------------------------------------------------------------- /src/java/src/test/resources/settings_n.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/cpp/Qt/Qtdemo.pro: -------------------------------------------------------------------------------- 1 | # 2 | # Authors: Géry Casiez 3 | # 4 | 5 | TEMPLATE = app 6 | 7 | QT += widgets gui 8 | 9 | INCLUDEPATH += ../../../src/cpp/ 10 | LIBS += -L../../../src/cpp/ -lparamtuner -framework CoreServices 11 | 12 | HEADERS += MyCanvas.h 13 | SOURCES += main.cpp MyCanvas.cpp 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /homebrew/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS generated files # 2 | ###################### 3 | .DS_Store 4 | .DS_Store? 5 | ehthumbs.db 6 | Icon? 7 | Thumbs.db 8 | 9 | # App generated files # 10 | ###################### 11 | # Vim 12 | *.swp 13 | 14 | # Kate 15 | *.kate-swp 16 | 17 | # Dolphin 18 | .directory 19 | 20 | # Folder ignore # 21 | ################# 22 | doc 23 | -------------------------------------------------------------------------------- /examples/cpp/console/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/cpp/Qt/main.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: c++ -*- 2 | * 3 | * 4 | * Authors: Géry Casiez 5 | * 6 | * 7 | */ 8 | 9 | #include 10 | 11 | #include "MyCanvas.h" 12 | 13 | int main(int argc, char **argv) 14 | { 15 | QApplication app (argc, argv); 16 | 17 | MyCanvas myCanvas; 18 | myCanvas.show(); 19 | 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/java/square/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/AtomicUtils.java: -------------------------------------------------------------------------------- 1 | package fr.univ_lille1.libparamtuner.gui; 2 | 3 | import java.util.concurrent.atomic.AtomicBoolean; 4 | 5 | public class AtomicUtils { 6 | 7 | public static void waitForValue(AtomicBoolean a, boolean wantedValue, long interval) throws InterruptedException { 8 | while(a.get() != wantedValue) { 9 | Thread.sleep(interval); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /examples/cpp/Qt/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/cpp/glut/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/gui/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | BLACK 7 | WHITE 8 | RED 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /homebrew/prepareHomebrewArchive: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEST=libparamtuner-1.2 4 | DEST2=homebrew/$DEST 5 | 6 | rm -rf $DEST 7 | mkdir $DEST 8 | mkdir $DEST/lib 9 | mkdir $DEST/test 10 | cd .. 11 | cp COPYING LICENSE $DEST2/ 12 | cp src/cpp/FileSystemWatcher.cpp $DEST2/ 13 | cp src/cpp/FileSystemWatcher.hpp $DEST2/ 14 | cp src/cpp/paramtuner.cpp $DEST2/ 15 | cp src/cpp/paramtuner.h $DEST2/ 16 | cp -r src/cpp/rapidxml-1.13 $DEST2/ 17 | cp -r src/cpp/osx $DEST2/ 18 | cd homebrew 19 | cp Makefile $DEST/ 20 | cp settings.xml $DEST/test/ 21 | cp simpletest.cpp $DEST/test/ -------------------------------------------------------------------------------- /src/java/src/test/resources/settings_o.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/cpp/Qt/MyCanvas.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: c++ -*- 2 | * 3 | * MyCanvas.h -- 4 | * 5 | * Authors: Géry Casiez 6 | * 7 | * 8 | */ 9 | 10 | #ifndef MyCanvas_h 11 | #define MyCanvas_h 12 | 13 | 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | class MyCanvas : public QWidget { 20 | 21 | Q_OBJECT ; 22 | 23 | string s; 24 | int x, y, fontsize; 25 | double angle; 26 | bool toggleColor; 27 | 28 | protected: 29 | 30 | void paintEvent(QPaintEvent *event) ; 31 | 32 | public: 33 | 34 | explicit MyCanvas(QWidget *parent=0) ; 35 | 36 | void update() ; 37 | 38 | ~MyCanvas(void) ; 39 | 40 | } ; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /homebrew/simpletest.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int 8 | main(int argc, char **argv) { 9 | double varDouble = 2.0; 10 | int varInt = 1; 11 | bool varBool = false; 12 | string varString; 13 | 14 | ParamTuner::load("test/settings.xml"); 15 | ParamTuner::bind("setting1", &varDouble); 16 | ParamTuner::bind("setting2", &varInt); 17 | ParamTuner::bind("mybool", &varBool); 18 | ParamTuner::bind("mystring", &varString); 19 | 20 | cout << "setting1 (double) = " << varDouble 21 | << " ; setting2 (int) = " << varInt 22 | << " ; mybool (bool) = " << varBool 23 | << " ; mystring (string) = " << varString 24 | << endl; 25 | 26 | return 0 ; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Gery Casiez, Marc Baloup, Veïs Oudjail 4 | * 5 | * https://github.com/casiez/libparamtuner/ 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | -------------------------------------------------------------------------------- /src/java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | fr.univ_lille1.libparamtuner 5 | libParamTuner 6 | 0.0.1-SNAPSHOT 7 | jar 8 | 9 | libParamTuner 10 | 11 | 12 | 1.8 13 | 1.8 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.12 22 | test 23 | 24 | 25 | 26 | 27 | ${project.artifactId} 28 | 29 | -------------------------------------------------------------------------------- /src/cpp/tests/libparam_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../paramtuner.h" 4 | 5 | 6 | TEST(ParamTunerTest, checkValidFileLoad) 7 | { 8 | EXPECT_EQ( ParamTuner::load("settings.xml"), 0 ) ; 9 | } 10 | 11 | TEST(ParamTunerTest, checkSlowDoubleDifferentFilesLoad_OpenIssue) 12 | { 13 | sleep(1); 14 | EXPECT_EQ( ParamTuner::load("settings1.xml"), 0 ) ; 15 | sleep(1); 16 | EXPECT_EQ( ParamTuner::load("settings2.xml"), 0 ) ; 17 | } 18 | 19 | 20 | TEST(ParamTunerTest, checkDoubleDifferentFilesLoad_OpenIssue) 21 | { 22 | EXPECT_EQ( ParamTuner::load("settings1.xml"), 0 ) ; 23 | EXPECT_EQ( ParamTuner::load("settings2.xml"), 0 ) ; 24 | } 25 | 26 | TEST(ParamTunerTest, checkDoubleLoad_OpenIssue) 27 | { 28 | EXPECT_EQ( ParamTuner::load("settings.xml"), 0 ) ; 29 | EXPECT_EQ( ParamTuner::load("settings.xml"), 0 ) ; 30 | } 31 | 32 | TEST(ParamTunerTest, checkInvalidFileLoad_OpenIssue) 33 | { 34 | EXPECT_EQ( ParamTuner::load("notexistingfile.xml"), -1 ) ; 35 | } 36 | 37 | int main(int argc, char **argv) { 38 | ::testing::InitGoogleTest(&argc, argv); 39 | return RUN_ALL_TESTS(); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/java/square/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # libParamTuner 3 | # Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(OS),Windows_NT) 20 | CP_SEP = ; 21 | else 22 | CP_SEP = : 23 | endif 24 | 25 | 26 | all: exec 27 | 28 | %.class: %.java 29 | javac -cp libParamTuner.jar $< 30 | 31 | clean: 32 | rm -f $(TARGETS) *.class *.jar 33 | 34 | 35 | .PHONY: clean all exec 36 | 37 | libParamTuner.jar: 38 | cd ../../../src/java && mvn install && cp target/libParamTuner.jar ../../examples/java/square 39 | 40 | 41 | exec: libParamTuner.jar Square.class 42 | java -cp "libParamTuner.jar$(CP_SEP)." Square -------------------------------------------------------------------------------- /examples/cpp/Qt/MyCanvas.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MyCanvas.cpp -- 4 | * 5 | * Authors: Géry Casiez 6 | * 7 | * 8 | */ 9 | 10 | #include "MyCanvas.h" 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | MyCanvas::MyCanvas(QWidget *parent) : QWidget(parent) { 18 | setGeometry(0,0,800,600); 19 | 20 | ParamTuner::load("settings.xml"); 21 | ParamTuner::bind("s", &s); 22 | ParamTuner::bind("x", &x); 23 | ParamTuner::bind("y", &y); 24 | ParamTuner::bind("fontsize", &fontsize); 25 | ParamTuner::bind("angle", &angle); 26 | ParamTuner::bind("toggle", &toggleColor); 27 | 28 | QTimer *timer = new QTimer(this); 29 | connect(timer, SIGNAL(timeout()), this, SLOT(update())); 30 | timer->start(16); 31 | } 32 | 33 | void MyCanvas::update() { 34 | this->repaint(); 35 | } 36 | 37 | void MyCanvas::paintEvent(QPaintEvent * /*event*/) { 38 | QPainter painter(this) ; 39 | 40 | QFont font = painter.font() ; 41 | font.setPointSize(fontsize); 42 | painter.setFont(font); 43 | if (toggleColor) 44 | painter.setPen(Qt::red); 45 | else 46 | painter.setPen(Qt::black); 47 | painter.translate(QPoint(x, y)); 48 | painter.rotate(angle); 49 | painter.drawText(QPoint(0, 0), QString::fromStdString(s)); 50 | } 51 | 52 | MyCanvas::~MyCanvas() { 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/cpp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # libParamTuner 3 | # Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | CXX = g++ 19 | AR = ar cqs 20 | 21 | TARGET_LIB = libparamtuner.a 22 | 23 | CPPFLAGS = -std=c++11 -Wall -Wextra 24 | 25 | ifeq ($(OS),Windows_NT) 26 | CPPFLAGS += -DUNICODE 27 | endif 28 | 29 | 30 | DOCDIR = ../../doc/cpp 31 | 32 | 33 | all: $(TARGET_LIB) 34 | 35 | doc: 36 | mkdir -p $(DOCDIR) && doxygen doxygen.conf 37 | 38 | %.o: %.cpp 39 | $(CXX) -c $(CPPFLAGS) $(LDINCS) -o $@ $< 40 | 41 | 42 | $(TARGET_LIB): paramtuner.o FileSystemWatcher.o 43 | $(AR) $@ $^ 44 | 45 | clean: 46 | rm -rf $(TARGET_LIB) *.o *.exe $(DOCDIR) 47 | 48 | .PHONY: clean all doc 49 | 50 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui; 19 | 20 | import java.awt.GraphicsEnvironment; 21 | 22 | import javafx.application.Application; 23 | 24 | public class Main { 25 | 26 | public static void main(String[] args) { 27 | 28 | boolean headless = GraphicsEnvironment.isHeadless(); 29 | 30 | if (headless) { 31 | System.err.println("Headless mode not supported (need graphical environment)."); 32 | System.exit(1); 33 | } 34 | 35 | Application.launch(MainFrame.class, args); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /homebrew/Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | DESTDIR ?= 3 | 4 | LIBPARAMTUNER = libparamtuner.dylib 5 | 6 | HEADERS = FileSystemWatcher.hpp paramtuner.h osx/FSEventsFileSystemWatcher.hpp rapidxml-1.13/rapidxml_iterators.hpp rapidxml-1.13/rapidxml_print.hpp rapidxml-1.13/rapidxml_utils.hpp rapidxml-1.13/rapidxml.hpp 7 | 8 | SOURCES = FileSystemWatcher.cpp paramtuner.cpp 9 | 10 | CXX ?= g++ 11 | CXXFLAGS := -mmacosx-version-min=10.7 -std=c++11 -stdlib=libc++ 12 | LIBS = -framework CoreServices 13 | 14 | OBJECTS = $(SOURCES:.cpp=.o) 15 | 16 | all: lib/$(LIBPARAMTUNER) 17 | 18 | lib/$(LIBPARAMTUNER): $(OBJECTS) 19 | $(CXX) -dynamiclib -install_name $(PREFIX)/lib/$(LIBPARAMTUNER) -o $@ $^ $(LDFLAGS) $(LIBS) 20 | 21 | test/simpletest: test/simpletest.cpp 22 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) -lparamtuner 23 | 24 | test: lib/$(LIBPARAMTUNER) test/simpletest 25 | test/simpletest 26 | clean: 27 | rm -f $(OBJECTS) 28 | distclean: clean 29 | rm -f lib/$(LIBPARAMTUNER) 30 | install: 31 | mkdir -p $(PREFIX)/include 32 | cp paramtuner.h $(PREFIX)/include 33 | mkdir -p $(PREFIX)/lib 34 | cp -r lib $(PREFIX) 35 | uninstall: 36 | rm -rf $(PREFIX)/include/paramtuner.h 37 | rm -f $(PREFIX)/lib/$(LIBPARAMTUNER) 38 | tarball: distclean 39 | cd .. && tar cvzf libparamtuner-mac-1.2.tar.gz libparamtuner-1.2/ 40 | openssl dgst -sha256 ../libparamtuner-mac-1.2.tar.gz 41 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/BooleanParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import org.w3c.dom.Element; 21 | 22 | public class BooleanParameter extends Parameter { 23 | 24 | public BooleanParameter(String n, boolean v) { 25 | super(n); 26 | setValue(v); 27 | } 28 | 29 | /* package */ BooleanParameter(Element el) { 30 | super(el); 31 | } 32 | 33 | public void setValue(boolean v) { 34 | value = Boolean.toString(v); 35 | } 36 | 37 | public boolean getValue() { 38 | return Boolean.parseBoolean(value); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/cpp/FileSystemWatcher.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef FILE_SYSTEM_WATCHER_HPP 19 | #define FILE_SYSTEM_WATCHER_HPP 20 | 21 | #include 22 | 23 | 24 | 25 | class FileSystemWatcher { 26 | 27 | private: 28 | std::string path; 29 | void (*callback)(void); 30 | 31 | protected: 32 | virtual void update() = 0; 33 | FileSystemWatcher(const std::string &path, void (*callback)(void)); 34 | void receiveSignal(); 35 | 36 | public: 37 | virtual ~FileSystemWatcher() {} 38 | 39 | std::string getPath() const; 40 | 41 | static FileSystemWatcher* createFileSystemWatcher(const std::string &path, void (*callback)(void)); 42 | }; 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/FloatParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import org.w3c.dom.Element; 21 | 22 | public class FloatParameter extends Parameter { 23 | 24 | public FloatParameter(String n, double v, double m, double M) { 25 | super(n, m, M); 26 | setValue(v); 27 | } 28 | 29 | public FloatParameter(String n, double v) { 30 | this(n, v, 0, 0); 31 | } 32 | 33 | /* package */ FloatParameter(Element el) { 34 | super(el); 35 | } 36 | 37 | public void setValue(double v) { 38 | value = Double.toString(v); 39 | } 40 | 41 | public double getValue() { 42 | return Double.parseDouble(value); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/IntegerParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import org.w3c.dom.Element; 21 | 22 | public class IntegerParameter extends Parameter { 23 | 24 | public IntegerParameter(String n, long v, long m, long M) { 25 | super(n, m, M); 26 | setValue(v); 27 | } 28 | 29 | public IntegerParameter(String n, long v) { 30 | this(n, v, 0, 0); 31 | } 32 | 33 | /* package */ IntegerParameter(Element el) { 34 | super(el); 35 | } 36 | 37 | public void setValue(long v) { 38 | value = Long.toString(v); 39 | } 40 | 41 | public long getValue() { 42 | return Long.parseLong(value); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /examples/cpp/console/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # libParamTuner 3 | # Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | CXX = g++ 19 | 20 | TARGETS = console \ 21 | 22 | 23 | CPPFLAGS = -std=c++11 -Wall -Wextra -Wno-unused-parameter 24 | 25 | ifeq ($(OS),Windows_NT) 26 | CPPFLAGS += -DUNICODE 27 | endif 28 | 29 | ifeq ($(shell uname),Darwin) 30 | CPPFLAGS += -framework CoreServices 31 | endif 32 | 33 | LDINCS = -I../../../src/cpp 34 | 35 | all: $(TARGETS) 36 | 37 | %.o: %.cpp 38 | $(CXX) -c $(CPPFLAGS) $(LDINCS) -o $@ $< 39 | 40 | 41 | clean: 42 | rm -f $(TARGETS) *.o *.exe *.a 43 | 44 | 45 | .PHONY: clean all 46 | 47 | libparamtuner.a: 48 | cd ../../../src/cpp && make libparamtuner.a && cp libparamtuner.a ../../examples/cpp/console/ 49 | 50 | # targets 51 | console: libparamtuner.a console.o 52 | $(CXX) $(CPPFLAGS) -o $@ console.o -L. -lparamtuner -lpthread 53 | 54 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/parameters_panel/BooleanParameterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui.parameters_panel; 19 | 20 | import fr.univ_lille1.libparamtuner.gui.MainFrame; 21 | import fr.univ_lille1.libparamtuner.parameters.BooleanParameter; 22 | import javafx.scene.control.CheckBox; 23 | 24 | public class BooleanParameterPanel extends ParameterPanel { 25 | 26 | public BooleanParameterPanel(MainFrame f, int index, BooleanParameter p) { 27 | super(f, index, p); 28 | 29 | CheckBox box = new CheckBox("Boolean value"); 30 | box.setSelected(p.getValue()); 31 | box.selectedProperty().addListener((o, old, newValue) -> { 32 | p.setValue(newValue); 33 | notifyContentModification(); 34 | }); 35 | box.setBackground(getBackground()); 36 | add(box); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/cpp/console/console.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: c++ -*- 2 | * 3 | * libParamTuner 4 | * Copyright (C) 2017 Gery Casiez, Marc Baloup, Veïs Oudjail 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include "paramtuner.h" 23 | 24 | #ifdef _WIN32 25 | # include 26 | # define SLEEP(ms) (Sleep(ms)) 27 | #else 28 | # include 29 | # define SLEEP(ms) (usleep(ms * 1000)) 30 | #endif 31 | 32 | using namespace std; 33 | 34 | int main() { 35 | double varDouble = 2.0; 36 | int varInt = 1; 37 | bool varBool = false; 38 | string varString; 39 | 40 | ParamTuner::load("settings.xml"); 41 | ParamTuner::bind("setting1", &varDouble); 42 | ParamTuner::bind("setting2", &varInt); 43 | ParamTuner::bind("mybool", &varBool); 44 | ParamTuner::bind("mystring", &varString); 45 | 46 | while (true) { 47 | SLEEP(500); // 500 ms 48 | cout << "setting1 (double) = " << varDouble 49 | << " ; setting2 (int) = " << varInt 50 | << " ; mybool (bool) = " << varBool 51 | << " ; mystring (string) = " << varString 52 | << endl; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/cpp/glut/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # libParamTuner 3 | # Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | CXX = g++ 19 | 20 | TARGETS = glut_without_lib glut_with_lib 21 | 22 | 23 | CPPFLAGS = -std=c++11 -Wall -Wextra -Wno-unused-parameter 24 | LDFLAGS = -lfreeglut -lopengl32 25 | 26 | ifeq ($(OS),Windows_NT) 27 | CPPFLAGS += -DUNICODE 28 | endif 29 | 30 | ifeq ($(shell uname),Darwin) 31 | LDFLAGS = -lglut -framework OpenGL 32 | CPPFLAGS += -framework CoreServices 33 | endif 34 | 35 | ifeq ($(shell uname), Linux) 36 | LDFLAGS = -lglut -lGL 37 | endif 38 | 39 | LDINCS = -I../../../src/cpp 40 | 41 | all: $(TARGETS) 42 | 43 | %.o: %.cpp 44 | $(CXX) -c $(CPPFLAGS) $(LDINCS) -o $@ $< 45 | 46 | 47 | clean: 48 | rm -f $(TARGETS) *.o *.exe *.a 49 | 50 | 51 | .PHONY: clean all 52 | 53 | libparamtuner.a: 54 | cd ../../../src/cpp && make libparamtuner.a 55 | cp ../../../src/cpp/libparamtuner.a ./ 56 | 57 | # targets 58 | glut_with_lib: libparamtuner.a glut_with_lib.o 59 | $(CXX) $(CPPFLAGS) -o $@ glut_with_lib.o $(LDFLAGS) -lparamtuner -lpthread -L. 60 | 61 | glut_without_lib: glut_without_lib.o 62 | $(CXX) $(CPPFLAGS) -o $@ glut_without_lib.o -L. $(LDFLAGS) 63 | -------------------------------------------------------------------------------- /src/cpp/FileSystemWatcher.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "FileSystemWatcher.hpp" 19 | 20 | 21 | #if defined __linux__ 22 | #include "linux/InotifyFileSystemWatcher.hpp" 23 | #elif defined __APPLE__ 24 | #include "osx/FSEventsFileSystemWatcher.hpp" 25 | #elif defined _WIN32 26 | #include "windows/Win32FileSystemWatcher.hpp" 27 | #endif 28 | 29 | #include 30 | 31 | using namespace std; 32 | 33 | 34 | /* 35 | * FileSystemWatcher implementation 36 | */ 37 | FileSystemWatcher::FileSystemWatcher(const string &path, void (*callback)(void)) : 38 | path(path), 39 | callback(callback) { 40 | } 41 | void FileSystemWatcher::receiveSignal() { 42 | update(); 43 | callback(); 44 | } 45 | string FileSystemWatcher::getPath() const { 46 | return path; 47 | } 48 | 49 | /* static method */ 50 | FileSystemWatcher* FileSystemWatcher::createFileSystemWatcher(const std::string &path, void (*callback)(void)) { 51 | 52 | #if defined __linux__ 53 | return new InotifyFileSystemWatcher(path, callback); 54 | #elif defined __APPLE__ 55 | return new FSEventsFileSystemWatcher(path, callback); 56 | #elif defined _WIN32 57 | return new Win32FileSystemWatcher(path, callback); 58 | #else 59 | #error "operating system not supported" 60 | #endif 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /examples/cpp/glut/glut_without_lib.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* Modified by Marc Baloup for libParamTuner examples */ 3 | 4 | /* Copyright (c) Mark J. Kilgard, 1996. */ 5 | 6 | /* This program is freely distributable without licensing fees 7 | and is provided without guarantee or warrantee expressed or 8 | implied. This program is -not- in the public domain. */ 9 | 10 | /* X compile line: cc -o simple simple.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */ 11 | 12 | #include 13 | #ifdef _WIN32 14 | # include 15 | # define SLEEP(ms) (Sleep(ms)) 16 | #else 17 | # include 18 | # define SLEEP(ms) (usleep(ms * 1000)) 19 | #endif 20 | 21 | using namespace std; 22 | 23 | void reshape(int w, int h) 24 | { 25 | glViewport(0, 0, w, h); /* Establish viewing area to cover entire window. */ 26 | glMatrixMode(GL_PROJECTION); /* Start modifying the projection matrix. */ 27 | glLoadIdentity(); /* Reset project matrix. */ 28 | glOrtho(0, w, 0, h, -1, 1); /* Map abstract coords directly to window coords. */ 29 | glScalef(1, -1, 1); /* Invert Y axis so increasing Y goes down. */ 30 | glTranslatef(0, -h, 0); /* Shift origin up to upper-left corner. */ 31 | } 32 | 33 | long ttime = 0; 34 | long targetDeltaTime = 33; // 30 FPS = 33 ms/frame 35 | 36 | 37 | double x1 = 0, 38 | y1 = 0, 39 | x2 = 200, 40 | y2 = 200, 41 | x3 = 20, 42 | y3 = 200; 43 | 44 | void display(void) 45 | { 46 | glClear(GL_COLOR_BUFFER_BIT); 47 | glBegin(GL_TRIANGLES); 48 | glColor3f(0.0, 0.0, 1.0); /* blue */ 49 | glVertex2i(x1, y1); 50 | glColor3f(0.0, 1.0, 0.0); /* green */ 51 | glVertex2i(x2, y2); 52 | glColor3f(1.0, 0.0, 0.0); /* red */ 53 | glVertex2i(x3, y3); 54 | glEnd(); 55 | glFlush(); /* Single buffered, so needs a flush. */ 56 | } 57 | 58 | 59 | void update() { 60 | long currTime = glutGet(GLUT_ELAPSED_TIME); 61 | if (currTime < ttime + targetDeltaTime) { 62 | SLEEP(ttime + targetDeltaTime - currTime); 63 | } 64 | ttime += targetDeltaTime; 65 | display(); 66 | } 67 | 68 | int main(int argc, char **argv) 69 | { 70 | glutInit(&argc, argv); 71 | glutCreateWindow("Single Triangle - libParamTuner examples"); 72 | glutDisplayFunc(display); 73 | glutReshapeFunc(reshape); 74 | glutIdleFunc(update); 75 | glutMainLoop(); 76 | return 0; 77 | } -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/parameters_panel/StringParameterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui.parameters_panel; 19 | 20 | import java.util.List; 21 | 22 | import fr.univ_lille1.libparamtuner.gui.MainFrame; 23 | import fr.univ_lille1.libparamtuner.parameters.StringParameter; 24 | import javafx.beans.value.ChangeListener; 25 | import javafx.collections.FXCollections; 26 | import javafx.scene.control.ComboBox; 27 | import javafx.scene.control.TextArea; 28 | import javafx.scene.layout.HBox; 29 | import javafx.scene.layout.Priority; 30 | 31 | public class StringParameterPanel extends ParameterPanel { 32 | 33 | public StringParameterPanel(MainFrame f, int index, StringParameter p) { 34 | super(f, index, p); 35 | 36 | List possibleValues = p.getPossibleValues(); 37 | if (possibleValues.isEmpty()) { 38 | // no predefined values 39 | 40 | TextArea textArea = new TextArea(p.getValue()); 41 | textArea.setPrefWidth(20); 42 | textArea.textProperty().addListener((ChangeListener) ((observable, old, newText) -> { 43 | p.setValue(newText); 44 | notifyContentModification(); 45 | })); 46 | add(textArea); 47 | HBox.setHgrow(textArea, Priority.ALWAYS); 48 | } 49 | else { 50 | // at least one predefined value 51 | ComboBox box = new ComboBox<>(FXCollections.observableList(possibleValues)); 52 | 53 | // user can always set custom value if he want (just write in the combo box) 54 | box.setEditable(true); 55 | 56 | box.setValue(p.getValue()); // the current value may not be in the list of predefined values 57 | 58 | box.valueProperty().addListener((observable, old, newText) -> { 59 | p.setValue(newText); 60 | notifyContentModification(); 61 | }); 62 | add(box); 63 | } 64 | 65 | 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/cpp/linux/InotifyFileSystemWatcher.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef INOTIFY_FILE_SYSTEM_WATCHER_HPP 19 | #define INOTIFY_FILE_SYSTEM_WATCHER_HPP 20 | 21 | #include "../FileSystemWatcher.hpp" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define EVENT_SIZE (sizeof(struct inotify_event)) 30 | #define EVENT_BUF_LEN (1024*(EVENT_SIZE+16)) 31 | 32 | 33 | class InotifyFileSystemWatcher : public FileSystemWatcher { 34 | 35 | protected: 36 | 37 | int inotifyFileDesc; 38 | int inotifyListenerDesc; 39 | std::thread watcherThread; 40 | bool end = false; 41 | 42 | virtual void update() { 43 | inotify_rm_watch(inotifyFileDesc, inotifyListenerDesc); 44 | inotifyListenerDesc = inotify_add_watch(inotifyFileDesc, FileSystemWatcher::getPath().c_str(), IN_MODIFY); 45 | } 46 | 47 | 48 | void async() { 49 | if (inotifyFileDesc < 0) { 50 | perror("inotify_init"); 51 | return; 52 | } 53 | int length; 54 | char buffer[EVENT_BUF_LEN]; 55 | while ((length = read(inotifyFileDesc, buffer, EVENT_BUF_LEN)) > 0 && !end) { 56 | int i = 0; 57 | while (i < length) { 58 | struct inotify_event *event = (struct inotify_event *) &buffer[i]; 59 | FileSystemWatcher::receiveSignal(); 60 | i += EVENT_SIZE + event->len; 61 | } 62 | } 63 | 64 | } 65 | 66 | public: 67 | InotifyFileSystemWatcher(const std::string &path, void (*callback)(void)) : 68 | FileSystemWatcher(path, callback), 69 | inotifyFileDesc(inotify_init()), 70 | inotifyListenerDesc(inotify_add_watch(inotifyFileDesc, path.c_str(), IN_MODIFY)), 71 | watcherThread(&InotifyFileSystemWatcher::async, this) 72 | { 73 | } 74 | 75 | virtual ~InotifyFileSystemWatcher() { 76 | end = true; 77 | inotify_rm_watch(inotifyFileDesc, inotifyListenerDesc); 78 | close(inotifyFileDesc); 79 | watcherThread.join(); 80 | } 81 | 82 | 83 | 84 | 85 | }; 86 | 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/StringParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | import org.w3c.dom.Document; 25 | import org.w3c.dom.Element; 26 | import org.w3c.dom.Node; 27 | import org.w3c.dom.NodeList; 28 | 29 | public class StringParameter extends Parameter { 30 | 31 | private List values = new ArrayList<>(); 32 | 33 | public StringParameter(String n, String v, String... possibleValues) { 34 | super(n); 35 | setValue(v); 36 | 37 | for (String pV : possibleValues) { 38 | if (pV != null) 39 | values.add(pV); 40 | } 41 | 42 | } 43 | 44 | /* package */ StringParameter(Element el) { 45 | super(el); 46 | 47 | NodeList valueNodes = el.getChildNodes(); 48 | for (int i = 0; i < valueNodes.getLength(); i++) { 49 | Node n = valueNodes.item(i); 50 | if (n.getNodeType() != Node.ELEMENT_NODE) 51 | continue; 52 | Element valueEl = (Element) n; 53 | if (!valueEl.getTagName().equalsIgnoreCase("value")) 54 | continue; 55 | String v = valueEl.getTextContent(); 56 | if (v != null) 57 | values.add(v); 58 | } 59 | 60 | } 61 | 62 | public void setValue(String v) { 63 | if (v == null) 64 | throw new IllegalArgumentException("value can't be null"); 65 | value = v; 66 | } 67 | 68 | public String getValue() { 69 | return value; 70 | } 71 | 72 | 73 | public List getPossibleValues() { 74 | return Collections.unmodifiableList(values); 75 | } 76 | 77 | 78 | 79 | @Override 80 | /* package */ Element toXMLElement(Document doc) { 81 | Element el = super.toXMLElement(doc); 82 | for (String value : values) { 83 | Element valueEl = doc.createElement("value"); 84 | valueEl.appendChild(doc.createTextNode(value)); 85 | el.appendChild(valueEl); 86 | } 87 | return el; 88 | } 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /examples/cpp/glut/glut_with_lib.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* Modified by Marc Baloup for libParamTuner examples */ 3 | 4 | /* Copyright (c) Mark J. Kilgard, 1996. */ 5 | 6 | /* This program is freely distributable without licensing fees 7 | and is provided without guarantee or warrantee expressed or 8 | implied. This program is -not- in the public domain. */ 9 | 10 | /* X compile line: cc -o simple simple.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */ 11 | 12 | #include 13 | #ifdef _WIN32 14 | # include 15 | # define SLEEP(ms) (Sleep(ms)) 16 | #else 17 | # include 18 | # define SLEEP(ms) (usleep(ms * 1000)) 19 | #endif 20 | 21 | #include 22 | #include "paramtuner.h" 23 | 24 | using namespace std; 25 | 26 | void reshape(int w, int h) 27 | { 28 | glViewport(0, 0, w, h); /* Establish viewing area to cover entire window. */ 29 | glMatrixMode(GL_PROJECTION); /* Start modifying the projection matrix. */ 30 | glLoadIdentity(); /* Reset project matrix. */ 31 | glOrtho(0, w, 0, h, -1, 1); /* Map abstract coords directly to window coords. */ 32 | glScalef(1, -1, 1); /* Invert Y axis so increasing Y goes down. */ 33 | glTranslatef(0, -h, 0); /* Shift origin up to upper-left corner. */ 34 | } 35 | 36 | long targetDeltaTime = 33; // 30 FPS = 33 ms/frame 37 | 38 | 39 | double x1 = 0, y1 = 0, x2 = 200, y2 = 200, x3 = 20, y3 = 200; 40 | 41 | void display(void) 42 | { 43 | static float angle=0.0; 44 | angle+=1.0; 45 | glClear(GL_COLOR_BUFFER_BIT); 46 | glPushMatrix(); 47 | glTranslatef(150.0,150.0,0.0); 48 | glRotatef(angle, 0.0, 0.0, 1.0); 49 | glBegin(GL_TRIANGLES); 50 | glColor3f(0.0, 0.0, 1.0); /* blue */ 51 | glVertex2i(x1, y1); 52 | glColor3f(0.0, 1.0, 0.0); /* green */ 53 | glVertex2i(x2, y2); 54 | glColor3f(1.0, 0.0, 0.0); /* red */ 55 | glVertex2i(x3, y3); 56 | glEnd(); 57 | glPopMatrix(); 58 | glFlush(); /* Single buffered, so needs a flush. */ 59 | } 60 | 61 | 62 | void update() { 63 | static long long prevTime = 0 ; 64 | long long currTime = glutGet(GLUT_ELAPSED_TIME); 65 | if ( (currTime - prevTime) < targetDeltaTime) { 66 | SLEEP((targetDeltaTime-(currTime-prevTime))); 67 | } 68 | prevTime = currTime; 69 | glutPostRedisplay(); 70 | } 71 | 72 | int main(int argc, char **argv) 73 | { 74 | 75 | ParamTuner::load("settings.xml"); 76 | ParamTuner::bind("x1", &x1); 77 | ParamTuner::bind("y1", &y1); 78 | ParamTuner::bind("x2", &x2); 79 | ParamTuner::bind("y2", &y2); 80 | ParamTuner::bind("x3", &x3); 81 | ParamTuner::bind("y3", &y3); 82 | glutInit(&argc, argv); 83 | glutCreateWindow("Single Triangle - libParamTuner examples"); 84 | glutDisplayFunc(display); 85 | glutReshapeFunc(reshape); 86 | glutIdleFunc(update); 87 | glutMainLoop(); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /examples/java/square/Square.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail, Géry Casiez 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | import fr.univ_lille1.libparamtuner.ParamTuner; 20 | import javafx.animation.AnimationTimer; 21 | import javafx.application.Application; 22 | import javafx.scene.Scene; 23 | import javafx.scene.canvas.Canvas; 24 | import javafx.scene.canvas.GraphicsContext; 25 | import javafx.scene.layout.VBox; 26 | import javafx.scene.paint.Color; 27 | import javafx.stage.Stage; 28 | 29 | public class Square extends Application { 30 | GraphicsContext gc; 31 | Canvas canvas; 32 | int x = 10, y = 10, width = 400, height = 200; 33 | String message = "Hello world"; 34 | 35 | @Override 36 | public void start(Stage stage) { 37 | // Load settings file 38 | ParamTuner.load("settings.xml", true); 39 | 40 | ParamTuner.bind("x", Integer.class, v -> x = v); 41 | ParamTuner.bind("y", Integer.class, v -> y = v); 42 | ParamTuner.bind("width", Integer.class, v -> width = v); 43 | ParamTuner.bind("height", Integer.class, v -> height = v); 44 | ParamTuner.bind("message", String.class, v -> message = v); 45 | 46 | ParamTuner.update(); 47 | 48 | VBox root = new VBox(); 49 | canvas = new Canvas(600, 400); 50 | gc = canvas.getGraphicsContext2D(); 51 | root.getChildren().add(canvas); 52 | 53 | stage.setTitle("Hello libparamtuner"); 54 | stage.setScene(new Scene(root)); 55 | stage.show(); 56 | stage.setOnCloseRequest((we) -> System.exit(0)); 57 | 58 | new AnimationTimer() { 59 | private long lastUpdate = 0; 60 | 61 | @Override 62 | public void handle(long now) { 63 | if (now - lastUpdate >= 15_000_000) { // 15 ms 64 | update(); 65 | lastUpdate = now; 66 | } 67 | } 68 | }.start(); 69 | } 70 | 71 | public void update() { 72 | ParamTuner.update(); 73 | gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); 74 | gc.setFill(Color.RED); 75 | gc.fillRect(x, y, width, height); 76 | gc.setFill(Color.BLACK); 77 | gc.fillText(message, x+3, y+20); 78 | } 79 | 80 | public static void main(String[] args) { 81 | launch(args); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/cpp/rapidxml-1.13/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /src/gui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | fr.univ_lille1.libparamtuner 5 | ParamTunerGUI 6 | 0.0.1-SNAPSHOT 7 | jar 8 | 9 | ParamTuner GUI 10 | 11 | 12 | 1.8 13 | 1.8 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.12 22 | test 23 | 24 | 25 | fr.univ_lille1.libparamtuner 26 | libParamTuner 27 | 0.0.1-SNAPSHOT 28 | compile 29 | 30 | 31 | 32 | 33 | ${project.artifactId} 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-shade-plugin 39 | 2.4.3 40 | 41 | 42 | package 43 | 44 | shade 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-jar-plugin 54 | 2.4 55 | 56 | 57 | 58 | fr.univ_lille1.libparamtuner.gui.Main 59 | 60 | 61 | 62 | 63 | 64 | com.zenjava 65 | javafx-maven-plugin 66 | 8.6.0 67 | 68 | fr.univ_lille1.libparamtuner.gui.Main 69 | 70 | Université Lille 1 71 | true 72 | 73 | true 74 | UNIVERSITE SCIENCES TECHNOLOGIES LILLE 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/parameters_panel/FloatParameterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui.parameters_panel; 19 | 20 | import fr.univ_lille1.libparamtuner.gui.MainFrame; 21 | import fr.univ_lille1.libparamtuner.parameters.FloatParameter; 22 | import javafx.scene.control.Slider; 23 | import javafx.scene.control.Spinner; 24 | import javafx.scene.layout.HBox; 25 | import javafx.scene.layout.Priority; 26 | 27 | public class FloatParameterPanel extends ParameterPanel { 28 | 29 | 30 | public FloatParameterPanel(MainFrame f, int index, FloatParameter p) { 31 | super(f, index, p); 32 | 33 | boolean minMaxValid = p.getMax() != p.getMin(); 34 | 35 | double value = !minMaxValid ? p.getValue() 36 | : (p.getValue() < p.getMin()) ? ((long) p.getMin()) 37 | : (p.getValue() > p.getMax()) ? ((long) p.getMax()) : p.getValue(); 38 | 39 | Spinner spinner = new Spinner<>( 40 | minMaxValid ? p.getMin() : Long.MIN_VALUE, 41 | minMaxValid ? p.getMax() : Long.MAX_VALUE, value); 42 | spinner.setEditable(true); 43 | 44 | // pressing ENTER after editing the spinner value is no more required 45 | // Here is how the value is automatically updated every time the editor's value change : 46 | spinner.getEditor().textProperty().addListener((o, old, newValue) -> { 47 | Double newV = null; 48 | try { 49 | newV = spinner.getValueFactory().getConverter().fromString(newValue); 50 | } catch (Exception e) { 51 | // ignore 52 | } 53 | if (newV != null) { 54 | spinner.getValueFactory().setValue(newV); 55 | } 56 | }); 57 | spinner.valueProperty().addListener((o, old, newValue) -> { 58 | p.setValue(newValue); 59 | notifyContentModification(); 60 | }); 61 | 62 | 63 | 64 | if (minMaxValid) { 65 | Slider slider = new Slider(p.getMin(), p.getMax(), value); 66 | slider.setShowTickMarks(false); 67 | slider.setShowTickLabels(false); 68 | // manual binding (because auto binding does'nt not round double values) 69 | spinner.valueProperty().addListener((o, old, newValue) -> { 70 | slider.setValue(newValue); 71 | }); 72 | slider.valueProperty().addListener((o, old, newValue) -> { 73 | spinner.getValueFactory().setValue((double)(Double)newValue); 74 | }); 75 | 76 | add(slider); 77 | HBox.setHgrow(slider, Priority.ALWAYS); 78 | } 79 | 80 | add(spinner); 81 | 82 | 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/java/src/test/java/fr/univ_lille1/libparamtuner/ParamTunerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner; 19 | 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.nio.file.StandardCopyOption; 23 | 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | public class ParamTunerTest { 28 | 29 | 30 | public static final String watchedPath = "target/test_settings.xml"; 31 | public static final String originalPath = "src/test/resources/settings_o.xml"; 32 | public static final String newPath = "src/test/resources/settings_n.xml"; 33 | 34 | 35 | 36 | Throwable threadThrowable; 37 | 38 | 39 | 40 | double setting1; 41 | int setting2; 42 | boolean mybool; 43 | String mystring; 44 | 45 | 46 | 47 | 48 | @Before 49 | public void setUp() throws Exception { 50 | threadThrowable = null; 51 | 52 | setting1 = 0; 53 | setting2 = 0; 54 | mybool = false; 55 | mystring = ""; 56 | 57 | Files.copy(Paths.get(originalPath), Paths.get(watchedPath), StandardCopyOption.REPLACE_EXISTING); 58 | } 59 | 60 | @Test 61 | public void testMain() throws Throwable { 62 | // ParamTuner usage: 63 | ParamTuner.load(watchedPath); 64 | ParamTuner.bind("setting1", Double.class, v -> setting1 = v); 65 | ParamTuner.bind("setting2", Integer.class, v -> setting2 = v); 66 | ParamTuner.bind("mybool", Boolean.class, v -> mybool = v); 67 | ParamTuner.bind("mystring", String.class, v -> mystring = v); 68 | 69 | 70 | // thread that simulate external software which modify the file settings.xml 71 | Thread t = new Thread(() -> { 72 | try { 73 | for (int i = 0;; i++) { 74 | Thread.sleep(1000); 75 | if (i % 2 == 0) 76 | Files.copy(Paths.get(newPath), Paths.get(watchedPath), StandardCopyOption.REPLACE_EXISTING); 77 | else 78 | Files.copy(Paths.get(originalPath), Paths.get(watchedPath), 79 | StandardCopyOption.REPLACE_EXISTING); 80 | } 81 | } catch (InterruptedException e) { 82 | return; 83 | } catch (Throwable e) { 84 | threadThrowable = e; 85 | } 86 | }); 87 | t.start(); 88 | 89 | 90 | // main loop 91 | for (int i = 0; i < 25; i++) { 92 | Thread.sleep(200); 93 | System.out.println("setting1 (double) = " + setting1 94 | + " ; setting2 (int) = " + setting2 95 | + " ; mybool (bool) = " + mybool 96 | + " ; mystring (string) = " + mystring); 97 | } 98 | 99 | t.interrupt(); 100 | t.join(); 101 | if (threadThrowable != null) 102 | throw threadThrowable; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/parameters_panel/IntegerParameterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui.parameters_panel; 19 | 20 | import fr.univ_lille1.libparamtuner.gui.MainFrame; 21 | import fr.univ_lille1.libparamtuner.parameters.IntegerParameter; 22 | import javafx.scene.control.Slider; 23 | import javafx.scene.control.Spinner; 24 | import javafx.scene.layout.HBox; 25 | import javafx.scene.layout.Priority; 26 | 27 | public class IntegerParameterPanel extends ParameterPanel { 28 | 29 | 30 | public IntegerParameterPanel(MainFrame f, int index, IntegerParameter p) { 31 | super(f, index, p); 32 | 33 | boolean minMaxValid = p.getMax() != p.getMin(); 34 | 35 | long value = !minMaxValid ? p.getValue() 36 | : (p.getValue() < p.getMin()) ? ((long) p.getMin()) 37 | : (p.getValue() > p.getMax()) ? ((long) p.getMax()) : p.getValue(); 38 | 39 | Spinner spinner = new Spinner<>( 40 | minMaxValid ? (long) p.getMin() : Long.MIN_VALUE, 41 | minMaxValid ? (long) p.getMax() : Long.MAX_VALUE, value); 42 | spinner.setEditable(true); 43 | 44 | // pressing ENTER after editing the spinner value is no more required 45 | // Here is how the value is automatically updated every time the editor's value change : 46 | spinner.getEditor().textProperty().addListener((o, old, newValue) -> { 47 | Double newV = null; 48 | try { 49 | newV = spinner.getValueFactory().getConverter().fromString(newValue); 50 | } catch (Exception e) { 51 | // ignore 52 | } 53 | if (newV != null) { 54 | spinner.getValueFactory().setValue(newV); 55 | } 56 | }); 57 | spinner.valueProperty().addListener((o, old, newValue) -> { 58 | p.setValue(newValue.longValue()); 59 | notifyContentModification(); 60 | }); 61 | 62 | 63 | 64 | if (minMaxValid) { 65 | Slider slider = new Slider((long) p.getMin(), (long) p.getMax(), value); 66 | slider.setShowTickMarks(false); 67 | slider.setShowTickLabels(false); 68 | slider.setMajorTickUnit(1); 69 | slider.setMinorTickCount(0); 70 | slider.setSnapToTicks(true); 71 | 72 | // manual binding (because auto binding does'nt not round double values) 73 | spinner.valueProperty().addListener((o, old, newValue) -> { 74 | slider.setValue(Math.round(newValue)); 75 | }); 76 | slider.valueProperty().addListener((o, old, newValue) -> { 77 | spinner.getValueFactory().setValue((double)Math.round((Double)newValue)); 78 | }); 79 | add(slider); 80 | HBox.setHgrow(slider, Priority.ALWAYS); 81 | } 82 | 83 | add(spinner); 84 | 85 | 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/FXDialogUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui; 19 | 20 | import java.io.PrintWriter; 21 | import java.io.StringWriter; 22 | import java.util.Arrays; 23 | 24 | import javafx.scene.control.Alert; 25 | import javafx.scene.control.ButtonType; 26 | import javafx.scene.control.Alert.AlertType; 27 | import javafx.scene.control.Label; 28 | import javafx.scene.control.TextArea; 29 | import javafx.scene.layout.GridPane; 30 | import javafx.scene.layout.Priority; 31 | 32 | /** 33 | * Utility class to show dialogs and confirmation messages. 34 | * 35 | * Based on : http://code.makery.ch/blog/javafx-dialogs-official/ 36 | * 37 | * 38 | */ 39 | public class FXDialogUtils { 40 | 41 | 42 | public static void showMessageDialog(AlertType type, String title, String header, String content) { 43 | Alert alert = new Alert(type); 44 | alert.setTitle(title); 45 | alert.setHeaderText(header); 46 | alert.setContentText(content); 47 | 48 | alert.showAndWait(); 49 | } 50 | 51 | public static void showExceptionDialog(String title, String header, Exception ex) { 52 | Alert alert = new Alert(AlertType.ERROR); 53 | alert.setTitle(title); 54 | alert.setHeaderText(header); 55 | alert.setContentText(ex.getLocalizedMessage()); 56 | 57 | // Create expandable Exception. 58 | StringWriter sw = new StringWriter(); 59 | PrintWriter pw = new PrintWriter(sw); 60 | ex.printStackTrace(pw); 61 | String exceptionText = sw.toString(); 62 | 63 | Label label = new Label("The exception stacktrace was:"); 64 | 65 | TextArea textArea = new TextArea(exceptionText); 66 | textArea.setEditable(false); 67 | textArea.setWrapText(true); 68 | 69 | textArea.setMaxWidth(Double.MAX_VALUE); 70 | textArea.setMaxHeight(Double.MAX_VALUE); 71 | GridPane.setVgrow(textArea, Priority.ALWAYS); 72 | GridPane.setHgrow(textArea, Priority.ALWAYS); 73 | 74 | GridPane expContent = new GridPane(); 75 | expContent.setMaxWidth(Double.MAX_VALUE); 76 | expContent.add(label, 0, 0); 77 | expContent.add(textArea, 0, 1); 78 | 79 | // Set expandable Exception into the dialog pane. 80 | alert.getDialogPane().setExpandableContent(expContent); 81 | 82 | alert.showAndWait(); 83 | } 84 | 85 | 86 | 87 | public static String showConfirmDialog(String title, String header, String content, String... options) { 88 | Alert alert = new Alert(AlertType.CONFIRMATION); 89 | alert.setTitle(title); 90 | alert.setHeaderText(header); 91 | alert.setContentText(content); 92 | 93 | alert.getButtonTypes().clear(); 94 | 95 | Arrays.stream(options) 96 | .map(ButtonType::new) 97 | .forEachOrdered(alert.getButtonTypes()::add); 98 | 99 | ButtonType result = alert.showAndWait().orElseGet(() -> null); 100 | 101 | return result != null ? result.getText() : null; 102 | } 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import java.util.Arrays; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.function.Function; 24 | 25 | public enum Type { 26 | 27 | INTEGER(IntegerParameter.class, "int", "integer", "long"), 28 | FLOAT(FloatParameter.class, "double", "float"), 29 | BOOLEAN(BooleanParameter.class, "bool", "boolean"), 30 | STRING(StringParameter.class, "string"); 31 | 32 | 33 | /* 34 | * Static values 35 | */ 36 | private static Map, Type> javaTypeToType = new HashMap<>(); 37 | private static Map, Function> javaTypeToGetter = new HashMap<>(); 38 | 39 | static { 40 | javaTypeToType.put(Integer.class, INTEGER); 41 | javaTypeToGetter.put(Integer.class, (IntegerParameter p) -> (int) p.getValue()); 42 | 43 | javaTypeToType.put(Long.class, INTEGER); 44 | javaTypeToGetter.put(Long.class, (IntegerParameter p) -> p.getValue()); 45 | 46 | javaTypeToType.put(Float.class, FLOAT); 47 | javaTypeToGetter.put(Float.class, (FloatParameter p) -> (float) p.getValue()); 48 | 49 | javaTypeToType.put(Double.class, FLOAT); 50 | javaTypeToGetter.put(Double.class, (FloatParameter p) -> p.getValue()); 51 | 52 | javaTypeToType.put(Boolean.class, BOOLEAN); 53 | javaTypeToGetter.put(Boolean.class, (BooleanParameter p) -> p.getValue()); 54 | 55 | javaTypeToType.put(String.class, STRING); 56 | javaTypeToGetter.put(String.class, (StringParameter p) -> p.getValue()); 57 | 58 | } 59 | 60 | 61 | 62 | /* 63 | * Static methods 64 | */ 65 | 66 | public static Type getType(String typeAttributeValue) { 67 | for (Type t : values()) { 68 | for (String v : t.typeAttrValues) { 69 | if (v.equalsIgnoreCase(typeAttributeValue)) 70 | return t; 71 | } 72 | } 73 | return null; 74 | } 75 | 76 | public static Type getTypeFromParamInstance(Class pC) { 77 | for (Type t : values()) { 78 | if (t.parameterClass.equals(pC)) 79 | return t; 80 | } 81 | return null; 82 | } 83 | 84 | public static String getStrTypeFromParamInstance(Class pC) { 85 | for (Type t : values()) { 86 | if (t.parameterClass.equals(pC)) 87 | return t.typeAttrValues[0]; 88 | } 89 | return ""; 90 | } 91 | 92 | public static Type getTypeFromJavaType(Class c) { 93 | return javaTypeToType.get(c); 94 | } 95 | 96 | @SuppressWarnings("unchecked") 97 | public static Function getFunctionGetterFromJavaType(Class c, 98 | @SuppressWarnings("unused") Class

pC) { 99 | return (Function) javaTypeToGetter.get(c); 100 | } 101 | 102 | 103 | 104 | 105 | 106 | public final Class parameterClass; 107 | private final String[] typeAttrValues; 108 | 109 | public String[] getTypeAttributesValues() { 110 | return Arrays.copyOf(typeAttrValues, typeAttrValues.length); 111 | } 112 | 113 | private Type(Class pC, String... attr) { 114 | parameterClass = pC; 115 | typeAttrValues = attr; 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/cpp/rapidxml-1.13/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_UTILS_HPP_INCLUDED 2 | #define RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful 8 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 9 | 10 | #include "rapidxml.hpp" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace rapidxml 17 | { 18 | 19 | //! Represents data loaded from a file 20 | template 21 | class file 22 | { 23 | 24 | public: 25 | 26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 27 | //! \param filename Filename to load. 28 | file(const char *filename) 29 | { 30 | using namespace std; 31 | 32 | // Open stream 33 | basic_ifstream stream(filename, ios::binary); 34 | if (!stream) 35 | throw runtime_error(string("cannot open file ") + filename); 36 | stream.unsetf(ios::skipws); 37 | 38 | // Determine stream size 39 | stream.seekg(0, ios::end); 40 | size_t size = stream.tellg(); 41 | stream.seekg(0); 42 | 43 | // Load data and add terminating 0 44 | m_data.resize(size + 1); 45 | stream.read(&m_data.front(), static_cast(size)); 46 | m_data[size] = 0; 47 | } 48 | 49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 50 | //! \param stream Stream to load from 51 | file(std::basic_istream &stream) 52 | { 53 | using namespace std; 54 | 55 | // Load data and add terminating 0 56 | stream.unsetf(ios::skipws); 57 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 58 | if (stream.fail() || stream.bad()) 59 | throw runtime_error("error reading stream"); 60 | m_data.push_back(0); 61 | } 62 | 63 | //! Gets file data. 64 | //! \return Pointer to data of file. 65 | Ch *data() 66 | { 67 | return &m_data.front(); 68 | } 69 | 70 | //! Gets file data. 71 | //! \return Pointer to data of file. 72 | const Ch *data() const 73 | { 74 | return &m_data.front(); 75 | } 76 | 77 | //! Gets file data size. 78 | //! \return Size of file data, in characters. 79 | std::size_t size() const 80 | { 81 | return m_data.size(); 82 | } 83 | 84 | private: 85 | 86 | std::vector m_data; // File data 87 | 88 | }; 89 | 90 | //! Counts children of node. Time complexity is O(n). 91 | //! \return Number of children of node 92 | template 93 | inline std::size_t count_children(xml_node *node) 94 | { 95 | xml_node *child = node->first_node(); 96 | std::size_t count = 0; 97 | while (child) 98 | { 99 | ++count; 100 | child = child->next_sibling(); 101 | } 102 | return count; 103 | } 104 | 105 | //! Counts attributes of node. Time complexity is O(n). 106 | //! \return Number of attributes of node 107 | template 108 | inline std::size_t count_attributes(xml_node *node) 109 | { 110 | xml_attribute *attr = node->first_attribute(); 111 | std::size_t count = 0; 112 | while (attr) 113 | { 114 | ++count; 115 | attr = attr->next_attribute(); 116 | } 117 | return count; 118 | } 119 | 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/cpp/paramtuner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef LIB_PARAM_TUNER_H 19 | #define LIB_PARAM_TUNER_H 20 | 21 | #include 22 | 23 | namespace ParamTuner { 24 | 25 | /** 26 | \brief Start listening modifications of the specified file. 27 | 28 | After this function call, when the specified file is modified 29 | by another program, the variables binded with lptBind() are updated 30 | to their new values from file. 31 | 32 | The specified file's content must be an XML file with a root node 33 | "ParamList". Direct child node of the ParamList node represent a 34 | parameter in your program, for example : 35 | 36 | See the documentation of lptBind() to see all possible types. 37 | 38 | If a node is not binded to a variable, a message will be sent to standard 39 | error stream. If a node has not a valid type or value, an error will be 40 | displayed too, and the variable will not be updated. 41 | 42 | When this function is called multiple times, the current call disable 43 | listener of the previous call. 44 | 45 | \param path the relative or absolute path to the file to listen to 46 | 47 | \param manualUpdate determine if parameters are updated using update() function 48 | 49 | \return -1 if a problem occurs when starting the listener, 0 otherwise. 50 | */ 51 | int load(const std::string &path, bool manualUpdate=false); 52 | 53 | 54 | /** 55 | \brief Bind a variable with a parameter in the XML file. 56 | 57 | Theses type of variable are actually supported, with the corresponding 58 | type in XML file : 59 | * Integer type (C/C++ type `int`) : type="int". 60 | * Floating point type (C/C++ type `double`) : type="double". 61 | * Boolean type (C++ type `bool`) : type="bool". 62 | The variable in program will have the value true if and only if the value in 63 | XML file is equal, case ignored, to "true". 64 | * String type (c++ type 'std::string') : type="string". 65 | 66 | If a variable is binded to a parameter that doesn't have compatible 67 | type, bad values may be written to the variables. 68 | 69 | This function may be called before or after calling lptLoad(). 70 | The internal storage of binded values is always preserved. 71 | 72 | If a variable is already binded with the specified name, the old 73 | binding will be erased. 74 | 75 | You must ensure that the memory at the address specified by ptr 76 | is always accessible during the program execution, to avoid 77 | segmentation fault. 78 | 79 | \param name the parameter name, that is equal to the node name 80 | containing the parameter value. 81 | 82 | \param ptr a pointer to the variable that will be updated when the 83 | file is modified. 84 | */ 85 | void bind(const std::string &name, void *ptr); 86 | 87 | /** 88 | \brief Remove a binded variable 89 | 90 | \param name the parameter name 91 | */ 92 | void unbind(const std::string &name); 93 | 94 | /** 95 | \brief Update all parameters in an explicit way when useUpdateFunc=true 96 | 97 | This function has no effect if useUpdateFunc=false 98 | 99 | If useUpdateFunc=true, the function reads the xml file only if it has changed 100 | and then updates all parameter values. 101 | */ 102 | void update(); 103 | 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/parameters_panel/ParameterPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui.parameters_panel; 19 | 20 | import fr.univ_lille1.libparamtuner.gui.MainFrame; 21 | import fr.univ_lille1.libparamtuner.parameters.BooleanParameter; 22 | import fr.univ_lille1.libparamtuner.parameters.FloatParameter; 23 | import fr.univ_lille1.libparamtuner.parameters.IntegerParameter; 24 | import fr.univ_lille1.libparamtuner.parameters.Parameter; 25 | import fr.univ_lille1.libparamtuner.parameters.StringParameter; 26 | import javafx.geometry.Pos; 27 | import javafx.scene.Node; 28 | import javafx.scene.control.Label; 29 | import javafx.scene.control.Tooltip; 30 | import javafx.scene.layout.Background; 31 | import javafx.scene.layout.BackgroundFill; 32 | import javafx.scene.layout.Border; 33 | import javafx.scene.layout.BorderPane; 34 | import javafx.scene.layout.BorderStroke; 35 | import javafx.scene.layout.BorderWidths; 36 | import javafx.scene.layout.HBox; 37 | import javafx.scene.paint.Color; 38 | import javafx.scene.text.Font; 39 | import javafx.scene.text.FontPosture; 40 | 41 | public abstract class ParameterPanel extends BorderPane { 42 | 43 | protected final MainFrame frame; 44 | protected final Parameter parameter; 45 | protected final HBox panel; 46 | 47 | public ParameterPanel(MainFrame f, int index, Parameter p) { 48 | frame = f; 49 | parameter = p; 50 | 51 | panel = new HBox(3); 52 | setCenter(panel); 53 | 54 | setBackground(new Background(new BackgroundFill((index % 2 == 0) ? Color.rgb(220, 220, 220) : Color.TRANSPARENT, null, null))); 55 | setBorder(new Border(new BorderStroke(Color.TRANSPARENT, null, null, new BorderWidths(2)))); 56 | panel.setAlignment(Pos.CENTER_LEFT); 57 | 58 | Label l = new Label(p.name); 59 | l.setTooltip(new Tooltip(p.name + " of type " + p.getType().name())); 60 | 61 | 62 | // the minWidth property of the label is bounded to the global "minWidth" property. 63 | l.minWidthProperty().bind(f.minLabelSize); 64 | 65 | // listener that update the global "minWidth" property if the current label is larger 66 | // so other labels will have the same "minWidth". 67 | l.widthProperty().addListener((o, old, newValue) -> { 68 | if ((Double)newValue > f.minLabelSize.doubleValue()) { 69 | f.minLabelSize.setValue(newValue); 70 | } 71 | }); 72 | 73 | 74 | 75 | add(l); 76 | 77 | 78 | if (!p.getDesc().isEmpty()) { 79 | Label descL = new Label(p.getDesc()); 80 | descL.setBorder(new Border(new BorderStroke(Color.TRANSPARENT, null, null, new BorderWidths(2, 10, 0, 10)))); 81 | descL.setWrapText(true); 82 | descL.setFont(Font.font(Font.getDefault().getFamily(), FontPosture.ITALIC, Font.getDefault().getSize())); 83 | setBottom(descL); 84 | } 85 | 86 | 87 | } 88 | 89 | 90 | 91 | protected void add(Node e) { 92 | panel.getChildren().add(e); 93 | } 94 | 95 | 96 | public void notifyContentModification() { 97 | frame.onContentModify(); 98 | } 99 | 100 | 101 | 102 | public static ParameterPanel fromParameter(MainFrame f, int index, Parameter p) { 103 | if (p instanceof BooleanParameter) { 104 | return new BooleanParameterPanel(f, index, (BooleanParameter) p); 105 | } 106 | if (p instanceof FloatParameter) { 107 | return new FloatParameterPanel(f, index, (FloatParameter) p); 108 | } 109 | if (p instanceof IntegerParameter) { 110 | return new IntegerParameterPanel(f, index, (IntegerParameter) p); 111 | } 112 | if (p instanceof StringParameter) { 113 | return new StringParameterPanel(f, index, (StringParameter) p); 114 | } 115 | 116 | throw new IllegalArgumentException("Unsupported Parameter type : " + p.getClass().getName()); 117 | } 118 | 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import org.w3c.dom.Document; 21 | import org.w3c.dom.Element; 22 | 23 | public abstract class Parameter { 24 | 25 | public final String name; 26 | protected String value; 27 | protected double min; 28 | protected double max; 29 | protected String desc = null; 30 | 31 | protected Parameter(String n, String v, double m, double M) { 32 | name = n; 33 | value = v; 34 | setMinMax(m, M); 35 | } 36 | 37 | protected Parameter(String n, String v) { 38 | this(n, v, 0, 0); 39 | } 40 | 41 | protected Parameter(String n) { 42 | this(n, "", 0, 0); 43 | } 44 | 45 | protected Parameter(String n, double m, double M) { 46 | this(n, "", m, M); 47 | } 48 | 49 | public String getStringValue() { 50 | return value; 51 | } 52 | 53 | public Type getType() { 54 | return Type.getTypeFromParamInstance(getClass()); 55 | } 56 | 57 | public double getMin() { 58 | return min; 59 | } 60 | 61 | public double getMax() { 62 | return max; 63 | } 64 | 65 | public void setMinMax(double m, double M) { 66 | if (m > M) { 67 | min = M; 68 | max = m; 69 | } 70 | else { 71 | min = m; 72 | max = M; 73 | } 74 | } 75 | 76 | public void setDesc(String d) { 77 | if (d == null) 78 | d = ""; 79 | desc = d; 80 | } 81 | 82 | public String getDesc() { 83 | return desc; 84 | } 85 | 86 | 87 | 88 | /* package */ Parameter(Element xmlEl) { 89 | name = xmlEl.getTagName(); 90 | value = xmlEl.getAttribute("value"); 91 | 92 | double m, M; 93 | 94 | try { 95 | m = Double.parseDouble(xmlEl.getAttribute("min")); 96 | } catch (NumberFormatException e) { 97 | m = 0; 98 | } 99 | try { 100 | M = Double.parseDouble(xmlEl.getAttribute("max")); 101 | } catch (NumberFormatException e) { 102 | M = 0; 103 | } 104 | setMinMax(m, M); 105 | 106 | setDesc(xmlEl.getAttribute("desc")); 107 | } 108 | 109 | 110 | /* package */ Element toXMLElement(Document doc) { 111 | Element el = doc.createElement(name); 112 | el.setAttribute("type", getType().getTypeAttributesValues()[0]); 113 | if (min != 0 || max != 0) { 114 | boolean isInteger = getClass() == IntegerParameter.class; 115 | el.setAttribute("min", isInteger ? ""+(int)min : ""+min); 116 | el.setAttribute("max", isInteger ? ""+(int)max : ""+max); 117 | } 118 | el.setAttribute("value", value); 119 | if (!desc.isEmpty()) 120 | el.setAttribute("desc", desc); 121 | return el; 122 | } 123 | 124 | 125 | 126 | 127 | /** 128 | * @deprecated Prefer using {@link #toXMLElement(Document)} because it is more flexible 129 | * and allow more clean code when overriding. For the current method, overriding it 130 | * requires to reimplement the code to add specific functionnality related to the subclass 131 | */ 132 | @Deprecated 133 | /* package */ String toXMLstring() { 134 | String res = "<"; 135 | res += name + " type=\""; 136 | 137 | String type = Type.getStrTypeFromParamInstance(getClass()); 138 | res+= type + "\" "; 139 | 140 | if (min != 0 || max != 0) { 141 | if (getClass() == IntegerParameter.class) { 142 | res += "min=\"" + (int)min + "\" "; 143 | res += "max=\"" + (int)max + "\" "; 144 | } else { 145 | res += "min=\"" + min + "\" "; 146 | res += "max=\"" + max + "\" "; 147 | } 148 | } 149 | 150 | res += "value=\"" + value + "\"/>"; 151 | 152 | return res; 153 | } 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | /* package */ static Parameter fromXMLElement(Element el) throws Exception { 162 | Type type = Type.getType(el.getAttribute("type")); 163 | 164 | if (type == null) 165 | throw new IllegalArgumentException("Element has not a valid type attribute : '" + type + "'"); 166 | 167 | return type.parameterClass.getDeclaredConstructor(Element.class).newInstance(el); 168 | 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/cpp/rapidxml-1.13/rapidxml_iterators.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED 2 | #define RAPIDXML_ITERATORS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! \file rapidxml_iterators.hpp This file contains rapidxml iterators 8 | 9 | #include "rapidxml.hpp" 10 | 11 | namespace rapidxml 12 | { 13 | 14 | //! Iterator of child nodes of xml_node 15 | template 16 | class node_iterator 17 | { 18 | 19 | public: 20 | 21 | typedef typename xml_node value_type; 22 | typedef typename xml_node &reference; 23 | typedef typename xml_node *pointer; 24 | typedef std::ptrdiff_t difference_type; 25 | typedef std::bidirectional_iterator_tag iterator_category; 26 | 27 | node_iterator() 28 | : m_node(0) 29 | { 30 | } 31 | 32 | node_iterator(xml_node *node) 33 | : m_node(node->first_node()) 34 | { 35 | } 36 | 37 | reference operator *() const 38 | { 39 | assert(m_node); 40 | return *m_node; 41 | } 42 | 43 | pointer operator->() const 44 | { 45 | assert(m_node); 46 | return m_node; 47 | } 48 | 49 | node_iterator& operator++() 50 | { 51 | assert(m_node); 52 | m_node = m_node->next_sibling(); 53 | return *this; 54 | } 55 | 56 | node_iterator operator++(int) 57 | { 58 | node_iterator tmp = *this; 59 | ++this; 60 | return tmp; 61 | } 62 | 63 | node_iterator& operator--() 64 | { 65 | assert(m_node && m_node->previous_sibling()); 66 | m_node = m_node->previous_sibling(); 67 | return *this; 68 | } 69 | 70 | node_iterator operator--(int) 71 | { 72 | node_iterator tmp = *this; 73 | ++this; 74 | return tmp; 75 | } 76 | 77 | bool operator ==(const node_iterator &rhs) 78 | { 79 | return m_node == rhs.m_node; 80 | } 81 | 82 | bool operator !=(const node_iterator &rhs) 83 | { 84 | return m_node != rhs.m_node; 85 | } 86 | 87 | private: 88 | 89 | xml_node *m_node; 90 | 91 | }; 92 | 93 | //! Iterator of child attributes of xml_node 94 | template 95 | class attribute_iterator 96 | { 97 | 98 | public: 99 | 100 | typedef typename xml_attribute value_type; 101 | typedef typename xml_attribute &reference; 102 | typedef typename xml_attribute *pointer; 103 | typedef std::ptrdiff_t difference_type; 104 | typedef std::bidirectional_iterator_tag iterator_category; 105 | 106 | attribute_iterator() 107 | : m_attribute(0) 108 | { 109 | } 110 | 111 | attribute_iterator(xml_node *node) 112 | : m_attribute(node->first_attribute()) 113 | { 114 | } 115 | 116 | reference operator *() const 117 | { 118 | assert(m_attribute); 119 | return *m_attribute; 120 | } 121 | 122 | pointer operator->() const 123 | { 124 | assert(m_attribute); 125 | return m_attribute; 126 | } 127 | 128 | attribute_iterator& operator++() 129 | { 130 | assert(m_attribute); 131 | m_attribute = m_attribute->next_attribute(); 132 | return *this; 133 | } 134 | 135 | attribute_iterator operator++(int) 136 | { 137 | attribute_iterator tmp = *this; 138 | ++this; 139 | return tmp; 140 | } 141 | 142 | attribute_iterator& operator--() 143 | { 144 | assert(m_attribute && m_attribute->previous_attribute()); 145 | m_attribute = m_attribute->previous_attribute(); 146 | return *this; 147 | } 148 | 149 | attribute_iterator operator--(int) 150 | { 151 | attribute_iterator tmp = *this; 152 | ++this; 153 | return tmp; 154 | } 155 | 156 | bool operator ==(const attribute_iterator &rhs) 157 | { 158 | return m_attribute == rhs.m_attribute; 159 | } 160 | 161 | bool operator !=(const attribute_iterator &rhs) 162 | { 163 | return m_attribute != rhs.m_attribute; 164 | } 165 | 166 | private: 167 | 168 | xml_attribute *m_attribute; 169 | 170 | }; 171 | 172 | } 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # libParamTuner 2 | 3 | Cross-platform library to ease the interactive tuning of parameters at run time and without the need to recompile code. 4 | 5 | ## Install on macOS using Homebrew 6 | 7 | Run ```brew install casiez/libparamtuner/libparamtuner``` 8 | 9 | ## Minimal example 10 | ```cpp 11 | #include 12 | #include 13 | #include "paramtuner.h" 14 | 15 | #ifdef _WIN32 16 | # include 17 | # define SLEEP(ms) (Sleep(ms)) 18 | #else 19 | # include 20 | # define SLEEP(ms) (usleep(ms * 1000)) 21 | #endif 22 | 23 | using namespace std; 24 | 25 | int main() { 26 | double varDouble = 2.0; 27 | int varInt = 1; 28 | bool varBool = false; 29 | string varString; 30 | 31 | ParamTuner::load("settings.xml"); 32 | // Use the line below if you want to explicitly update 33 | // all parameters using update() function 34 | // ParamTuner::load("settings.xml", true); 35 | ParamTuner::bind("setting1", &varDouble); 36 | ParamTuner::bind("setting2", &varInt); 37 | ParamTuner::bind("mybool", &varBool); 38 | ParamTuner::bind("mystring", &varString); 39 | 40 | while (true) { 41 | SLEEP(500); // 500 ms 42 | // Uncomment the line below if you use ParamTuner::load("settings.xml", true); 43 | // ParamTuner::update(); 44 | cout << "setting1 (double) = " << varDouble 45 | << " ; setting2 (int) = " << varInt 46 | << " ; mybool (bool) = " << varBool 47 | << " ; mystring (string) = " << varString 48 | << endl; 49 | } 50 | } 51 | ``` 52 | 53 | The associated settings.xml file is as follows: 54 | 55 | ``` 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ``` 64 | 65 | ## C++ Library 66 | 67 | The C++ libParamTuner library use system-dependent libraries 68 | that are already installed in their respective OS : 69 | * Windows ([FindFirstChangeNotification() function](https://msdn.microsoft.com/en-us/library/aa364417%28VS.85%29.aspx)) 70 | * Linux (kernel > 2.6.13, with [Inotify](https://en.wikipedia.org/wiki/Inotify)) 71 | * Mac OS X (version > 10.5, with [FSEvents](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html)) 72 | 73 | ### Compilation 74 | 75 | * In directory `src/cpp`, run `make` 76 | * Library file : `libparamtuner.a` 77 | * Header file : `paramtuner.h` 78 | 79 | ### Usage and documentation 80 | 81 | Read detailed documentation in the header file `paramtuner.h` 82 | 83 | ### Example files 84 | 85 | Some examples files are available in `examples/cpp` directory. 86 | You can compile them with `make [C++ filename without extension]` command. 87 | 88 | 89 | 90 | ## Java 8+ Library 91 | 92 | ### Compilation and installation 93 | 94 | The Java library use Maven. In directory `src/java`, run `mvn clean install`. 95 | This command will create a libParamTuner.jar in the `target` subdirectory. 96 | Also, it will install it into your local maven repository, so you can use 97 | it in an other Maven project. 98 | 99 | To use it in a Maven project, add theses lines in your POM's 100 | `` section : 101 | ``` 102 | 103 | fr.univ_lille1.libparamtuner 104 | libParamTuner 105 | 0.0.1-SNAPSHOT 106 | 107 | ``` 108 | 109 | If you have a non-Maven project, just add `libParamTuner.jar` to the 110 | build path of your project. 111 | 112 | To get the javadoc, run `mvn javadoc:javadoc` , then go to the subdirectory 113 | `target/site/apidocs` 114 | 115 | 116 | 117 | ## ParamTuner GUI 118 | 119 | This JavaFX interface allow developers to change value in 120 | real-time without having to edit the settings file manually. 121 | 122 | ### Available binaries 123 | See the [releases](https://github.com/casiez/libparamtuner/releases) section to directly download a binary version. 124 | 125 | ### Compilation 126 | 127 | The Java application use Maven. First, you have to compile the Java library 128 | (see instruction above). Then, in directory `src/gui`, run `mvn package`. 129 | The executable Jar is in subdirectory `target`. 130 | 131 | If you want to create an installer with an executable, run `mvn jfx:native`. Note that icns icons for macOS were created using the command `makeicns -in ParamTunerGUI.png -out ParamTunerGUI.icns` 132 | 133 | ### Usage 134 | 135 | java -jar ParamTunerGUI.jar path/to/settings.xml 136 | 137 | or 138 | 139 | java -jar ParamTunerGUI.jar 140 | 141 | then you can put the path to the XML directly into the GUI. 142 | 143 | ## More information 144 | 145 | libParamTuner has been presented as a demo during the [IHM'17 conference](http://ihm17.afihm.org/). 146 | More information (in French) available on [HAL](https://hal.archives-ouvertes.fr/hal-01577686). 147 | -------------------------------------------------------------------------------- /src/cpp/paramtuner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "paramtuner.h" 19 | 20 | #include "FileSystemWatcher.hpp" 21 | #include "rapidxml-1.13/rapidxml.hpp" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using namespace rapidxml; 32 | using namespace std; 33 | 34 | 35 | namespace ParamTuner { 36 | 37 | // Data structure 38 | std::map binding; 39 | 40 | FileSystemWatcher* watcher; 41 | 42 | bool useUpdateFunction = false; 43 | bool someParametersChanged = true; 44 | 45 | 46 | // Private function 47 | double stringToDouble(const string & str) 48 | { 49 | try { 50 | double dest; 51 | istringstream iss(str); 52 | iss >> dest; 53 | return dest; 54 | } catch (const exception& e) { 55 | cerr << "std::exception thrown in string_to_double: " << e.what() << endl; 56 | return 0; 57 | } 58 | 59 | } 60 | 61 | int stringToInt(const string & str) 62 | { 63 | try { 64 | int dest; 65 | istringstream iss(str); 66 | iss >> dest; 67 | return dest; 68 | } catch (const exception& e) { 69 | cerr << "std::exception thrown in string_to_int: " << e.what() << endl; 70 | return 0; 71 | } 72 | } 73 | 74 | void loadFile(bool verbose) 75 | { 76 | if (!watcher) 77 | return; 78 | // based on https://gist.github.com/JSchaenzle/2726944 79 | try { 80 | 81 | xml_document<> doc; 82 | xml_node<> * root_node; 83 | // Read the xml file into a vector 84 | ifstream theFile (watcher->getPath()); 85 | vector buffer((istreambuf_iterator(theFile)), istreambuf_iterator()); 86 | buffer.push_back('\0'); 87 | // Parse the buffer using the xml file parsing library into doc 88 | doc.parse<0>(&buffer[0]); 89 | 90 | // Find our root node 91 | root_node = doc.first_node("ParamList"); 92 | 93 | if (!root_node) { 94 | if (verbose) 95 | cerr << "Settings file does not contains ParamList root node" << endl; 96 | return; 97 | } 98 | // Iterate over the parameters 99 | for (xml_node<> * param_node = root_node->first_node(); param_node; param_node = param_node->next_sibling()) 100 | { 101 | string name(param_node->name()); 102 | if (binding.find(name) == binding.end()) { 103 | if (verbose) 104 | cerr << "Setting '" << name << "' is not binded with lptBind()" << endl; 105 | continue; 106 | } 107 | xml_attribute<> *value_attr = param_node->first_attribute("value"); 108 | xml_attribute<> *type_attr = param_node->first_attribute("type"); 109 | if (!value_attr) { 110 | if (verbose) 111 | cerr << "Setting '" << name << "' does not have 'value' attribute" << endl; 112 | continue; 113 | } 114 | if (!type_attr) { 115 | if (verbose) 116 | cerr << "Setting '" << name << "' does not have 'type' attribute" << endl; 117 | continue; 118 | } 119 | string type(type_attr->value()); 120 | std::transform(type.begin(), type.end(), type.begin(), ::tolower); 121 | string value(value_attr->value()); 122 | 123 | if (type == "bool") { 124 | std::transform(value.begin(), value.end(), value.begin(), ::tolower); 125 | *((bool*)binding[name]) = value == "true"; 126 | } 127 | else if (type == "string") { 128 | *((string*)binding[name]) = value; 129 | } 130 | else if (type == "int") { 131 | *((int*)binding[name]) = stringToInt(value); 132 | } 133 | else if (type == "double") { 134 | *((double*)binding[name]) = stringToDouble(value); 135 | } 136 | else { 137 | if (verbose) 138 | cerr << "Setting '" << name << "' has an unsupported 'type' attribute" << endl; 139 | } 140 | 141 | } 142 | 143 | } catch (const rapidxml::parse_error &e) { 144 | cerr << "Error while parsing XML file : " << e.what() << endl; 145 | } 146 | 147 | } 148 | 149 | void fileModificationCallback() 150 | { 151 | if (useUpdateFunction) 152 | someParametersChanged = true; 153 | else 154 | loadFile(true); 155 | } 156 | 157 | 158 | // Public function 159 | int load(const string &path, bool manualUpdate) 160 | { 161 | useUpdateFunction = manualUpdate; 162 | binding.clear(); 163 | if (watcher) 164 | delete watcher; 165 | 166 | // Construct the file system watcher depending on current OS 167 | watcher = FileSystemWatcher::createFileSystemWatcher(path, fileModificationCallback); 168 | if (!watcher) 169 | return -1; 170 | 171 | return 0; 172 | } 173 | 174 | void bind(const string &name, void *ptr) 175 | { 176 | binding[name] = ptr; 177 | loadFile(false); 178 | } 179 | 180 | void unbind(const string &name) 181 | { 182 | binding.erase(name); 183 | } 184 | 185 | void update() 186 | { 187 | if (useUpdateFunction) { 188 | if (someParametersChanged) { 189 | loadFile(true); 190 | someParametersChanged = false; 191 | } 192 | } 193 | else { 194 | static bool once = true; 195 | if (once) { 196 | cerr << "libParamTuner update() call is useless unless manualUpdate parameter in load function is set to true" << std::endl; 197 | once = false; 198 | } 199 | } 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/FileWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.lang.reflect.Field; 23 | import java.nio.file.FileSystems; 24 | import java.nio.file.Path; 25 | import java.nio.file.StandardWatchEventKinds; 26 | import java.nio.file.WatchEvent; 27 | import java.nio.file.WatchEvent.Modifier; 28 | import java.nio.file.WatchKey; 29 | import java.nio.file.WatchService; 30 | import java.util.function.Consumer; 31 | import java.util.logging.Level; 32 | 33 | class FileWatcher extends Thread { 34 | public final File confFile; 35 | private final Path parentPath; 36 | 37 | private final WatchService watcher; 38 | private final WatchKey key; 39 | 40 | private final Consumer callback; 41 | 42 | /* package */ FileWatcher(File configFile, Consumer cb) throws IOException { 43 | super("libParamTuner Thread"); 44 | callback = cb; 45 | confFile = configFile.getAbsoluteFile(); 46 | if (!confFile.isFile()) 47 | throw new IllegalArgumentException("configFile is not a regular file"); 48 | if (confFile.getParentFile() == null) 49 | throw new IllegalArgumentException("configFile hasn't got a parent directory"); 50 | 51 | parentPath = confFile.getParentFile().toPath(); 52 | 53 | // initialize a new watcher service 54 | watcher = FileSystems.getDefault().newWatchService(); 55 | 56 | Modifier sensitivityModifier = getHIGHSensitivityModifier(); 57 | if (sensitivityModifier != null) { 58 | key = parentPath.register(watcher, 59 | new WatchEvent.Kind[] {StandardWatchEventKinds.ENTRY_MODIFY}, 60 | sensitivityModifier); 61 | } 62 | else { 63 | key = parentPath.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); 64 | } 65 | 66 | } 67 | 68 | 69 | /** 70 | * Return a WathService Modifier that ask for a High sensitivity. 71 | * 72 | * This modifier, in some Java for Mac OS implementation, allow to reduce 73 | * the time between event updates. 74 | * Because some modifier is specific to certain implementation of 75 | * Java (and is not part to the Java standard public library), we have to 76 | * get it via reflexion. 77 | * 78 | * @return the modifier if it exist in the current Java implementation, 79 | * or null otherwise. 80 | */ 81 | private static Modifier getHIGHSensitivityModifier() { 82 | try { 83 | /* 84 | * Java Sun implementation 85 | */ 86 | Class c = Class.forName("com.sun.nio.file.SensitivityWatchEventModifier"); 87 | Modifier watcherModifier = (Modifier) c.getField("HIGH").get(null); 88 | ParamTuner.logger.info("Watcher Sensitivity Modifier: com.sun.nio.file.SensitivityWatchEventModifier.HIGH"); 89 | 90 | /* 91 | * This watcher modifier is, by default, setted with an interval of 2 seconds 92 | */ 93 | Field sensitivityField = c.getDeclaredField("sensitivity"); 94 | sensitivityField.setAccessible(true); 95 | // remove the final modifier of the field sensitivity (reflection-ception !) 96 | Field jModifiersField = Field.class.getDeclaredField("modifiers"); 97 | jModifiersField.setAccessible(true); 98 | jModifiersField.setInt(sensitivityField, sensitivityField.getModifiers() & ~java.lang.reflect.Modifier.FINAL); 99 | 100 | sensitivityField.setInt(watcherModifier, 1); 101 | ParamTuner.logger.info("Watcher Sensitivity Modifier: com.sun.nio.file.SensitivityWatchEventModifier.HIGH set sensitivity to 1 second via reflexion"); 102 | 103 | return watcherModifier; 104 | } catch (Exception e) { 105 | ParamTuner.logger.info("Watcher Sensitivity Modifier: null"); 106 | return null; // fallback (other Java implementation may be handled here) 107 | } 108 | } 109 | 110 | 111 | @Override 112 | public void run() { 113 | try { 114 | /* 115 | * Based on https://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java 116 | */ 117 | for (;;) { 118 | 119 | // wait for key to be signaled 120 | WatchKey key; 121 | try { 122 | key = watcher.take(); 123 | } catch (InterruptedException e) { 124 | ParamTuner.logger.log(Level.SEVERE, "thread interrupted", e); 125 | watcher.close(); 126 | return; 127 | } 128 | 129 | 130 | if (key == null || !key.equals(this.key)) 131 | continue; 132 | 133 | for (WatchEvent event : key.pollEvents()) { 134 | WatchEvent.Kind kind = event.kind(); 135 | 136 | // TBD - provide example of how OVERFLOW event is handled 137 | if (kind == StandardWatchEventKinds.OVERFLOW) 138 | continue; 139 | 140 | @SuppressWarnings("unchecked") 141 | Path child = parentPath.resolve(((WatchEvent) event).context()); 142 | if (!child.toFile().equals(confFile)) 143 | continue; 144 | 145 | callback.accept(this); 146 | 147 | } 148 | 149 | // reset key and remove from set if directory no longer accessible 150 | boolean valid = key.reset(); 151 | if (!valid) { 152 | ParamTuner.logger.severe("WatchKey no longer valid"); 153 | watcher.close(); 154 | return; 155 | } 156 | } 157 | } catch (Exception e) { 158 | ParamTuner.logger.log(Level.SEVERE, "Exception in watcher thread", e); 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/parameters/ParameterFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.parameters; 19 | 20 | import java.io.File; 21 | import java.io.FileWriter; 22 | import java.io.IOException; 23 | import java.io.StringWriter; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.TreeMap; 28 | import java.util.Vector; 29 | 30 | import javax.xml.parsers.DocumentBuilder; 31 | import javax.xml.parsers.DocumentBuilderFactory; 32 | import javax.xml.parsers.ParserConfigurationException; 33 | import javax.xml.transform.OutputKeys; 34 | import javax.xml.transform.Transformer; 35 | import javax.xml.transform.TransformerFactory; 36 | import javax.xml.transform.dom.DOMSource; 37 | import javax.xml.transform.stream.StreamResult; 38 | 39 | import org.w3c.dom.Document; 40 | import org.w3c.dom.Element; 41 | import org.w3c.dom.Node; 42 | import org.w3c.dom.NodeList; 43 | 44 | public class ParameterFile { 45 | 46 | private final Map parameters = new TreeMap<>(); 47 | private final Vector paramOrder = new Vector<>(); 48 | 49 | public final File file; 50 | 51 | public ParameterFile(String fileName, boolean loadFromFile) throws Exception { 52 | this(new File(fileName), loadFromFile); 53 | } 54 | 55 | public ParameterFile(File f, boolean loadFromFile) throws Exception { 56 | file = f; 57 | 58 | if (loadFromFile) { 59 | load(); 60 | } 61 | } 62 | 63 | 64 | private static DocumentBuilder getXMLBuilder() throws ParserConfigurationException { 65 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 66 | factory.setIgnoringComments(true); 67 | return factory.newDocumentBuilder(); 68 | } 69 | 70 | private void readDocument(Document doc) throws Exception { 71 | Element parentEl = doc.getDocumentElement(); 72 | 73 | if (!parentEl.getTagName().equalsIgnoreCase("ParamList")) { 74 | throw new Exception("Settings file does not contains ParamList root node"); 75 | } 76 | 77 | NodeList paramNodes = parentEl.getChildNodes(); 78 | 79 | for (int i = 0; i < paramNodes.getLength(); i++) { 80 | Node node = paramNodes.item(i); 81 | if (node.getNodeType() != Node.ELEMENT_NODE) 82 | continue; 83 | Parameter s = Parameter.fromXMLElement((Element) node); 84 | addParameter(s); 85 | } 86 | } 87 | 88 | private Document createXMLDocument() throws ParserConfigurationException { 89 | Document doc = getXMLBuilder().newDocument(); 90 | 91 | Element parentEl = doc.createElement("ParamList"); 92 | doc.appendChild(parentEl); 93 | 94 | for (String s : paramOrder) { 95 | parentEl.appendChild(parameters.get(s).toXMLElement(doc)); 96 | } 97 | 98 | 99 | return doc; 100 | } 101 | 102 | /** 103 | * @deprecated Prefer using {@link #createXMLDocument()} because it is more flexible 104 | * and allow more clean code when overriding. For the current method, overriding it 105 | * requires to reimplement the code to add specific functionnality related to the subclass 106 | */ 107 | @Deprecated 108 | protected String createXMLstring() { 109 | String res = "\n"; 110 | res += "\n"; 111 | 112 | for (String s : paramOrder) { 113 | res += "\t" + parameters.get(s).toXMLstring() + "\n"; 114 | } 115 | res += "\n"; 116 | 117 | return res; 118 | } 119 | 120 | public void save() throws Exception { 121 | 122 | // converting content to XML String 123 | Transformer tf = TransformerFactory.newInstance().newTransformer(); 124 | tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); 125 | tf.setOutputProperty(OutputKeys.INDENT, "yes"); 126 | 127 | // the propery used below depend of the implementation of the Transformer 128 | // xslt and xalan are used in Oracle implementation of Java 129 | tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 130 | tf.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); 131 | 132 | String content; 133 | try (StringWriter swr = new StringWriter()) { 134 | tf.transform(new DOMSource(createXMLDocument()), new StreamResult(swr)); 135 | content = swr.toString(); 136 | } 137 | 138 | // saving XML to file (multiple try if needed) 139 | boolean ok = false; 140 | for(int i = 0; !ok; i++) { 141 | /* 142 | * Sometimes, the file is not writable, surely because an other 143 | * software is still reading/writing in the file. We try multiple 144 | * times to write the file until it succeeds. 145 | */ 146 | try (FileWriter wr = new FileWriter(file, false)) { 147 | wr.write(content); 148 | ok = true; 149 | } catch (IOException e) { 150 | /* In case of the file will not writable anymore (access right ?) 151 | * we count and stop if we've done to many trials 152 | */ 153 | if (i >= 10) 154 | throw e; 155 | Thread.sleep(50); // Wait before retry 156 | continue; 157 | } 158 | 159 | } 160 | } 161 | 162 | 163 | public void load() throws Exception { 164 | DocumentBuilder builder = getXMLBuilder(); 165 | Document doc = null; 166 | int i = 0; 167 | do { 168 | /* 169 | * Sometimes, the file is not readable when we receive the notification 170 | * from the watcher (surely because an other software is still writing 171 | * in the file). We try multiple times to read the file until it 172 | * succeeds. 173 | */ 174 | try { 175 | doc = builder.parse(file); 176 | } catch (Exception e) { 177 | /* In case of the file will not readable anymore (deleted ? ) 178 | * we count and stop if we've done to many trials 179 | */ 180 | i++; 181 | if (i >= 10) 182 | throw e; 183 | Thread.sleep(50); // Wait before retry 184 | } 185 | } while (doc == null); 186 | readDocument(doc); 187 | } 188 | 189 | 190 | 191 | public void addParameter(Parameter s) { 192 | parameters.put(s.name, s); 193 | paramOrder.add(s.name); 194 | } 195 | 196 | public Parameter getParameter(String name) { 197 | return parameters.get(name); 198 | } 199 | 200 | public void removeParameter(String name) { 201 | parameters.remove(name); 202 | } 203 | 204 | public List getAll() { 205 | ArrayList res = new ArrayList<>(); 206 | 207 | for (String s : paramOrder) { 208 | res.add(parameters.get(s)); 209 | } 210 | return res; 211 | } 212 | 213 | 214 | } 215 | -------------------------------------------------------------------------------- /src/gui/src/main/java/fr/univ_lille1/libparamtuner/gui/MainFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail, Géry Casiez 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner.gui; 19 | 20 | import java.io.File; 21 | import java.io.UnsupportedEncodingException; 22 | import java.math.BigInteger; 23 | import java.security.MessageDigest; 24 | import java.security.NoSuchAlgorithmException; 25 | import java.util.concurrent.atomic.AtomicBoolean; 26 | import java.util.prefs.BackingStoreException; 27 | import java.util.prefs.Preferences; 28 | 29 | import javafx.application.Application; 30 | import javafx.application.Platform; 31 | import javafx.beans.property.DoubleProperty; 32 | import javafx.beans.property.SimpleDoubleProperty; 33 | import javafx.scene.Scene; 34 | import javafx.scene.control.Alert; 35 | import javafx.scene.control.Alert.AlertType; 36 | import javafx.scene.control.CheckMenuItem; 37 | import javafx.scene.control.Label; 38 | import javafx.scene.control.Menu; 39 | import javafx.scene.control.MenuBar; 40 | import javafx.scene.control.MenuItem; 41 | import javafx.scene.control.ScrollPane; 42 | import javafx.scene.control.ScrollPane.ScrollBarPolicy; 43 | import javafx.scene.control.SeparatorMenuItem; 44 | import javafx.scene.image.Image; 45 | import javafx.scene.input.KeyCode; 46 | import javafx.scene.input.KeyCodeCombination; 47 | import javafx.scene.input.KeyCombination; 48 | import javafx.scene.layout.BorderPane; 49 | import javafx.scene.layout.HBox; 50 | import javafx.scene.layout.VBox; 51 | import javafx.stage.FileChooser; 52 | import javafx.stage.FileChooser.ExtensionFilter; 53 | import javafx.stage.Stage; 54 | 55 | import fr.univ_lille1.libparamtuner.gui.parameters_panel.ParameterPanel; 56 | import fr.univ_lille1.libparamtuner.parameters.Parameter; 57 | import fr.univ_lille1.libparamtuner.parameters.ParameterFile; 58 | 59 | public class MainFrame extends Application { 60 | 61 | private Stage stage; 62 | private Scene scene; 63 | 64 | final FileChooser fileChooser = new FileChooser(); 65 | private VBox contentPanel; 66 | public ScrollPane contentScroll; // TODO private 67 | private MenuItem btnSave; 68 | Menu openrecent; 69 | 70 | public DoubleProperty minLabelSize = new SimpleDoubleProperty(0); // TODO private 71 | 72 | private File file; 73 | private ParameterFile loadedFile = null; 74 | private boolean saved = true; 75 | private boolean autosave = true; 76 | 77 | private SaveThread saveThread = new SaveThread(); 78 | 79 | private Preferences prefs; 80 | 81 | @Override 82 | public void start(Stage primaryStage) throws Exception { 83 | stage = primaryStage; 84 | stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("icon.png"))); 85 | 86 | stage.setOnCloseRequest((event) -> { 87 | if (confirmSaveBeforeClosingFile()) { 88 | stage.hide(); 89 | try { 90 | prefs.sync(); 91 | } catch (BackingStoreException e1) { 92 | e1.printStackTrace(); 93 | } 94 | System.exit(0); 95 | } 96 | else { 97 | event.consume(); 98 | } 99 | }); 100 | 101 | // Save settings in a persistent way 102 | prefs = Preferences.userRoot().node(this.getClass().getName()); 103 | if (getParameters().getRaw().size() > 0) 104 | file = new File(getParameters().getRaw().get(0)); 105 | else 106 | file = new File(prefs.get("lastpath","")); 107 | autosave = prefs.getBoolean("autosave", true); 108 | 109 | BorderPane globalPanel = new BorderPane(); 110 | 111 | double windowWidth = prefs.getDouble(getCode(file.getPath()) + "width", 300); 112 | double windowHeight = prefs.getDouble(getCode(file.getPath()) + "height", 300); 113 | 114 | scene = new Scene(globalPanel, windowWidth, windowHeight); 115 | stage.setScene(scene); 116 | stage.sizeToScene(); 117 | stage.centerOnScreen(); 118 | 119 | stage.setMinWidth(250); 120 | stage.setMinHeight(250); 121 | 122 | 123 | MenuBar menuBar = new MenuBar(); 124 | menuBar.setUseSystemMenuBar(true); 125 | 126 | // File 127 | Menu menu1 = new Menu("File"); 128 | KeyCombination krfile = new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN); 129 | menu1.setAccelerator(krfile); 130 | 131 | // Open... 132 | MenuItem open = new MenuItem("Open..."); 133 | KeyCombination kropen = new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN); 134 | open.setAccelerator(kropen); 135 | open.setOnAction(e -> { 136 | File f = fileChooser.showOpenDialog(stage); 137 | if (f != null) { 138 | setFilePathAndLoad(f.getPath()); 139 | } 140 | }); 141 | 142 | // Open recent 143 | //openrecent = new Menu("Open Recent"); 144 | SeparatorMenuItem smi = new SeparatorMenuItem(); 145 | 146 | // Save 147 | btnSave = new MenuItem("Save"); 148 | KeyCombination krsave = new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN); 149 | btnSave.setAccelerator(krsave); 150 | btnSave.setOnAction(e -> saveFile()); 151 | btnSave.setDisable(true); 152 | 153 | // Auto save 154 | CheckMenuItem chckbxAutosave = new CheckMenuItem("Auto save"); 155 | chckbxAutosave.setSelected(autosave); 156 | chckbxAutosave.setOnAction(e -> setAutosave(chckbxAutosave.isSelected())); 157 | SeparatorMenuItem smi2 = new SeparatorMenuItem(); 158 | 159 | // Revert file 160 | MenuItem btnRevert = new MenuItem("Revert file"); 161 | KeyCombination krrevert = new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN); 162 | btnRevert.setAccelerator(krrevert); 163 | btnRevert.setOnAction(e -> { 164 | /* manually set 'saved' to true to avoid dialog that ask for saving while 165 | * we wan't to revert file (useless to revert just after saving) 166 | */ 167 | saved = true; 168 | loadFile(file); 169 | }); 170 | 171 | menu1.getItems().addAll(open, smi, btnSave, chckbxAutosave, smi2, btnRevert); 172 | 173 | // Help 174 | Menu menu2 = new Menu("Help"); 175 | 176 | // About 177 | MenuItem btnAbout = new MenuItem("About"); 178 | btnAbout.setOnAction(e -> { 179 | Alert alert = new Alert(AlertType.INFORMATION); 180 | alert.setTitle("About"); 181 | alert.setHeaderText(null); 182 | alert.setContentText("ParamTunerGUI version 1.2\n\nParamTunerGUI is part of libParamTuner\nGet more information on https://github.com/casiez/libparamtuner"); 183 | 184 | alert.showAndWait(); 185 | }); 186 | menu2.getItems().add(btnAbout); 187 | menuBar.getMenus().addAll(menu1, menu2); 188 | globalPanel.setTop(menuBar); 189 | 190 | fileChooser.setInitialDirectory(new File(".")); 191 | ExtensionFilter xmlFilter = new ExtensionFilter("XML Files", "*.xml"); 192 | fileChooser.getExtensionFilters().add(xmlFilter); 193 | fileChooser.getExtensionFilters().add(new ExtensionFilter("All files", "*")); 194 | fileChooser.setSelectedExtensionFilter(xmlFilter); 195 | 196 | 197 | contentScroll = new ScrollPane(); 198 | contentScroll.setVbarPolicy(ScrollBarPolicy.AS_NEEDED); 199 | //contentScroll.setHbarPolicy(ScrollBarPolicy.AS_NEEDED); 200 | globalPanel.setCenter(contentScroll); 201 | 202 | contentPanel = new VBox(); 203 | contentScroll.setContent(contentPanel); 204 | contentScroll.setFitToWidth(true); 205 | 206 | 207 | scene.widthProperty().addListener((observableValue, oldSceneWidth, newSceneWidth) -> { 208 | prefs.putDouble(getCode(file.getPath()) + "width", (double)newSceneWidth); 209 | }); 210 | 211 | scene.heightProperty().addListener((observableValue, oldSceneHeight, newSceneHeight) -> { 212 | prefs.putDouble(getCode(file.getPath()) + "height", (double)newSceneHeight); 213 | }); 214 | 215 | saveThread.start(); 216 | 217 | loadFile(file); 218 | updateTitle(); 219 | stage.show(); 220 | } 221 | 222 | private static String getCode(String filepath) { 223 | String res = ""; 224 | try { 225 | MessageDigest md = MessageDigest.getInstance("MD5"); 226 | byte bytes[] = md.digest(filepath.getBytes("ISO-8859-1")); 227 | BigInteger bi = new BigInteger(1, bytes); 228 | res = String.format("%0" + (bytes.length << 1) + "X", bi); 229 | //System.out.println(res); 230 | } catch (NoSuchAlgorithmException e) { 231 | e.printStackTrace(); 232 | } catch (UnsupportedEncodingException e) { 233 | e.printStackTrace(); 234 | } 235 | return res; 236 | } 237 | 238 | private void saveFile() { 239 | if (saved || loadedFile == null) 240 | return; 241 | 242 | saveThread.askForSave(); 243 | 244 | setSaved(true); 245 | 246 | } 247 | 248 | 249 | 250 | /** 251 | * Ask to the user if he want to save or not save the file before closing it. 252 | * If the user want to save the file, it is saved inside this method. 253 | * @return true if the user want to close the file (with or without saving) or if the file is already saved, false if the user click cancel. 254 | */ 255 | private boolean confirmSaveBeforeClosingFile() { 256 | if (saved) 257 | return true; 258 | String ret = FXDialogUtils.showConfirmDialog("Save current file ?", null, "Do you want to save the current file?", 259 | "Yes", "No", "Cancel"); 260 | if (ret == null || ret.equals("Cancel")) 261 | return false; 262 | if (ret.equals("Yes")) 263 | saveFile(); 264 | return true; 265 | } 266 | 267 | public void loadFile(File f) { 268 | 269 | if (new File("").equals(f)) { 270 | String value = FXDialogUtils.showConfirmDialog("Error", null, "Path not specified. Do you want to open?", "Yes", "No"); 271 | if ("Yes".equals(value)) { 272 | f = fileChooser.showOpenDialog(stage); 273 | if (f != null) 274 | setFilePathAndLoad(f.getPath()); 275 | } 276 | return; 277 | } 278 | 279 | if (!confirmSaveBeforeClosingFile()) 280 | return; 281 | 282 | clearConfigEntries(); 283 | 284 | 285 | ParameterFile pFile; 286 | prefs.put("lastpath", f.getPath()); 287 | 288 | 289 | try { 290 | pFile = new ParameterFile(f.getPath(), true); 291 | 292 | for (Parameter p : pFile.getAll()) { 293 | addConfigEntry(p); 294 | } 295 | 296 | 297 | 298 | 299 | loadedFile = pFile; 300 | 301 | } catch (Exception e) { 302 | e.printStackTrace(); 303 | clearConfigEntries(); 304 | String value = FXDialogUtils.showConfirmDialog("Unable to load the file", "Path: " + f.getPath(), e.getMessage()+"\n\nDo you want to open another file?", "Yes", "No"); 305 | if ("Yes".equals(value)) { 306 | f = fileChooser.showOpenDialog(stage); 307 | if (f != null) 308 | setFilePathAndLoad(f.getPath()); 309 | } 310 | return; 311 | } 312 | 313 | } 314 | 315 | private void clearConfigEntries() { 316 | contentPanel.getChildren().forEach(entry -> ((Label)((HBox)((ParameterPanel)entry).getCenter()).getChildren().get(0)).minWidthProperty().unbind()); 317 | contentPanel.getChildren().clear(); 318 | minLabelSize.setValue(0); 319 | } 320 | 321 | private void addConfigEntry(Parameter p) { 322 | contentPanel.getChildren().add(ParameterPanel.fromParameter(this, contentPanel.getChildren().size(), p)); 323 | } 324 | 325 | private void setFileAndLoad(File f) { 326 | file = f; 327 | updateTitle(); 328 | loadFile(file); 329 | } 330 | 331 | public void setFilePathAndLoad(String path) { 332 | setFileAndLoad(new File(path.trim())); 333 | } 334 | 335 | public void onContentModify() { 336 | setSaved(false); 337 | if (autosave) 338 | saveFile(); 339 | } 340 | 341 | private void setSaved(boolean s) { 342 | saved = s; 343 | updateTitle(); 344 | updateSaveButton(); 345 | } 346 | 347 | private void updateTitle() { 348 | String t = "ParamTuner GUI"; 349 | if (file != null && !new File("").equals(file)) { 350 | t = file.getName() + " - " + t; 351 | if (!saved) 352 | t = "*" + t; 353 | } 354 | stage.setTitle(t); 355 | } 356 | 357 | private void setAutosave(boolean as) { 358 | autosave = as; 359 | prefs.putBoolean("autosave", as); 360 | updateSaveButton(); 361 | if (autosave && !saved) { 362 | saveFile(); 363 | } 364 | } 365 | 366 | private void updateSaveButton() { 367 | btnSave.setDisable(autosave || saved); 368 | } 369 | 370 | private class SaveThread extends Thread { 371 | 372 | private AtomicBoolean wantToSave = new AtomicBoolean(false); 373 | 374 | @Override 375 | public void run() { 376 | try { 377 | for(;;) { 378 | AtomicUtils.waitForValue(wantToSave, true, 50); 379 | wantToSave.set(false); 380 | 381 | try { 382 | loadedFile.save(); 383 | } catch (Exception e) { 384 | Platform.runLater(() -> FXDialogUtils.showExceptionDialog("Unable to save the file", "Path: " + loadedFile.file, e)); 385 | return; 386 | } 387 | 388 | Thread.sleep(100); 389 | } 390 | } catch (InterruptedException e) { 391 | return; 392 | } 393 | } 394 | 395 | public void askForSave() { 396 | wantToSave.set(true); 397 | } 398 | } 399 | } 400 | -------------------------------------------------------------------------------- /src/java/src/main/java/fr/univ_lille1/libparamtuner/ParamTuner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * libParamTuner 3 | * Copyright (C) 2017 Marc Baloup, Veïs Oudjail 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package fr.univ_lille1.libparamtuner; 19 | 20 | import java.io.File; 21 | import java.io.FileNotFoundException; 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | import java.util.function.Consumer; 26 | import java.util.logging.Level; 27 | import java.util.logging.Logger; 28 | 29 | import fr.univ_lille1.libparamtuner.parameters.Parameter; 30 | import fr.univ_lille1.libparamtuner.parameters.ParameterFile; 31 | import fr.univ_lille1.libparamtuner.parameters.Type; 32 | 33 | /** 34 | * Class allowing developers to set up internal software settings in real-time. 35 | * It avoid repetitively compile a whole software every time we need to change 36 | * a constant value inside the source code. 37 | *

38 | * How to use this library ? 39 | * 40 | *

    41 | *
  1. Create an XML file. It must contain a parent node <ParamNode>, 42 | * which contains itseft some node that respect theses rules : 43 | *
      44 | *
    • The name of the node is the name of the parameter
    • 45 | *
    • The node have a type attribute wich describe the type of the parameter
    • 46 | *
    • The node have a value attribe that contains the value of the parameter
    • 47 | *
    48 | * For example : 49 | *
     50 |  *<ParamNode>
     51 |  *	<myString type="string" value="foo"/>
     52 |  *	<myInteger type="int" value="183"/>
     53 |  *</ParamNode>
    54 | *
  2. 55 | *
  3. 56 | * Call the method {@link #load(String)} to monitor modifications of the XML file. 57 | *
  4. 58 | *
  5. Then you must say to the library which variable will be updated when the file is modified.
    59 | * The library can only update static variables or member variable (due to Java limitations).
    60 | * Example code : 61 | *
     62 |  *  class Foo {
     63 |  *  	// values to update
     64 |  *  	public static int intValue;
     65 |  *  	public static String stringValue;
     66 |  *  
     67 |  *  	// setter for intValue;
     68 |  *  	public static void setInt(int newValue) { intValue = newValue; }
     69 |  *  	
     70 |  *  	public static void main(String[] args) throws Exception {
     71 |  *  		
     72 |  *  		ParamTuner.load("settings.xml"); // relative path are allowed
     73 |  *  
     74 |  *  		// we use lambda expression here. v is the new value read in file.
     75 |  *  		ParamTuner.bind("myString", String.class, v -> stringValue = v);
     76 |  *  		
     77 |  *  		// we use method reference here, if you have a setter for your variable
     78 |  *  		ParamTuner.bind("myInteger", Integer.class, Foo::setInt); 
     79 |  *  		
     80 |  *  		while(true) { // your main loop
     81 |  *  			Thread.sleep(500);
     82 |  *  			System.out.println(intValue + " " + stringValue);
     83 |  *  		}
     84 |  *  	}
     85 |  *  }
    86 | * For this example, when the file is saved with the XML example above, intValue 87 | * will contain 123 and stringValue will contain "foo". 88 | * 89 | *
  6. 90 | *
91 | * 92 | * 93 | * 94 | * 95 | * 96 | * 97 | * 98 | * 99 | * 100 | * 101 | * 102 | * 103 | * 104 | * 105 | * 106 | * 107 | * 108 | * 109 | * 110 | * 111 | * 112 | * 113 | * 114 | * 115 | * 116 | * 117 | * 118 | * 119 | *
List of supported types
Java typetype attributevalue attribute interpretation
boolean, {@link Boolean}bool or booleanSee {@link Boolean#parseBoolean(String)}
{@link String}stringAs is
int, {@link Integer}, long, {@link Long}int, integer or longSee {@link Long#parseLong(String)}
double, {@link Double}, float, {@link Float}double or floatSee {@link Double#parseDouble(String)}
120 | * 121 | * 122 | */ 123 | public class ParamTuner { 124 | 125 | /* package */ static final Logger logger = Logger.getLogger(ParamTuner.class.getName()); 126 | private static final Level defaultLevel = logger.getLevel(); 127 | 128 | /* 129 | * Static data structure 130 | */ 131 | private static FileWatcher fileWatcherInstance; 132 | 133 | private static boolean useUpdateFunction = false; 134 | private static boolean someParametersChanged = true; 135 | 136 | private static Map> binding = Collections.synchronizedMap(new HashMap<>()); 137 | 138 | private static class Bind { 139 | public final Class javaType; 140 | public final Consumer setter; 141 | 142 | private Bind(Class jType, Consumer s) { 143 | javaType = jType; 144 | setter = s; 145 | } 146 | } 147 | 148 | /* 149 | * Private static method 150 | */ 151 | @SuppressWarnings("unchecked") 152 | private static synchronized void loadFile() { 153 | if (fileWatcherInstance == null) 154 | return; 155 | 156 | try { 157 | ParameterFile parameterFile = new ParameterFile(fileWatcherInstance.confFile, true); 158 | 159 | for (Parameter param : parameterFile.getAll()) { 160 | 161 | try { 162 | if (binding.containsKey(param.name)) { 163 | @SuppressWarnings("rawtypes") 164 | Bind bind = binding.get(param.name); 165 | Type t = Type.getTypeFromJavaType(bind.javaType); 166 | if (t.parameterClass.isInstance(param)) { 167 | bind.setter.accept(Type.getFunctionGetterFromJavaType(bind.javaType, t.parameterClass) 168 | .apply(t.parameterClass.cast(param))); 169 | } 170 | else { 171 | logger.severe("Setting '" + param.name + "' has type '" + param.getType().name().toLowerCase() 172 | + "' in XML file but is binded to Java type " + bind.javaType.getSimpleName() 173 | + "."); 174 | } 175 | } 176 | else { 177 | logger.warning("Setting '" + param.name + "' is not binded to a variable."); 178 | } 179 | 180 | } catch (NumberFormatException e) { 181 | logger.log(Level.SEVERE, "Value for setting '" + param.name + "' is not valid.", e); 182 | } 183 | } 184 | } catch (FileNotFoundException e) { 185 | logger.log(Level.SEVERE, e.getMessage(), e); 186 | } catch (Exception e) { 187 | logger.log(Level.SEVERE, "Error while parsing XML file", e); 188 | } 189 | } 190 | 191 | 192 | 193 | /** 194 | * @param fw the fileWatcher that call this method 195 | */ 196 | private static void fileModificationCallback(FileWatcher fw) { 197 | if (useUpdateFunction) 198 | someParametersChanged = true; 199 | else 200 | loadFile(); 201 | } 202 | 203 | 204 | /* 205 | * Public static methods (public API) 206 | */ 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | /** 215 | * Start listening modifications of the specified file.
216 | * 217 | * Calling this method is equivalent to : 218 | * 219 | *
ParamTuner.load(new File(configFile), false);
220 | * 221 | * @param configFile The absolute or relative path to the file. 222 | * 223 | * @see #load(File, boolean) 224 | */ 225 | public static void load(String configFile) { 226 | load(new File(configFile), false); 227 | } 228 | 229 | 230 | 231 | 232 | /** 233 | * Start listening modifications of the specified file.
234 | * 235 | * Calling this method is equivalent to : 236 | * 237 | *
ParamTuner.load(configFile, false);
238 | * 239 | @param configFile the {@link File} to listen to 240 | * 241 | * @see #load(File, boolean) 242 | */ 243 | public static void load(File configFile) { 244 | load(configFile, false); 245 | } 246 | 247 | 248 | 249 | 250 | /** 251 | * Start listening modifications of the specified file.
252 | * 253 | * Calling this method is equivalent to : 254 | * 255 | *
ParamTuner.load(new File(configFile), manualUpdate);
256 | * 257 | * @param configFile The absolute or relative path to the file. 258 | * @param manualUpdate determine if parameters are updated using update() function 259 | * 260 | * @see #load(File, boolean) 261 | */ 262 | public static void load(String configFile, boolean manualUpdate) { 263 | load(new File(configFile), manualUpdate); 264 | } 265 | 266 | 267 | /** 268 | * Start listening modifications of the specified file.
269 |
270 | After this method call, when the specified file is modified 271 | by another program, the variables binded with one of the bind...() method 272 | are updated to their new values from file.
273 |
274 | The specified file's content must be an XML file with a root node 275 | "ParamList". Direct child node of the ParamList node represent a 276 | parameter in your program, for example : 277 |
<paramName value="foo" type="string"/>
278 | 279 | 280 | If a node is not binded to a variable, a message will be sent to standard 281 | error stream. If a node has not a valid type or value, an error will be 282 | displayed too, and the variable will not be updated.
283 |
284 | When this method is called multiple times, the current call disable 285 | listener of the previous call. 286 | 287 | @param configFile the {@link File} to listen to 288 | @param manualUpdate determine if parameters are updated using update() function 289 | 290 | */ 291 | public static synchronized void load(File configFile, boolean manualUpdate) { 292 | if (fileWatcherInstance != null) { 293 | fileWatcherInstance.interrupt(); 294 | } 295 | 296 | useUpdateFunction = manualUpdate; 297 | 298 | try { 299 | fileWatcherInstance = new FileWatcher(configFile, ParamTuner::fileModificationCallback); 300 | } catch (Exception e) { 301 | logger.log(Level.SEVERE, "Can't start Watcher thread because of Exception:", e); 302 | fileWatcherInstance = null; 303 | return; 304 | } 305 | fileWatcherInstance.start(); 306 | } 307 | 308 | 309 | /** 310 | Bind a variable with a parameter in the XML file.
311 |
312 | This method may be called before or after calling one of load() methods. 313 | The internal storage of binded values is always preserved.
314 |
315 | If a variable is already binded with the specified name, the old 316 | binding will be erased. 317 | 318 | @param type of the variable binded to the parameter. This is related to javaType 319 | method parameter. 320 | 321 | @param parameterName the parameter name, that is equal to the node name 322 | containing the parameter value. 323 | 324 | @param javaType the javaType of the variable that has to be updated. 325 | Primitive {@link Class} object are not supported. Please specify wrapper 326 | Class object instead (even if your variable is primitive) 327 | 328 | @param setter a {@link Consumer} that take the new value as parameter 329 | and should apply this new value to the variable. 330 | */ 331 | public synchronized static void bind(String parameterName, Class javaType, Consumer setter) { 332 | if (javaType.isPrimitive()) { 333 | throw new IllegalArgumentException( 334 | "Please specify wrapper Class object instead of primitive Class object, on parameter 'javaType'"); 335 | } 336 | if (Type.getTypeFromJavaType(javaType) == null) { 337 | throw new IllegalArgumentException( 338 | "Java type " + javaType.getSimpleName() + " is not supported for binding."); 339 | } 340 | binding.put(parameterName, new Bind<>(javaType, setter)); 341 | } 342 | 343 | 344 | /** 345 | Unbind a previously binded variable. 346 | 347 | If there is no binding with the specified name, this method does nothing. 348 | 349 | @param parameterName the parameter name, that is equal to the node name 350 | containing the parameter value. 351 | */ 352 | public synchronized static void unbind(String parameterName) { 353 | binding.remove(parameterName); 354 | } 355 | 356 | 357 | 358 | private static boolean once = true; 359 | 360 | /** 361 | Manually update all binded variables if the file was modified since 362 | the last update. 363 | 364 | This only work if the load(...) method is called with the 365 | manualUpdate parameter set to true. 366 | 367 | This method also work juste after calling the load(...) method. 368 | 369 | */ 370 | public synchronized static void update() { 371 | if (useUpdateFunction) { 372 | if (someParametersChanged) { 373 | loadFile(); 374 | someParametersChanged = false; 375 | } 376 | } 377 | else { 378 | if (once) { 379 | logger.warning("libParamTuner update() call is useless unless manualUpdate parameter in load method is set to true"); 380 | once = false; 381 | } 382 | } 383 | } 384 | 385 | 386 | 387 | 388 | /** 389 | * Set if log messages under Level.SEVERE are displayed. 390 | * 391 | * Default is true 392 | * 393 | * @param log true if log messages are displayed 394 | */ 395 | public static void logWarnings(boolean log) { 396 | logger.setLevel(log ? defaultLevel : Level.SEVERE); 397 | } 398 | 399 | } 400 | -------------------------------------------------------------------------------- /src/cpp/doxygen.conf: -------------------------------------------------------------------------------- 1 | # Doxyfile 0.49-990405 2 | # This file describes the settings to be used by doxygen for a project 3 | # 4 | # All text after a hash (#) is considered a comment and will be ignored 5 | # The format is: 6 | # TAG = value [value, ...] 7 | # Values that contain spaces should be placed between quotes (" ") 8 | 9 | #--------------------------------------------------------------------------- 10 | # General configuration options 11 | #--------------------------------------------------------------------------- 12 | 13 | # The PROJECT_NAME tag is a single word (or a sequence of word surrounded 14 | # by quotes) that should identify the project. 15 | 16 | PROJECT_NAME = "LibParamTuner" 17 | 18 | # The PROJECT_NUMBER tag can be used to enter a project or revision number. 19 | # This could be handy for archiving the generated documentation or 20 | # if some version control system is used. 21 | 22 | PROJECT_NUMBER = 23 | 24 | # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 25 | # base path where the generated documentation will be put. 26 | # If a relative path is entered, it will be relative to the location 27 | # where doxygen was started. If left blank the current directory will be used. 28 | 29 | OUTPUT_DIRECTORY = ../../doc/cpp 30 | 31 | # The OUTPUT_LANGUAGE tag is used to specify the language in which all 32 | # documentation generated by doxygen is written. Doxygen will use this 33 | # information to generate all constant output in the proper language. 34 | # The default language is English, other supported languages are: Dutch 35 | 36 | OUTPUT_LANGUAGE = English 37 | 38 | # The QUIET tag can be used to turn on/off the messages that are generated 39 | # by doxygen. Possible values are YES and NO. If left blank NO is used. 40 | 41 | QUIET = NO 42 | 43 | # The WARNINGS tag can be used to turn on/off the warning messages that are 44 | # generated by doxygen. Possible values are YES and NO. If left blank 45 | # NO is used. 46 | 47 | WARNINGS = YES 48 | 49 | # The DISABLE_INDEX tag can be used to turn on/off the condensed index at 50 | # top of each page. A value of NO (the default) enables the index and the 51 | # value YES disables it. 52 | 53 | DISABLE_INDEX = NO 54 | 55 | # If the EXTRACT_ALL tag is set to YES all classes and functions will be 56 | # included in the documentation, even if no documentation was available. 57 | 58 | EXTRACT_ALL = YES 59 | 60 | # If the EXTRACT_PRIVATE tag is set to YES all private members of a class 61 | # will be included in the documentation. 62 | 63 | EXTRACT_PRIVATE = NO 64 | 65 | # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 66 | # undocumented members inside documented classes or files. 67 | 68 | HIDE_UNDOC_MEMBERS = NO 69 | 70 | # If the HIDE_UNDOC_CLASSESS tag is set to YES, Doxygen will hide all 71 | # undocumented classes. 72 | 73 | HIDE_UNDOC_CLASSES = NO 74 | 75 | # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 76 | # include brief member descriptions after the members that are listed in 77 | # the file and class documentation (similar to JavaDoc). 78 | # Set to NO to disable this. 79 | 80 | BRIEF_MEMBER_DESC = YES 81 | 82 | # The INTERNAL_DOCS tag determines if documentation 83 | # that is typed after a \internal command is included. If the tag is set 84 | # to NO (the default) then the documentation will be excluded. 85 | # Set it to YES to include the internal documentation. 86 | 87 | INTERNAL_DOCS = NO 88 | 89 | # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 90 | # the brief description of a member or function before the detailed description. 91 | # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 92 | # brief descriptions will be completely suppressed. 93 | 94 | REPEAT_BRIEF = YES 95 | 96 | # If the FULL_PATH_NAMES tag is set to YES Doxygen will prepend the full 97 | # path before files name in the file list and in the header files. If set 98 | # to NO the shortest path that makes the file name unique will be used. 99 | 100 | FULL_PATH_NAMES = YES 101 | 102 | # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 103 | # can be used to strip a user defined part of the path. Stripping is 104 | # only done if the specified string matches the left-hand part of the path. 105 | 106 | STRIP_FROM_PATH = 107 | 108 | # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 109 | # generate a class diagram (in Html and LaTeX) for classes with base or 110 | # super classes. Setting the tag to NO turns the diagrams off. 111 | 112 | CLASS_DIAGRAMS = YES 113 | 114 | # If the CASE_SENSE_NAMES tag is set to NO (the default) then Doxygen 115 | # will only generate file names in lower case letters. If set to 116 | # YES upper case letters are also allowed. This is useful if you have 117 | # classes or files whose names only differ in case and if your file system 118 | # supports case sensitive file names. 119 | 120 | CASE_SENSE_NAMES = YES 121 | 122 | # If the VERBATIM_HEADERS tag is set the YES (the default) then Doxygen 123 | # will generate a verbatim copy of the header file for each class for 124 | # which an include is specified. Set to NO to disable this. 125 | 126 | VERBATIM_HEADERS = YES 127 | 128 | #--------------------------------------------------------------------------- 129 | # configuration options related to the input files 130 | #--------------------------------------------------------------------------- 131 | 132 | # The INPUT tag can be used to specify the files and/or directories that contain 133 | # documented source files. You may enter file names like "myfile.cpp" or 134 | # directories like "/usr/src/myproject". Separate the files or directories 135 | # with spaces. 136 | 137 | INPUT = suif/suif2b 138 | 139 | # If the value of the INPUT tag contains directories, you can use the 140 | # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 141 | # and *.h) to filter out the source-files in the directories. If left 142 | # blank all files are included. 143 | 144 | FILE_PATTERNS = *.h *.cpp *.cc 145 | 146 | # The RECURSIVE tag can be used to turn specify whether or not subdirectories 147 | # should be searched for input files as well. Possible values are YES and NO. 148 | # If left blank NO is used. 149 | 150 | RECURSIVE = YES 151 | 152 | # The EXCLUDE tag can be used to specify files and/or directories that should 153 | # excluded from the INPUT source files. This way you can easily exclude a 154 | # subdirectory from a directory tree whose root is specified with the INPUT tag. 155 | 156 | EXCLUDE = 157 | 158 | # If the value of the INPUT tag contains directories, you can use the 159 | # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 160 | # certain files from those directories. 161 | 162 | EXCLUDE_PATTERNS = 163 | 164 | # The EXAMPLE_PATH tag can be used to specify one or more files or 165 | # directories that contain example code fragments that are included (see 166 | # the \include command). 167 | 168 | EXAMPLE_PATH = 169 | 170 | # The INPUT_FILTER tag can be used to specify a program that doxygen should 171 | # invoke to filter for each input file. Doxygen will invoke the filter program 172 | # by executing (via popen()) the command , where 173 | # is the value of the INPUT_FILTER tag, and is the name of an 174 | # input file. Doxygen will then use the output that the filter program writes 175 | # to standard output. 176 | 177 | INPUT_FILTER = 178 | 179 | #--------------------------------------------------------------------------- 180 | # configuration options related to the HTML output 181 | #--------------------------------------------------------------------------- 182 | 183 | # If the GENERATE_HTML tag is set to YES (the default) Doxygen will 184 | # generate HTML output 185 | 186 | GENERATE_HTML = YES 187 | 188 | # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 189 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 190 | # put in front of it. If left blank `html' will be used as the default path. 191 | 192 | HTML_OUTPUT = 193 | 194 | # The HTML_HEADER tag can be used to specify a personal HTML header for 195 | # each generated HTML page. If it is left blank doxygen will generate a 196 | # standard header. 197 | 198 | HTML_HEADER = 199 | 200 | # The HTML_FOOTER tag can be used to specify a personal HTML footer for 201 | # each generated HTML page. If it is left blank doxygen will generate a 202 | # standard footer. 203 | 204 | HTML_FOOTER = 205 | 206 | #--------------------------------------------------------------------------- 207 | # configuration options related to the LaTeX output 208 | #--------------------------------------------------------------------------- 209 | 210 | # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 211 | # generate Latex output. 212 | 213 | GENERATE_LATEX = YES 214 | 215 | # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 216 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 217 | # put in front of it. If left blank `latex' will be used as the default path. 218 | 219 | LATEX_OUTPUT = 220 | 221 | # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 222 | # LaTeX documents. This may be useful for small projects and may help to 223 | # save some trees in general. 224 | 225 | COMPACT_LATEX = NO 226 | 227 | # The PAPER_TYPE tag can be used to set the paper type that is used 228 | # by the printer. Possible values are: a4, a4wide, letter, legal and 229 | # executive. If left blank a4wide will be used. 230 | 231 | PAPER_TYPE = a4wide 232 | 233 | # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 234 | # packages that should be included in the LaTeX output. 235 | 236 | EXTRA_PACKAGES = 237 | 238 | #--------------------------------------------------------------------------- 239 | # configuration options related to the man page output 240 | #--------------------------------------------------------------------------- 241 | 242 | # If the GENERATE_MAN tag is set to YES (the default) Doxygen will 243 | # generate man pages 244 | 245 | GENERATE_MAN = YES 246 | 247 | # The MAN_OUTPUT tag is used to specify where the man pages will be put. 248 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 249 | # put in front of it. If left blank `man' will be used as the default path. 250 | 251 | MAN_OUTPUT = 252 | 253 | #--------------------------------------------------------------------------- 254 | # Configuration options related to the preprocessor 255 | #--------------------------------------------------------------------------- 256 | 257 | # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 258 | # evaluate all C-preprocessor directives found in the sources and include 259 | # files. 260 | 261 | ENABLE_PREPROCESSING = YES 262 | 263 | # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 264 | # names in the source code. If set to NO (the default) only conditional 265 | # compilation will be performed. 266 | 267 | MACRO_EXPANSION = NO 268 | 269 | # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 270 | # in the INCLUDE_PATH (see below) will be search if a #include is found. 271 | 272 | SEARCH_INCLUDES = YES 273 | 274 | # The INCLUDE_PATH tag can be used to specify one or more directories that 275 | # contain include files that are not input files but should be processed by 276 | # the preprocessor. 277 | 278 | INCLUDE_PATH = 279 | 280 | # The PREDEFINED tag can be used to specify one or more macro names that 281 | # are defined before the preprocessor is started (similar to the -D option of 282 | # gcc). The argument of the tag is a list of macros of the form: name 283 | # or name=definition (no spaces). If the definition and the = are 284 | # omitted =1 is assumed. 285 | 286 | PREDEFINED = 287 | 288 | # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 289 | # then the macro expansion is limited to the macros specified with the 290 | # PREDEFINED tag. 291 | 292 | EXPAND_ONLY_PREDEF = NO 293 | 294 | #--------------------------------------------------------------------------- 295 | # Configuration options related to external references 296 | #--------------------------------------------------------------------------- 297 | 298 | # The TAGFILES tag can be used to specify one or more tagfiles. 299 | 300 | TAGFILES = 301 | 302 | # When a file name is specified after GENERATE_TAGFILE, doxygen will create 303 | # a tag file that is based on the input files it reads. 304 | 305 | GENERATE_TAGFILE = 306 | 307 | # If the ALLEXTERNALS tag is set to YES all external classes will be listed 308 | # in the class index. If set to NO only the inherited external classes 309 | # will be listed. 310 | 311 | ALLEXTERNALS = NO 312 | 313 | # The PERL_PATH should be the absolute path and name of the perl script 314 | # interpreter (i.e. the result of `which perl'). 315 | 316 | PERL_PATH = /usr/local/bin/perl 317 | 318 | #--------------------------------------------------------------------------- 319 | # Configuration options related to the search engine 320 | #--------------------------------------------------------------------------- 321 | 322 | # The SEARCHENGINE tag specifies whether or not a search engine should be 323 | # used. If set to NO the values of all tags below this one will be ignored. 324 | 325 | SEARCHENGINE = NO 326 | 327 | # The CGI_NAME tag should be the name of the CGI script that 328 | # starts the search engine (doxysearch) with the correct parameters. 329 | # A script with this name will be generated by doxygen. 330 | 331 | CGI_NAME = search.cgi 332 | 333 | # The CGI_URL tag should be the absolute URL to the directory where the 334 | # cgi binaries are located. See the documentation of your http daemon for 335 | # details. 336 | 337 | CGI_URL = 338 | 339 | # The DOC_URL tag should be the absolute URL to the directory where the 340 | # documentation is located. If left blank the absolute path to the 341 | # documentation, with file:// prepended to it, will be used. 342 | 343 | DOC_URL = 344 | 345 | # The DOC_ABSPATH tag should be the absolute path to the directory where the 346 | # documentation is located. If left blank the directory on the local machine 347 | # will be used. 348 | 349 | DOC_ABSPATH = 350 | 351 | # The BIN_ABSPATH tag must point to the directory where the doxysearch binary 352 | # is installed. 353 | 354 | BIN_ABSPATH = /usr/local/bin/ 355 | 356 | # The EXT_DOC_PATHS tag can be used to specify one or more paths to 357 | # documentation generated for other projects. This allows doxysearch to search 358 | # the documentation for these projects as well. 359 | 360 | EXT_DOC_PATHS = 361 | -------------------------------------------------------------------------------- /src/cpp/rapidxml-1.13/rapidxml_print.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_PRINT_HPP_INCLUDED 2 | #define RAPIDXML_PRINT_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! \file rapidxml_print.hpp This file contains rapidxml printer implementation 8 | 9 | #include "rapidxml.hpp" 10 | 11 | // Only include streams if not disabled 12 | #ifndef RAPIDXML_NO_STREAMS 13 | #include 14 | #include 15 | #endif 16 | 17 | namespace rapidxml 18 | { 19 | 20 | /////////////////////////////////////////////////////////////////////// 21 | // Printing flags 22 | 23 | const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function. 24 | 25 | /////////////////////////////////////////////////////////////////////// 26 | // Internal 27 | 28 | //! \cond internal 29 | namespace internal 30 | { 31 | 32 | /////////////////////////////////////////////////////////////////////////// 33 | // Internal character operations 34 | 35 | // Copy characters from given range to given output iterator 36 | template 37 | inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out) 38 | { 39 | while (begin != end) 40 | *out++ = *begin++; 41 | return out; 42 | } 43 | 44 | // Copy characters from given range to given output iterator and expand 45 | // characters into references (< > ' " &) 46 | template 47 | inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out) 48 | { 49 | while (begin != end) 50 | { 51 | if (*begin == noexpand) 52 | { 53 | *out++ = *begin; // No expansion, copy character 54 | } 55 | else 56 | { 57 | switch (*begin) 58 | { 59 | case Ch('<'): 60 | *out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';'); 61 | break; 62 | case Ch('>'): 63 | *out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';'); 64 | break; 65 | case Ch('\''): 66 | *out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';'); 67 | break; 68 | case Ch('"'): 69 | *out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';'); 70 | break; 71 | case Ch('&'): 72 | *out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';'); 73 | break; 74 | default: 75 | *out++ = *begin; // No expansion, copy character 76 | } 77 | } 78 | ++begin; // Step to next character 79 | } 80 | return out; 81 | } 82 | 83 | // Fill given output iterator with repetitions of the same character 84 | template 85 | inline OutIt fill_chars(OutIt out, int n, Ch ch) 86 | { 87 | for (int i = 0; i < n; ++i) 88 | *out++ = ch; 89 | return out; 90 | } 91 | 92 | // Find character 93 | template 94 | inline bool find_char(const Ch *begin, const Ch *end) 95 | { 96 | while (begin != end) 97 | if (*begin++ == ch) 98 | return true; 99 | return false; 100 | } 101 | 102 | /////////////////////////////////////////////////////////////////////////// 103 | // Internal printing operations 104 | 105 | // Print node 106 | template 107 | inline OutIt print_node(OutIt out, const xml_node *node, int flags, int indent) 108 | { 109 | // Print proper node type 110 | switch (node->type()) 111 | { 112 | 113 | // Document 114 | case node_document: 115 | out = print_children(out, node, flags, indent); 116 | break; 117 | 118 | // Element 119 | case node_element: 120 | out = print_element_node(out, node, flags, indent); 121 | break; 122 | 123 | // Data 124 | case node_data: 125 | out = print_data_node(out, node, flags, indent); 126 | break; 127 | 128 | // CDATA 129 | case node_cdata: 130 | out = print_cdata_node(out, node, flags, indent); 131 | break; 132 | 133 | // Declaration 134 | case node_declaration: 135 | out = print_declaration_node(out, node, flags, indent); 136 | break; 137 | 138 | // Comment 139 | case node_comment: 140 | out = print_comment_node(out, node, flags, indent); 141 | break; 142 | 143 | // Doctype 144 | case node_doctype: 145 | out = print_doctype_node(out, node, flags, indent); 146 | break; 147 | 148 | // Pi 149 | case node_pi: 150 | out = print_pi_node(out, node, flags, indent); 151 | break; 152 | 153 | // Unknown 154 | default: 155 | assert(0); 156 | break; 157 | } 158 | 159 | // If indenting not disabled, add line break after node 160 | if (!(flags & print_no_indenting)) 161 | *out = Ch('\n'), ++out; 162 | 163 | // Return modified iterator 164 | return out; 165 | } 166 | 167 | // Print children of the node 168 | template 169 | inline OutIt print_children(OutIt out, const xml_node *node, int flags, int indent) 170 | { 171 | for (xml_node *child = node->first_node(); child; child = child->next_sibling()) 172 | out = print_node(out, child, flags, indent); 173 | return out; 174 | } 175 | 176 | // Print attributes of the node 177 | template 178 | inline OutIt print_attributes(OutIt out, const xml_node *node, int flags) 179 | { 180 | for (xml_attribute *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) 181 | { 182 | if (attribute->name() && attribute->value()) 183 | { 184 | // Print attribute name 185 | *out = Ch(' '), ++out; 186 | out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out); 187 | *out = Ch('='), ++out; 188 | // Print attribute value using appropriate quote type 189 | if (find_char(attribute->value(), attribute->value() + attribute->value_size())) 190 | { 191 | *out = Ch('\''), ++out; 192 | out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out); 193 | *out = Ch('\''), ++out; 194 | } 195 | else 196 | { 197 | *out = Ch('"'), ++out; 198 | out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out); 199 | *out = Ch('"'), ++out; 200 | } 201 | } 202 | } 203 | return out; 204 | } 205 | 206 | // Print data node 207 | template 208 | inline OutIt print_data_node(OutIt out, const xml_node *node, int flags, int indent) 209 | { 210 | assert(node->type() == node_data); 211 | if (!(flags & print_no_indenting)) 212 | out = fill_chars(out, indent, Ch('\t')); 213 | out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out); 214 | return out; 215 | } 216 | 217 | // Print data node 218 | template 219 | inline OutIt print_cdata_node(OutIt out, const xml_node *node, int flags, int indent) 220 | { 221 | assert(node->type() == node_cdata); 222 | if (!(flags & print_no_indenting)) 223 | out = fill_chars(out, indent, Ch('\t')); 224 | *out = Ch('<'); ++out; 225 | *out = Ch('!'); ++out; 226 | *out = Ch('['); ++out; 227 | *out = Ch('C'); ++out; 228 | *out = Ch('D'); ++out; 229 | *out = Ch('A'); ++out; 230 | *out = Ch('T'); ++out; 231 | *out = Ch('A'); ++out; 232 | *out = Ch('['); ++out; 233 | out = copy_chars(node->value(), node->value() + node->value_size(), out); 234 | *out = Ch(']'); ++out; 235 | *out = Ch(']'); ++out; 236 | *out = Ch('>'); ++out; 237 | return out; 238 | } 239 | 240 | // Print element node 241 | template 242 | inline OutIt print_element_node(OutIt out, const xml_node *node, int flags, int indent) 243 | { 244 | assert(node->type() == node_element); 245 | 246 | // Print element name and attributes, if any 247 | if (!(flags & print_no_indenting)) 248 | out = fill_chars(out, indent, Ch('\t')); 249 | *out = Ch('<'), ++out; 250 | out = copy_chars(node->name(), node->name() + node->name_size(), out); 251 | out = print_attributes(out, node, flags); 252 | 253 | // If node is childless 254 | if (node->value_size() == 0 && !node->first_node()) 255 | { 256 | // Print childless node tag ending 257 | *out = Ch('/'), ++out; 258 | *out = Ch('>'), ++out; 259 | } 260 | else 261 | { 262 | // Print normal node tag ending 263 | *out = Ch('>'), ++out; 264 | 265 | // Test if node contains a single data node only (and no other nodes) 266 | xml_node *child = node->first_node(); 267 | if (!child) 268 | { 269 | // If node has no children, only print its value without indenting 270 | out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out); 271 | } 272 | else if (child->next_sibling() == 0 && child->type() == node_data) 273 | { 274 | // If node has a sole data child, only print its value without indenting 275 | out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out); 276 | } 277 | else 278 | { 279 | // Print all children with full indenting 280 | if (!(flags & print_no_indenting)) 281 | *out = Ch('\n'), ++out; 282 | out = print_children(out, node, flags, indent + 1); 283 | if (!(flags & print_no_indenting)) 284 | out = fill_chars(out, indent, Ch('\t')); 285 | } 286 | 287 | // Print node end 288 | *out = Ch('<'), ++out; 289 | *out = Ch('/'), ++out; 290 | out = copy_chars(node->name(), node->name() + node->name_size(), out); 291 | *out = Ch('>'), ++out; 292 | } 293 | return out; 294 | } 295 | 296 | // Print declaration node 297 | template 298 | inline OutIt print_declaration_node(OutIt out, const xml_node *node, int flags, int indent) 299 | { 300 | // Print declaration start 301 | if (!(flags & print_no_indenting)) 302 | out = fill_chars(out, indent, Ch('\t')); 303 | *out = Ch('<'), ++out; 304 | *out = Ch('?'), ++out; 305 | *out = Ch('x'), ++out; 306 | *out = Ch('m'), ++out; 307 | *out = Ch('l'), ++out; 308 | 309 | // Print attributes 310 | out = print_attributes(out, node, flags); 311 | 312 | // Print declaration end 313 | *out = Ch('?'), ++out; 314 | *out = Ch('>'), ++out; 315 | 316 | return out; 317 | } 318 | 319 | // Print comment node 320 | template 321 | inline OutIt print_comment_node(OutIt out, const xml_node *node, int flags, int indent) 322 | { 323 | assert(node->type() == node_comment); 324 | if (!(flags & print_no_indenting)) 325 | out = fill_chars(out, indent, Ch('\t')); 326 | *out = Ch('<'), ++out; 327 | *out = Ch('!'), ++out; 328 | *out = Ch('-'), ++out; 329 | *out = Ch('-'), ++out; 330 | out = copy_chars(node->value(), node->value() + node->value_size(), out); 331 | *out = Ch('-'), ++out; 332 | *out = Ch('-'), ++out; 333 | *out = Ch('>'), ++out; 334 | return out; 335 | } 336 | 337 | // Print doctype node 338 | template 339 | inline OutIt print_doctype_node(OutIt out, const xml_node *node, int flags, int indent) 340 | { 341 | assert(node->type() == node_doctype); 342 | if (!(flags & print_no_indenting)) 343 | out = fill_chars(out, indent, Ch('\t')); 344 | *out = Ch('<'), ++out; 345 | *out = Ch('!'), ++out; 346 | *out = Ch('D'), ++out; 347 | *out = Ch('O'), ++out; 348 | *out = Ch('C'), ++out; 349 | *out = Ch('T'), ++out; 350 | *out = Ch('Y'), ++out; 351 | *out = Ch('P'), ++out; 352 | *out = Ch('E'), ++out; 353 | *out = Ch(' '), ++out; 354 | out = copy_chars(node->value(), node->value() + node->value_size(), out); 355 | *out = Ch('>'), ++out; 356 | return out; 357 | } 358 | 359 | // Print pi node 360 | template 361 | inline OutIt print_pi_node(OutIt out, const xml_node *node, int flags, int indent) 362 | { 363 | assert(node->type() == node_pi); 364 | if (!(flags & print_no_indenting)) 365 | out = fill_chars(out, indent, Ch('\t')); 366 | *out = Ch('<'), ++out; 367 | *out = Ch('?'), ++out; 368 | out = copy_chars(node->name(), node->name() + node->name_size(), out); 369 | *out = Ch(' '), ++out; 370 | out = copy_chars(node->value(), node->value() + node->value_size(), out); 371 | *out = Ch('?'), ++out; 372 | *out = Ch('>'), ++out; 373 | return out; 374 | } 375 | 376 | } 377 | //! \endcond 378 | 379 | /////////////////////////////////////////////////////////////////////////// 380 | // Printing 381 | 382 | //! Prints XML to given output iterator. 383 | //! \param out Output iterator to print to. 384 | //! \param node Node to be printed. Pass xml_document to print entire document. 385 | //! \param flags Flags controlling how XML is printed. 386 | //! \return Output iterator pointing to position immediately after last character of printed text. 387 | template 388 | inline OutIt print(OutIt out, const xml_node &node, int flags = 0) 389 | { 390 | return internal::print_node(out, &node, flags, 0); 391 | } 392 | 393 | #ifndef RAPIDXML_NO_STREAMS 394 | 395 | //! Prints XML to given output stream. 396 | //! \param out Output stream to print to. 397 | //! \param node Node to be printed. Pass xml_document to print entire document. 398 | //! \param flags Flags controlling how XML is printed. 399 | //! \return Output stream. 400 | template 401 | inline std::basic_ostream &print(std::basic_ostream &out, const xml_node &node, int flags = 0) 402 | { 403 | print(std::ostream_iterator(out), node, flags); 404 | return out; 405 | } 406 | 407 | //! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process. 408 | //! \param out Output stream to print to. 409 | //! \param node Node to be printed. 410 | //! \return Output stream. 411 | template 412 | inline std::basic_ostream &operator <<(std::basic_ostream &out, const xml_node &node) 413 | { 414 | return print(out, node); 415 | } 416 | 417 | #endif 418 | 419 | } 420 | 421 | #endif 422 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------