summaryrefslogtreecommitdiff
path: root/ext/dsent/libutil
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2014-10-11 16:16:00 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2014-10-11 16:16:00 -0500
commitc1aecc05e6cad977423a15905f6bd4f5f33b53c8 (patch)
treeb013259fe0a6ec5e4fca8c47f757b50e92871f4d /ext/dsent/libutil
parente8ed7b1d1b5bef31e9874f679a5797c2e00d06f1 (diff)
downloadgem5-c1aecc05e6cad977423a15905f6bd4f5f33b53c8.tar.xz
ext: dsent: adds a Python interface, drops C++ one
This patch extensively modifies DSENT so that it can be accessed using Python. To access the Python interface, DSENT needs to compiled as a shared library. For this purpose a CMakeLists.txt file has been added. Some of the code that is not required is being removed.
Diffstat (limited to 'ext/dsent/libutil')
-rw-r--r--ext/dsent/libutil/Assert.h21
-rw-r--r--ext/dsent/libutil/Calculator.cc78
-rw-r--r--ext/dsent/libutil/Calculator.h51
-rw-r--r--ext/dsent/libutil/Config.cc94
-rw-r--r--ext/dsent/libutil/Config.h50
-rw-r--r--ext/dsent/libutil/Exception.cc21
-rw-r--r--ext/dsent/libutil/Exception.h21
-rw-r--r--ext/dsent/libutil/LibUtil.h21
-rw-r--r--ext/dsent/libutil/Log.cc21
-rw-r--r--ext/dsent/libutil/Log.h21
-rw-r--r--ext/dsent/libutil/Makefile43
-rw-r--r--ext/dsent/libutil/Map.h21
-rw-r--r--ext/dsent/libutil/MathUtil.cc21
-rw-r--r--ext/dsent/libutil/MathUtil.h21
-rw-r--r--ext/dsent/libutil/OptionParser.cc177
-rw-r--r--ext/dsent/libutil/OptionParser.h57
-rw-r--r--ext/dsent/libutil/String.cc21
-rw-r--r--ext/dsent/libutil/String.h21
18 files changed, 391 insertions, 390 deletions
diff --git a/ext/dsent/libutil/Assert.h b/ext/dsent/libutil/Assert.h
index 0fdd364b2..dae12e9ae 100644
--- a/ext/dsent/libutil/Assert.h
+++ b/ext/dsent/libutil/Assert.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __ASSERT_H__
#define __ASSERT_H__
diff --git a/ext/dsent/libutil/Calculator.cc b/ext/dsent/libutil/Calculator.cc
index e78e67287..ca4192dd6 100644
--- a/ext/dsent/libutil/Calculator.cc
+++ b/ext/dsent/libutil/Calculator.cc
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include "Calculator.h"
#include <cctype>
@@ -23,9 +44,13 @@ namespace LibUtil
return;
}
- void Calculator::evaluateString(const String& str_)
+ void Calculator::evaluateString(const String& str_,
+ const map<String, String> &config,
+ DSENT::Model *ms_model,
+ map<string, double> &outputs)
{
istringstream ist(str_);
+
while(ist)
{
getToken(ist);
@@ -42,26 +67,28 @@ namespace LibUtil
getToken(ist);
if(m_curr_token_ == SEP)
{
+ outputs[print_str] = 0;
cout << print_str << endl;
}
else
{
- double v = expr(ist, false);
- cout << scientific << print_str << v << endl;
+ double v = expr(ist, false, config, ms_model);
+ outputs[print_str] = v;
+ cout << print_str << v << endl;
}
}
else
{
- double v = expr(ist, false);
- cout << scientific << v << endl;
+ double v = expr(ist, false, config, ms_model);
+ outputs["Missing Expression"] = v;
+ cout << v << endl;
}
}
else
{
- expr(ist, false);
+ expr(ist, false, config, ms_model);
}
}
- return;
}
Calculator::Token Calculator::getToken(istringstream& ist_)
@@ -146,7 +173,9 @@ namespace LibUtil
}
}
- double Calculator::prim(istringstream& ist_, bool is_get_)
+ double Calculator::prim(istringstream& ist_, bool is_get_,
+ const map<String, String> &config,
+ DSENT::Model *ms_model)
{
if(is_get_)
{
@@ -164,7 +193,7 @@ namespace LibUtil
if(getToken(ist_) == ASSIGN)
{
String var_name = m_value_string_;
- v = expr(ist_, true);
+ v = expr(ist_, true, config, ms_model);
m_var_.set(var_name, v);
}
else
@@ -173,13 +202,13 @@ namespace LibUtil
}
return v;
case NAME2:
- v = getEnvVar(m_value_string_);
+ v = getEnvVar(m_value_string_, config, ms_model);
getToken(ist_);
return v;
case MINUS:
- return -prim(ist_, true);
+ return -prim(ist_, true, config, ms_model);
case LP:
- v = expr(ist_, true);
+ v = expr(ist_, true, config, ms_model);
ASSERT((m_curr_token_ == RP), "[Error] ')' expected");
getToken(ist_);
return v;
@@ -188,9 +217,11 @@ namespace LibUtil
}
}
- double Calculator::term(istringstream& ist_, bool is_get_)
+ double Calculator::term(istringstream& ist_, bool is_get_,
+ const map<String, String> &config,
+ DSENT::Model *ms_model)
{
- double left = prim(ist_, is_get_);
+ double left = prim(ist_, is_get_, config, ms_model);
while(1)
{
@@ -198,10 +229,10 @@ namespace LibUtil
switch(m_curr_token_)
{
case MUL:
- left *= prim(ist_, true);
+ left *= prim(ist_, true, config, ms_model);
break;
case DIV:
- d = prim(ist_, true);
+ d = prim(ist_, true, config, ms_model);
ASSERT(d, "[Error] divided by 0");
left /= d;
break;
@@ -211,19 +242,21 @@ namespace LibUtil
}
}
- double Calculator::expr(istringstream& ist_, bool is_get_)
+ double Calculator::expr(istringstream& ist_, bool is_get_,
+ const map<String, String> &config,
+ DSENT::Model *ms_model)
{
- double left = term(ist_, is_get_);
+ double left = term(ist_, is_get_, config, ms_model);
while(1)
{
switch(m_curr_token_)
{
case PLUS:
- left += term(ist_, true);
+ left += term(ist_, true, config, ms_model);
break;
case MINUS:
- left -= term(ist_, true);
+ left -= term(ist_, true, config, ms_model);
break;
default:
return left;
@@ -231,9 +264,10 @@ namespace LibUtil
}
}
- double Calculator::getEnvVar(const String& var_name_) const
+ double Calculator::getEnvVar(const String& var_name_,
+ const map<String, String> &config,
+ DSENT::Model *ms_model) const
{
return m_var_.get(var_name_);
}
} // namespace LibUtil
-
diff --git a/ext/dsent/libutil/Calculator.h b/ext/dsent/libutil/Calculator.h
index 4fcdf471f..78b3fb63a 100644
--- a/ext/dsent/libutil/Calculator.h
+++ b/ext/dsent/libutil/Calculator.h
@@ -1,8 +1,30 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __LIBUTIL_CALCULATOR_H__
#define __LIBUTIL_CALCULATOR_H__
#include <sstream>
+#include "model/Model.h"
#include "String.h"
#include "Map.h"
#include "Assert.h"
@@ -10,6 +32,7 @@
namespace LibUtil
{
using std::istringstream;
+ using std::ostringstream;
/*
* program:
@@ -63,14 +86,30 @@ namespace LibUtil
public:
void reset();
- void evaluateString(const String& str_);
+ void evaluateString(const String& str_,
+ const std::map<String, String> &config,
+ DSENT::Model *ms_model,
+ std::map<std::string, double> &outputs);
protected:
Token getToken(istringstream& ist_);
- double prim(istringstream& ist_, bool is_get_);
- double term(istringstream& ist_, bool is_get_);
- double expr(istringstream& ist_, bool is_get_);
- virtual double getEnvVar(const String& var_name_) const;
+
+ double prim(istringstream& ist_, bool is_get_,
+ const std::map<String, String> &config,
+ DSENT::Model *ms_model);
+
+ double term(istringstream& ist_, bool is_get_,
+ const std::map<String, String> &config,
+ DSENT::Model *ms_model);
+
+ double expr(istringstream& ist_, bool is_get_,
+ const std::map<String, String> &config,
+ DSENT::Model *ms_model);
+
+ virtual double getEnvVar(
+ const String& var_name_,
+ const std::map<String, String> &config,
+ DSENT::Model *ms_model) const;
protected:
String m_reserved_chars_;
@@ -79,7 +118,7 @@ namespace LibUtil
Token m_curr_token_;
double m_value_number_;
String m_value_string_;
- }; // class Calculator
+ };
} // namespace LibUtil
#endif // __LIBUTIL_CALCULATOR_H__
diff --git a/ext/dsent/libutil/Config.cc b/ext/dsent/libutil/Config.cc
index f858c6926..c0b4f5bda 100644
--- a/ext/dsent/libutil/Config.cc
+++ b/ext/dsent/libutil/Config.cc
@@ -1,69 +1,44 @@
-#include "Config.h"
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
#include <fstream>
#include "Assert.h"
+#include "Config.h"
+
+using namespace std;
namespace LibUtil
{
- Config::Config(const String& delimiter_, const String& comment_, const String& sentry_)
- : mDelimiter(delimiter_), mComment(comment_), mSentry(sentry_)
- {}
-
- Config::Config(const Config& config_)
- : StringMap(config_)
- {
- mDelimiter = config_.mDelimiter;
- mComment = config_.mComment;
- mSentry = config_.mSentry;
- }
-
- Config::~Config()
- {}
-
- Config* Config::clone() const
- {
- return new Config(*this);
- }
-
- void Config::readFile(const String& filename_)
+ void readFile(const char *filename_, map<String, String> &config)
{
- std::ifstream fin(filename_.c_str());
+ std::ifstream ist_(filename_);
- ASSERT(fin, "File not found: " + filename_);
- fin >> (*this);
- return;
- }
-
- void Config::readString(const String& str_)
- {
- String newString = str_;
- newString.substitute(";", "\n");
- std::istringstream iss(newString, std::istringstream::in);
-
- iss >> (*this);
- }
-
- std::ostream& operator<<(std::ostream& ost_, const Config& config_)
- {
- Config::ConstIterator it;
- for(it = config_.begin(); it != config_.end(); it++)
- {
- ost_ << it->first << " " << config_.mDelimiter << " ";
- ost_ << it->second << std::endl;
- }
- return ost_;
- }
-
- std::istream& operator>>(std::istream& ist_, Config& config_)
- {
// Set a Config from ist_
// Read in keys and values, keeping internal whitespace
typedef String::size_type pos;
- const String& delim = config_.mDelimiter; // separator
- const String& comm = config_.mComment; // comment
- const String& sentry = config_.mSentry; // end of file sentry
- const pos skip = delim.length(); // length of separator
+ const String& delimiter = "=";
+ const String& comment = "#";
+ const String& sentry = "End";
+ const pos skip = delimiter.length(); // length of separator
String nextline = ""; // might need to read ahead to see where value ends
@@ -83,17 +58,17 @@ namespace LibUtil
}
// Ignore comments and the spaces on both ends
- line = line.substr(0, line.find(comm));
+ line = line.substr(0, line.find(comment));
line.trim();
// Check for end of file sentry
- if((sentry != "") && (line.find(sentry) != String::npos)) return ist_;
+ if((sentry != "") && (line.find(sentry) != String::npos)) return;
if(line.length() == 0)
continue;
// Parse the line if it contains a delimiter
- pos delimPos = line.find(delim);
+ pos delimPos = line.find(delimiter);
ASSERT((delimPos < String::npos), "Invalid config line: '" + line + "'");
// Extract the key
@@ -119,7 +94,7 @@ namespace LibUtil
nlcopy.trim();
if(nlcopy == "") continue;
- nextline = nextline.substr(0, nextline.find(comm));
+ nextline = nextline.substr(0, nextline.find(comment));
//if(nextline.find(delim) != String::npos)
// continue;
if((sentry != "") && (nextline.find(sentry) != String::npos))
@@ -136,9 +111,8 @@ namespace LibUtil
// Store key and value
key.trim();
line.trim();
- config_.set(key, line); // overwrites if key is repeated
+ config[key] = line; // overwrites if key is repeated
}
- return ist_;
}
}
diff --git a/ext/dsent/libutil/Config.h b/ext/dsent/libutil/Config.h
index a60c4b8fd..d88a800a2 100644
--- a/ext/dsent/libutil/Config.h
+++ b/ext/dsent/libutil/Config.h
@@ -1,36 +1,36 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __LIBUTIL_CONFIG_H__
#define __LIBUTIL_CONFIG_H__
#include <iostream>
+#include <map>
-#include "Map.h"
+#include "libutil/String.h"
namespace LibUtil
{
- class Config : public StringMap
- {
- public:
- Config(const String& delimiter_ = "=", const String& comment_ = "#", const String& sentry_ = "End");
- Config(const Config& config_);
- virtual ~Config();
-
- public:
- // Make a copy of this instance
- virtual Config* clone() const;
- // Load the config from file
- virtual void readFile(const String& filename_);
- // Parse string and overwrite the Config instance if keys exist
- virtual void readString(const String& str_);
-
- // Write or read map using standard IO
- friend std::ostream& operator<<(std::ostream& ost_, const Config& config_);
- friend std::istream& operator>>(std::istream& ist_, Config& config_);
-
- protected:
- String mDelimiter;
- String mComment;
- String mSentry;
- };
+ // Load the config from file
+ void readFile(const char *filename_, std::map<String, String> &config);
}
#endif // __LIBUTIL_CONFIG_H__
diff --git a/ext/dsent/libutil/Exception.cc b/ext/dsent/libutil/Exception.cc
index c6db0e3fb..81a459f18 100644
--- a/ext/dsent/libutil/Exception.cc
+++ b/ext/dsent/libutil/Exception.cc
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include "Exception.h"
namespace LibUtil
diff --git a/ext/dsent/libutil/Exception.h b/ext/dsent/libutil/Exception.h
index 88d68cce2..640eac8b8 100644
--- a/ext/dsent/libutil/Exception.h
+++ b/ext/dsent/libutil/Exception.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
diff --git a/ext/dsent/libutil/LibUtil.h b/ext/dsent/libutil/LibUtil.h
index 12eb76fa0..b5170ffb5 100644
--- a/ext/dsent/libutil/LibUtil.h
+++ b/ext/dsent/libutil/LibUtil.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __LIBUTIL_H__
#define __LIBUTIL_H__
diff --git a/ext/dsent/libutil/Log.cc b/ext/dsent/libutil/Log.cc
index cb4266bf9..d662ed921 100644
--- a/ext/dsent/libutil/Log.cc
+++ b/ext/dsent/libutil/Log.cc
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include "Log.h"
#include "Assert.h"
diff --git a/ext/dsent/libutil/Log.h b/ext/dsent/libutil/Log.h
index 9c759e702..9aafa4e40 100644
--- a/ext/dsent/libutil/Log.h
+++ b/ext/dsent/libutil/Log.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __LOG_H__
#define __LOG_H__
diff --git a/ext/dsent/libutil/Makefile b/ext/dsent/libutil/Makefile
deleted file mode 100644
index 150028346..000000000
--- a/ext/dsent/libutil/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-
-# Define the directories that will be compiled
-DIRS_TO_COMPILE := . \
-
-DIRS = $(patsubst %,$(CURDIR)/%,$(DIRS_TO_COMPILE))
-
-SRCS = $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc))
-
-OBJS = $(SRCS:%.cc=%.o)
-
-DEF_FLAGS =
-
-ifdef LIBUTIL_IS_LOG
- LIBUTIL_IS_LOG = true
-else
- LIBUTIL_IS_LOG = false
-endif
-DEF_FLAGS += -DLIBUTIL_IS_LOG=$(LIBUTIL_IS_LOG)
-
-INCLUDE_FLAGS = $(foreach dir, $(DIRS), -I$(dir))
-OPT_FLAGS = -O2 -g
-WARN_FLAGS = -pedantic -Wall -W -Wextra -Werror
-CXXFLAGS = $(OPT_FLAGS) $(WARN_FLAGS) $(INCLUDE_FLAGS) $(DEF_FLAGS)
-
-TARGET = $(CURDIR)/libutil.a
-
-all: $(TARGET)
-
-$(TARGET): $(OBJS)
- ar rcs $@ $^
-#$(TARGET): $(OBJS)
-# $(CXX) $(CXXFLAGS) $^ -o $(TARGET)
-
-%.o: %.cc
- $(CXX) $(CXXFLAGS) -c $< -o $@
-
-%/created:
- mkdir -p $(dir $@)
- touch $@
-
-clean:
- $(RM) -rf $(OBJS) $(TARGET)
-
diff --git a/ext/dsent/libutil/Map.h b/ext/dsent/libutil/Map.h
index 0352c8634..7a990fc99 100644
--- a/ext/dsent/libutil/Map.h
+++ b/ext/dsent/libutil/Map.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __MAP_H__
#define __MAP_H__
diff --git a/ext/dsent/libutil/MathUtil.cc b/ext/dsent/libutil/MathUtil.cc
index 0e177b5fc..d14e9ae70 100644
--- a/ext/dsent/libutil/MathUtil.cc
+++ b/ext/dsent/libutil/MathUtil.cc
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include "MathUtil.h"
namespace LibUtil
diff --git a/ext/dsent/libutil/MathUtil.h b/ext/dsent/libutil/MathUtil.h
index 1f3341ee1..0275b02d2 100644
--- a/ext/dsent/libutil/MathUtil.h
+++ b/ext/dsent/libutil/MathUtil.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __MATH_H__
#define __MATH_H__
diff --git a/ext/dsent/libutil/OptionParser.cc b/ext/dsent/libutil/OptionParser.cc
deleted file mode 100644
index 6d2695f2d..000000000
--- a/ext/dsent/libutil/OptionParser.cc
+++ /dev/null
@@ -1,177 +0,0 @@
-#include "OptionParser.h"
-
-#include <cstdlib>
-#include <iostream>
-
-namespace LibUtil
-{
- using std::cout;
- using std::cerr;
- using std::endl;
-
- OptionParser::OptionInfo::OptionInfo(
- const String& var_name_,
- bool has_arg_,
- const String& arg_name_,
- bool has_default_arg_value_,
- const String& default_arg_value_,
- const String& description_
- )
- : m_var_name_(var_name_),
- m_has_arg_(has_arg_),
- m_arg_name_(arg_name_),
- m_has_default_arg_value_(has_default_arg_value_),
- m_default_arg_value_(default_arg_value_),
- m_description_(description_)
- {}
-
- OptionParser::OptionInfo::~OptionInfo()
- {
- }
-
- OptionParser::OptionParser()
- {}
-
- OptionParser::~OptionParser()
- {
- clearPtrMap(&m_option_infos_);
- }
-
- void OptionParser::addOption(
- const String& option_name_,
- const String& var_name_,
- bool has_arg_,
- const String& arg_name_,
- bool has_default_arg_value_,
- const String& default_arg_value_,
- const String& description_)
- {
- OptionInfo* option_info = new OptionInfo(var_name_, has_arg_, arg_name_,
- has_default_arg_value_, default_arg_value_, description_);
-
- ASSERT(!m_option_infos_.keyExist(option_name_), "Option exists: " + option_name_);
-
- // Add the option name to an array for sorting
- m_option_names_.push_back(option_name_);
-
- // Add option info
- m_option_infos_.set(option_name_, option_info);
-
- // Set the default argument value
- if(has_default_arg_value_)
- {
- set(var_name_, default_arg_value_);
- }
-
- return;
- }
-
- void OptionParser::parseArguments(int argc_, char** argv_)
- {
- bool is_print_options = false;
- int arg_idx = 0;
-
- while(arg_idx < argc_)
- {
- String option_name = String(argv_[arg_idx]);
-
- // Print the options page if -help is specified
- if(option_name == "-help")
- {
- is_print_options = true;
- break;
- }
- else if(m_option_infos_.keyExist(option_name))
- {
- const OptionInfo* option_info = m_option_infos_.get(option_name);
- const String& var_name = option_info->getVarName();
- if(option_info->hasArg())
- {
- if((arg_idx + 1) >= argc_)
- {
- cerr << "[Error] Missing argument for option: '" << option_name << "'" << endl;
- is_print_options = true;
- break;
- }
-
- String option_arg = String(argv_[arg_idx + 1]);
- set(var_name, option_arg);
-
- arg_idx += 2;
- }
- else
- {
- // If the option does not require an argument
- // then set it to true
- set(var_name, "true");
-
- arg_idx += 1;
- }
- }
- else
- {
- cerr << "[Error] Unknown option: '" << option_name << "'" << endl;
- is_print_options = true;
- break;
- }
- }
-
- // Check if all required options are set (the ones without default values)
- vector<String>::const_iterator it;
- for(it = m_option_names_.begin(); it != m_option_names_.end(); ++it)
- {
- const String& option_name = *it;
- const OptionInfo* option_info = m_option_infos_.get(option_name);
-
- if(!option_info->hasDefaultArgValue())
- {
- const String& var_name = option_info->getVarName();
- if(!keyExist(var_name))
- {
- cerr << "[Error] Missing required option: '" << option_name << "'" << endl;
- is_print_options = true;
- }
- }
- }
-
- if(is_print_options)
- {
- printOptions();
- exit(0);
- }
- return;
- }
-
- void OptionParser::printOptions() const
- {
- cout << endl;
- cout << "Available options:" << endl;
- cout << "==================" << endl << endl;
-
- vector<String>::const_iterator it;
- for(it = m_option_names_.begin(); it != m_option_names_.end(); ++it)
- {
- const String& option_name = *it;
- const OptionInfo* option_info = m_option_infos_.get(option_name);
-
- cout << option_name;
- if(option_info->hasArg())
- {
- cout << " <" << option_info->getArgName() << ">";
- }
- cout << endl;
-
- cout << " " << option_info->getDescription() << endl;
- if(option_info->hasArg() && option_info->hasDefaultArgValue())
- {
- cout << " " << "Default: " << option_info->getDefaultArgValue() << endl;
- }
- cout << endl;
- }
- cout << "-help" << endl;
- cout << " " << "Print this page" << endl;
- cout << endl;
- return;
- }
-
-} // namespace LibUtil
diff --git a/ext/dsent/libutil/OptionParser.h b/ext/dsent/libutil/OptionParser.h
deleted file mode 100644
index b98012a80..000000000
--- a/ext/dsent/libutil/OptionParser.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef __LIBUTIL_OPTION_PARSER_H__
-#define __LIBUTIL_OPTION_PARSER_H__
-
-#include <vector>
-
-#include "Map.h"
-
-namespace LibUtil
-{
- using std::vector;
-
- // Simple option parser
- class OptionParser : public StringMap
- {
- private:
- class OptionInfo
- {
- public:
- OptionInfo(const String& var_name_, bool has_arg_, const String& arg_name_, bool has_default_arg_value_, const String& default_arg_value_, const String& description_);
- ~OptionInfo();
-
- public:
- inline const String& getVarName() const { return m_var_name_; }
- inline bool hasArg() const { return m_has_arg_; }
- inline const String& getArgName() const { return m_arg_name_; }
- inline bool hasDefaultArgValue() const { return m_has_default_arg_value_; }
- inline const String& getDefaultArgValue() const { return m_default_arg_value_; }
- inline const String& getDescription() const { return m_description_; }
-
- private:
- String m_var_name_;
- bool m_has_arg_;
- String m_arg_name_;
- bool m_has_default_arg_value_;
- String m_default_arg_value_;
- String m_description_;
- }; // class Option
-
- public:
- OptionParser();
- virtual ~OptionParser();
-
- public:
- void addOption(const String& option_name_, const String& var_name_, bool has_arg_, const String& arg_name_, bool has_default_arg_value_, const String& default_arg_value_, const String& description_);
-
- void parseArguments(int argc_, char** argv_);
-
- void printOptions() const;
-
- protected:
- vector<String> m_option_names_;
- Map<OptionInfo*> m_option_infos_;
- }; // class OptionParser
-} // LibUtil
-
-#endif // __LIBUTIL_OPTION_PARSER_H__
-
diff --git a/ext/dsent/libutil/String.cc b/ext/dsent/libutil/String.cc
index 146e9f824..472be802a 100644
--- a/ext/dsent/libutil/String.cc
+++ b/ext/dsent/libutil/String.cc
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#include "String.h"
#include <cstdarg>
diff --git a/ext/dsent/libutil/String.h b/ext/dsent/libutil/String.h
index 95fe17565..0662a6a18 100644
--- a/ext/dsent/libutil/String.h
+++ b/ext/dsent/libutil/String.h
@@ -1,3 +1,24 @@
+/* Copyright (c) 2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
#ifndef __STRING_H__
#define __STRING_H__