-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sequences git-svn-id: https://projectname.googlecode.com/svn/trunk@3 c416075f-80b4-e980-4839-00ea3ed24e77
- Loading branch information
1 parent
22a3c1b
commit 4b6a2bd
Showing
7 changed files
with
141 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
SRC_DIR = src | ||
PROJECT_NAME = pn | ||
SRCS = $(wildcard $(SRC_DIR)/*.cpp) | ||
LIBS = boost_program_options boost_filesystem boost_system | ||
CFLAGS = -O2 -Wall -pedantic | ||
PROJECT_NAME = pn | ||
SRC_DIR = src | ||
SRCS = $(wildcard $(SRC_DIR)/*.cpp) | ||
OBJS = $(patsubst $(SRC_DIR)/%.cpp,%.o,$(SRCS)) | ||
|
||
builds = debug release | ||
debug_flags = -ggdb | ||
release_flags = -DNDEBUG | ||
|
||
.PHONY: first debug release makedirs clean | ||
first: debug | ||
debug: | ||
@make makedirs DIR=debug | ||
@make debug/$(PROJECT_NAME) DIR=debug FLAGS=-ggdb | ||
release: | ||
@make makedirs DIR=release | ||
@make release/$(PROJECT_NAME) DIR=release FLAGS=-DNDEBUG | ||
makedirs: | ||
-@mkdir -p $(dir $(subst $(SRC_DIR),$(DIR),$(SRCS))) $(dir $(subst $(SRC_DIR),.depend,$(SRCS))) | ||
.PHONY: $(builds) clean | ||
$(builds): %: %-makedirs %/$(PROJECT_NAME) | ||
$(addsuffix -makedirs,$(builds)): %-makedirs: | ||
-@mkdir -p $(dir $(subst $(SRC_DIR),$*,$(SRCS))) $(dir $(subst $(SRC_DIR),.depend,$(SRCS))) | ||
clean: | ||
-@rm -rf debug release $(DIR) .depend | ||
-@rm -rf $(builds) .depend | ||
|
||
-include $(patsubst $(SRC_DIR)/%.cpp, .depend/%.dep, $(SRCS)) | ||
-include $(patsubst $(SRC_DIR)/%.cpp,.depend/%.dep,$(SRCS)) | ||
|
||
$(DIR)/$(PROJECT_NAME): $(patsubst $(SRC_DIR)/%.cpp, $(DIR)/%.o, $(SRCS)) | ||
g++ $^ -o $@ $(patsubst %,-l%,$(LIBS)) | ||
$(DIR)/%.o: $(SRC_DIR)/%.cpp | ||
g++ $< -c $(CFLAGS) -o $@ $(FLAGS) -MMD -MT $@ -MF .depend/$*.dep | ||
$(addsuffix /%.o,$(builds)): $(SRC_DIR)/%.cpp | ||
g++ $< -c -o $@ $(CFLAGS) $($(D@)_flags) -MMD -MT $@ -MF .depend/$*.dep | ||
$(addsuffix /$(PROJECT_NAME),$(builds)): %$(PROJECT_NAME): $(addprefix %,$(OBJS)) | ||
g++ $^ -o $@ $(addprefix -l,$(LIBS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifndef _SEQUENCE_H_ | ||
#define _SEQUENCE_H_ | ||
|
||
template<typename S> | ||
struct end { | ||
virtual void operator()(const S& v) = 0; | ||
}; | ||
|
||
template<typename V> | ||
void operator>>=(const V& from, end<V>& to) { | ||
to(from); | ||
} | ||
|
||
template<typename Iter, typename V> | ||
void operator>>=(const std::pair<Iter, Iter>& from, end<V>& to) { | ||
for (Iter it = from.first; it != from.second; to(*it++)) ; | ||
} | ||
|
||
template<typename Funct, typename V> | ||
void operator>>=(const std::pair<Funct, int>& from, end<V>& to) { | ||
for (int i = 0; i < from.second; ++i) { | ||
to(from.first()); | ||
} | ||
} | ||
|
||
template<typename S, typename T> | ||
class seq: public end<S> { | ||
end<T>* e; | ||
protected: | ||
void put(const T& t) { | ||
(*e)(t); | ||
} | ||
public: | ||
end<S>& operator>>=(end<T>& to) { | ||
e = &to; | ||
return *this; | ||
} | ||
}; | ||
|
||
template<typename V, typename Iter> | ||
class iterator_end: public end<V> { | ||
Iter it; | ||
public: | ||
iterator_end(const Iter& i): it(i) {} | ||
void operator()(const V& value) { *it++ = value; } | ||
}; | ||
|
||
template<typename T, typename P> | ||
class filter: public seq<T, T> { | ||
P _p; | ||
public: | ||
filter(const P& p): _p(p) {} | ||
void operator()(const T& value) { | ||
if (_p(value)) { | ||
put(value); | ||
} | ||
} | ||
}; | ||
|
||
template<typename T> | ||
struct id: seq<T, T> { | ||
void operator()(const T& t) { put(t); } | ||
}; | ||
|
||
template<typename T> T& The() { static T r; return r; } | ||
template<typename T> T& The(const T& t) { static T r(t); return r; } | ||
template<template<typename S> class R, typename S> R<S>& The() { static R<S> r; return r; } | ||
template<template<typename S> class R, typename S> R<S>& The(const S& s) { static R<S> r(s); return r; } | ||
template<template<typename S> class R, typename S> R<S>& The(const R<S>& t) { static R<S> r(t); return r; } | ||
template<template<typename S, typename T> class R, typename S, typename T> R<S, T>& The() { static R<S, T> r; return r; } | ||
template<template<typename S, typename T> class R, typename S, typename T> R<S, T>& The(const T& t) { static R<S, T> r(t); return r; } | ||
template<template<typename S, typename T> class R, typename S, typename T> R<S, T>& The(const R<S, T>& t) { static R<S, T> r(t); return r; } | ||
template<template<typename S, typename T, typename U> class R, typename S, typename T, typename U> R<S, T, U>& The() { static R<S, T, U> r; return r; } | ||
template<template<typename S, typename T, typename U> class R, typename S, typename T, typename U> R<S, T, U>& The(const U& u) { static R<S, T, U> r(u); return r; } | ||
template<template<typename S, typename T, typename U> class R, typename S, typename T, typename U> R<S, T, U>& The(const R<S, T, U>& t) { static R<S, T, U> r(t); return r; } | ||
|
||
#endif |