-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the compile work on a Mac #2
Changes from 5 commits
9234e94
eee36ed
1810f1f
790489f
fd1d287
04db54b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ VERSION = 0.6.1 | |
NAME = fnss | ||
ARCHIVE_NAME = fnss-cpp-api-$(VERSION) | ||
|
||
# BUILD TARGET | ||
BUILDTARGET = $(shell uname) | ||
|
||
# Compiler options | ||
LDFLAGS = | ||
LDLIBS = | ||
|
@@ -132,8 +135,13 @@ remove_root = $(shell echo $1 | sed s/\[.]\*\[/]\*\[^/]\*\\\///) | |
get_src = $2/$(call remove_root, $(basename $1)$(SRC_EXT)) | ||
get_bin = $(filter %$(notdir $1), $(BIN)) | ||
get_bin_dep = $(filter $(subst $(HDR_EXT),$(SRC_EXT), $(filter $(patsubst ./%,%,$(HDR)), $1)), $(patsubst ./%,%,$(SRC))) | ||
ifeq ($(BUILDTARGET),Darwin) | ||
make_dep = @$(CXX) -MM $(CXXFLAGS) $1 > $2.d; \ | ||
sed -i '' 's/.*:/$(subst /,\/,$@):/' [email protected] | ||
else | ||
make_dep = @$(CXX) -MM $(CXXFLAGS) $1 > $2.d; \ | ||
sed -i 's/.*:/$(subst /,\/,$@):/' [email protected] | ||
endif | ||
|
||
# Compile a file and print message. Args: <src_file> <dest_file> <cxx_options> | ||
compile = @echo "Compiling: $(strip $1) -> $(strip $2): " $(shell $(call compile_cmd, $1, $2, $3)) | ||
|
@@ -159,8 +167,8 @@ run_test = printf "Executing: $1: "; \ | |
if [ $$OUT -eq 0 ]; then \ | ||
echo "OK"; \ | ||
else \ | ||
rm $1; \ | ||
exit 1; \ | ||
rm $1; \ | ||
exit 1; \ | ||
fi \ | ||
|
||
# Summary message | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include "quantity.h" | ||
|
||
#include <sstream> | ||
#include <regex> | ||
|
||
namespace fnss { | ||
|
||
|
@@ -20,8 +21,19 @@ Quantity::Quantity(const MeasurementUnit &converter_) : | |
value(0), unit(converter_.getBaseUnit()), converter(converter_) {} | ||
|
||
void Quantity::fromString(const std::string &str) { | ||
std::istringstream ss(str); | ||
ss>>this->value>>this->unit; | ||
|
||
std::string regexpstr = "([0-9]+)(\\.[0-9]*)? *([^ \t]*)"; | ||
std::regex reg(regexpstr); | ||
std::smatch match; | ||
std::regex_search(str, match, reg); | ||
|
||
if ( !match.empty() ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: in the rest of the code, there are not spaces between parentheses and conditions (see for example at L38 below). I would use the same convention for consistency |
||
this->value = std::stod(match[1].str() + match[2].str()); | ||
this->unit = match[3]; | ||
} else { | ||
this->value = 0.0; | ||
this->unit = ""; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: this block uses spaces for indentation, while the rest of the code uses tabs. I'd suggest we use tabs here too for consistency |
||
|
||
if(this->unit == "") | ||
this->unit = this->converter.getBaseUnit(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,8 @@ void testEdge() { | |
cout<<"Edge test: "; | ||
|
||
Edge e; | ||
|
||
e.setBufferSize(Quantity("1kB", Units::Data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit like my comment above about using tabs instead of spaces |
||
// test default values | ||
assert(e.getCapacity().toString() == DEFAULT_CAPACITY); | ||
assert(e.getDelay().toString() == DEFAULT_DELAY); | ||
|
@@ -520,11 +522,11 @@ void testEvent() { | |
|
||
void testQuantity() { | ||
cout<<"Quantity test: "; | ||
Quantity t1(Units::Time); | ||
Quantity t1("2days",Units::Time); | ||
Quantity t2(1, "h", Units::Time); | ||
Quantity t3("60min", Units::Time); | ||
Quantity t4("3601 sec", Units::Time); | ||
t1.fromString("2days"); | ||
//t1.fromString("2days"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is commenting this out intended? Without this we are no longer testing anywhere the |
||
assert(t2 == t3); | ||
assert(t4 > t2); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: not sure if intended but by adding space in front of these two lines makes them no longer aligned with the
echo "OK"; \
instruction above. Was this change intended?