Skip to content
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

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace fnss {
/**
* Default buffer size, set if no buffer size is specified in the constructor
*/
#define DEFAULT_BUFFER_SIZE "100packets"
#define DEFAULT_BUFFER_SIZE "1kB"

/**
* Represent an edge of a topology
Expand Down
16 changes: 14 additions & 2 deletions src/quantity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "quantity.h"

#include <sstream>
#include <regex>

namespace fnss {

Expand All @@ -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()) {
this->value = std::stod(match[1].str() + match[2].str());
this->unit = match[3];
} else {
this->value = 0.0;
this->unit = "";
}

if(this->unit == "")
this->unit = this->converter.getBaseUnit();
Expand Down
4 changes: 3 additions & 1 deletion test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ void testEdge() {
cout<<"Edge test: ";

Edge e;

e.setBufferSize(Quantity("1kB", Units::Data));
// test default values
assert(e.getCapacity().toString() == DEFAULT_CAPACITY);
assert(e.getDelay().toString() == DEFAULT_DELAY);
Expand Down Expand Up @@ -520,7 +522,7 @@ 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);
Expand Down