summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-04 10:49:55 +0100
committerTim Redfern <tim@herge.(none)>2013-07-04 10:49:55 +0100
commitfddff1ff3e50260b6518e754714b46e28fefaea6 (patch)
tree3aa94083cde9a5d0086ae3e1365d4c7bcbd0e94d
parent729e602bbf825f909193fd130d68ee9eeafb0eae (diff)
tidying
-rw-r--r--Ianimal/Ianimal.cpp138
-rwxr-xr-xIanimal/make1
-rw-r--r--poco-httpd/Makefile221
-rw-r--r--poco-httpd/poco-httpd.cpp169
4 files changed, 0 insertions, 529 deletions
diff --git a/Ianimal/Ianimal.cpp b/Ianimal/Ianimal.cpp
deleted file mode 100644
index 2814757..0000000
--- a/Ianimal/Ianimal.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-#include <string>
-#include <iostream>
-#include <unordered_map>
-#include <vector>
-
-//simple really, to refer to a class from a pointer to the base class, the base class must refer to every member
-//how to make a factory for a derived class carrying settings in the constructor
-
-using namespace std;
-
-class Node { //abstract base class
- public:
- virtual string get_name(){}; //base class
- virtual Node* clone(unordered_map<string,string> &_settings){};
- void set(unordered_map<string,string> &_settings){settings=_settings;type=settings["type"];};
- unordered_map<string,string> settings;
- string get_type(){ return type; };
- string type;
-};
-class Node_o: public Node {
- public:
- virtual string get_occupation(){}; //needs to be an abstract subclass implementing the interface
-
-};
-
-
-class A_node: public Node_o {
- public:
- A_node(){};
- A_node(unordered_map<string,string> &_settings){
- settings=_settings;
- type=_settings["type"];
- cout << "making a " << type << endl;
- };
- A_node* clone(unordered_map<string,string> &_settings) { return new A_node(_settings);};
- string get_name(){ return "A"; };
- string get_occupation(){ return "an A"; };
-
-};
-
-class B_node: public Node_o {
- public:
- B_node(){};
- B_node(unordered_map<string,string> &_settings) {
- settings=_settings;
- type=_settings["type"];
- cout << "making a " << type << endl;
- };
- B_node* clone(unordered_map<string,string> &_settings) { return new B_node(_settings);};
- string get_name(){ return "B"; };
- string get_occupation(){ return "a B"; };
-};
-
-class C_node: public Node_o {
- public:
- C_node(){};
- C_node(unordered_map<string,string> &_settings) {
- settings=_settings;
- type=_settings["type"];
- cout << "making a " << type << endl;
- };
- C_node* clone(unordered_map<string,string> &_settings) { return new C_node(_settings);};
- string get_name(){ return settings["type"]; };
- string get_occupation(){ return "C node"; };
-
-};
-
-class Node_factory {
- public:
- template <typename T>
- T* clone(T* proto) {
- cout << "cloning.. " << endl;
- return new T();
- };
- Node_factory() {
- add_type("A",new A_node());
- add_type("B",new B_node());
- add_type("C",new C_node());
- }
- Node *get_node(string type) {
- if (type=="A") return new A_node();
- if (type=="B") return new B_node();
- if (type=="C") return new C_node();
- };
- unordered_map<string,Node*> type_map;
- void add_type(string type,Node *proto){
- type_map[type]=proto;
- };
-
- Node *create(unordered_map<string,string> &settings) {
- if (settings.find("type")!=settings.end()) {
- if (type_map.find(settings["type"])!=type_map.end()) {
- return type_map[settings["type"]]->clone(settings);
- }
- }
- }
- Node *create(string type,unordered_map<string,string> &settings) {
- if (settings.find("type")!=settings.end()) {
- if (type_map.find(settings["type"])!=type_map.end()) {
- Node* t=clone(type_map[settings["type"]]);
- cout << "cloned.. " << endl;
- t->set(settings);
- return t;
-
- //T* t= new T();
- }
- }
- }
- //so when you get a pointer from an array of pointers to base class, thats all you get
- /*
- Node *create(string type) {
- if (type_map.find(type)!=type_map.end()) {
- return (Node*)clone(type_map[type]);
- }
- }
- Node *create(string type,string desc) {
- if (type_map.find(type)!=type_map.end()) {
- return (Node*)clone(type_map[type],desc);
- }
- }
- */
-};
-
-int main() {
- Node_factory f=Node_factory();
- unordered_map<string,string> settings;
- vector<Node*> nodes;
- settings["type"]="A";
- nodes.push_back(f.create("A",settings));
- settings["type"]="B";
- nodes.push_back(f.create(settings));
- settings["type"]="C";
- //nodes.push_back(f.create(settings));
- for (auto &i: nodes) {
- //cout << ((Node_o*)i)->get_type() << ", " << ((Node_o*)i)->get_occupation()<< endl;
- cout << ((Node_o*)i)->get_occupation()<< endl;
- }
-} \ No newline at end of file
diff --git a/Ianimal/make b/Ianimal/make
deleted file mode 100755
index 7c1cc2e..0000000
--- a/Ianimal/make
+++ /dev/null
@@ -1 +0,0 @@
-g++ Ianimal.cpp -std=c++11 -o Ianimal
diff --git a/poco-httpd/Makefile b/poco-httpd/Makefile
deleted file mode 100644
index 9098836..0000000
--- a/poco-httpd/Makefile
+++ /dev/null
@@ -1,221 +0,0 @@
-# The pre-processor and compiler options.
-MY_CFLAGS =
-
-# The linker options.
-MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation
-
-# The pre-processor options used by the cpp (man cpp for more).
-CPPFLAGS = -Wall
-
-# The options used in linking as well as in any direct use of ld.
-LDFLAGS =
-
-# The directories in which source files reside.
-# If not specified, only the current directory will be serached.
-SRCDIRS =
-
-# The executable file name.
-# If not specified, current directory name or `a.out' will be used.
-PROGRAM =
-
-## Implicit Section: change the following only when necessary.
-##==========================================================================
-
-# The source file types (headers excluded).
-# .c indicates C source files, and others C++ ones.
-SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp
-
-# The header file types.
-HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp
-
-# The pre-processor and compiler options.
-# Users can override those variables from the command line.
-CFLAGS = -g -O2
-CXXFLAGS= -g -O2
-
-# The C program compiler.
-#CC = gcc
-
-# The C++ program compiler.
-#CXX = g++
-
-# Un-comment the following line to compile C programs as C++ ones.
-#CC = $(CXX)
-
-# The command used to delete file.
-#RM = rm -f
-
-ETAGS = etags
-ETAGSFLAGS =
-
-CTAGS = ctags
-CTAGSFLAGS =
-
-## Stable Section: usually no need to be changed. But you can add more.
-##==========================================================================
-SHELL = /bin/sh
-EMPTY =
-SPACE = $(EMPTY) $(EMPTY)
-ifeq ($(PROGRAM),)
- CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
- PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
- ifeq ($(PROGRAM),)
- PROGRAM = a.out
- endif
-endif
-ifeq ($(SRCDIRS),)
- SRCDIRS = .
-endif
-SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
-HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
-SRC_CXX = $(filter-out %.c,$(SOURCES))
-OBJS = $(addsuffix .o, $(basename $(SOURCES)))
-DEPS = $(OBJS:.o=.d)
-
-## Define some useful variables.
-DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
- echo "-MM -MP"; else echo "-M"; fi )
-DEPEND = $(CC) $(DEP_OPT) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)
-DEPEND.d = $(subst -g ,,$(DEPEND))
-COMPILE.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c
-COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
-LINK.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
-LINK.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
-
-.PHONY: all objs tags ctags clean distclean help show
-
-# Delete the default suffixes
-.SUFFIXES:
-
-all: $(PROGRAM)
-
-# Rules for creating dependency files (.d).
-#------------------------------------------
-
-%.d:%.c
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.C
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cc
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cpp
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.CPP
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.c++
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cp
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cxx
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-# Rules for generating object files (.o).
-#----------------------------------------
-objs:$(OBJS)
-
-%.o:%.c
- $(COMPILE.c) $< -o $@
-
-%.o:%.C
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cc
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cpp
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.CPP
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.c++
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cp
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cxx
- $(COMPILE.cxx) $< -o $@
-
-# Rules for generating the tags.
-#-------------------------------------
-tags: $(HEADERS) $(SOURCES)
- $(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
-
-ctags: $(HEADERS) $(SOURCES)
- $(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
-
-# Rules for generating the executable.
-#-------------------------------------
-$(PROGRAM):$(OBJS)
-ifeq ($(SRC_CXX),) # C program
- $(LINK.c) $(OBJS) $(MY_LIBS) -o $@
- @echo Type ./$@ to execute the program.
-else # C++ program
- $(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@
- @echo Type ./$@ to execute the program.
-endif
-
-ifndef NODEP
-ifneq ($(DEPS),)
- sinclude $(DEPS)
-endif
-endif
-
-clean:
- $(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe
-
-distclean: clean
- $(RM) $(DEPS) TAGS
-
-# Show help.
-help:
- @echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
- @echo 'Copyright (C) 2007, 2008 whyglinux <whyglinux@hotmail.com>'
- @echo
- @echo 'Usage: make [TARGET]'
- @echo 'TARGETS:'
- @echo ' all (=make) compile and link.'
- @echo ' NODEP=yes make without generating dependencies.'
- @echo ' objs compile only (no linking).'
- @echo ' tags create tags for Emacs editor.'
- @echo ' ctags create ctags for VI editor.'
- @echo ' clean clean objects and the executable file.'
- @echo ' distclean clean objects, the executable and dependencies.'
- @echo ' show show variables (for debug use only).'
- @echo ' help print this message.'
- @echo
- @echo 'Report bugs to <whyglinux AT gmail DOT com>.'
-
-# Show variables (for debug use only.)
-show:
- @echo 'PROGRAM :' $(PROGRAM)
- @echo 'SRCDIRS :' $(SRCDIRS)
- @echo 'HEADERS :' $(HEADERS)
- @echo 'SOURCES :' $(SOURCES)
- @echo 'SRC_CXX :' $(SRC_CXX)
- @echo 'OBJS :' $(OBJS)
- @echo 'DEPS :' $(DEPS)
- @echo 'DEPEND :' $(DEPEND)
- @echo 'COMPILE.c :' $(COMPILE.c)
- @echo 'COMPILE.cxx :' $(COMPILE.cxx)
- @echo 'link.c :' $(LINK.c)
- @echo 'link.cxx :' $(LINK.cxx)
-
-## End of the Makefile ## Suggestions are welcome ## All rights reserved ##
-#############################################################################
diff --git a/poco-httpd/poco-httpd.cpp b/poco-httpd/poco-httpd.cpp
deleted file mode 100644
index 5ca33b6..0000000
--- a/poco-httpd/poco-httpd.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "Poco/Net/HTTPServer.h"
-#include "Poco/Net/HTTPRequestHandler.h"
-#include "Poco/Net/HTTPRequestHandlerFactory.h"
-#include "Poco/Net/HTTPServerParams.h"
-#include "Poco/Net/HTTPServerRequest.h"
-#include "Poco/Net/HTTPServerResponse.h"
-#include "Poco/Net/HTTPServerParams.h"
-#include "Poco/Net/ServerSocket.h"
-#include "Poco/Timestamp.h"
-#include "Poco/DateTimeFormatter.h"
-#include "Poco/DateTimeFormat.h"
-#include "Poco/Exception.h"
-#include "Poco/ThreadPool.h"
-#include "Poco/Util/ServerApplication.h"
-#include "Poco/Util/Option.h"
-#include "Poco/Util/OptionSet.h"
-#include "Poco/Util/HelpFormatter.h"
-#include <iostream>
-
-using Poco::Net::ServerSocket;
-using Poco::Net::HTTPRequestHandler;
-using Poco::Net::HTTPRequestHandlerFactory;
-using Poco::Net::HTTPServer;
-using Poco::Net::HTTPServerRequest;
-using Poco::Net::HTTPServerResponse;
-using Poco::Net::HTTPServerParams;
-using Poco::Timestamp;
-using Poco::DateTimeFormatter;
-using Poco::DateTimeFormat;
-using Poco::ThreadPool;
-using Poco::Util::ServerApplication;
-using Poco::Util::Application;
-using Poco::Util::Option;
-using Poco::Util::OptionSet;
-using Poco::Util::OptionCallback;
-using Poco::Util::HelpFormatter;
-
-class TimeRequestHandler: public HTTPRequestHandler
-{
-public:
- TimeRequestHandler(const std::string& format): _format(format)
- {
- }
-
- void handleRequest(HTTPServerRequest& request,
- HTTPServerResponse& response)
- {
- Application& app = Application::instance();
- app.logger().information("Request from "
- + request.clientAddress().toString());
-
- Timestamp now;
- std::string dt(DateTimeFormatter::format(now, _format));
-
- response.setChunkedTransferEncoding(true);
- response.setContentType("text/html");
-
- std::ostream& ostr = response.send();
- ostr << "<html><head><title>HTTPTimeServer powered by "
- "POCO C++ Libraries</title>";
- ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
- ostr << "<body><p style=\"text-align: center; "
- "font-size: 48px;\">";
- ostr << dt;
- ostr << "</p></body></html>";
- }
-
-private:
- std::string _format;
-};
-
-class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
-{
-public:
- TimeRequestHandlerFactory(const std::string& format):
- _format(format)
- {
- }
-
- HTTPRequestHandler* createRequestHandler(
- const HTTPServerRequest& request)
- {
- if (request.getURI() == "/")
- return new TimeRequestHandler(_format);
- else
- return 0;
- }
-
-private:
- std::string _format;
-};
-
-class HTTPTimeServer: public Poco::Util::ServerApplication
-{
-public:
- HTTPTimeServer(): _helpRequested(false)
- {
- }
-
- ~HTTPTimeServer()
- {
- }
-
-protected:
- void initialize(Application& self)
- {
- loadConfiguration();
- ServerApplication::initialize(self);
- }
-
- void uninitialize()
- {
- ServerApplication::uninitialize();
- }
-
- void defineOptions(OptionSet& options)
- {
- ServerApplication::defineOptions(options);
-
- options.addOption(
- Option("help", "h", "display argument help information")
- .required(false)
- .repeatable(false)
- .callback(OptionCallback<HTTPTimeServer>(
- this, &HTTPTimeServer::handleHelp)));
- }
-
- void handleHelp(const std::string& name,
- const std::string& value)
- {
- HelpFormatter helpFormatter(options());
- helpFormatter.setCommand(commandName());
- helpFormatter.setUsage("OPTIONS");
- helpFormatter.setHeader(
- "A web server that serves the current date and time.");
- helpFormatter.format(std::cout);
- stopOptionsProcessing();
- _helpRequested = true;
- }
-
- int main(const std::vector<std::string>& args)
- {
- if (!_helpRequested)
- {
- unsigned short port = (unsigned short)
- config().getInt("HTTPTimeServer.port", 9980);
- std::string format(
- config().getString("HTTPTimeServer.format",
- DateTimeFormat::SORTABLE_FORMAT));
-
- ServerSocket svs(port);
- HTTPServer srv(new TimeRequestHandlerFactory(format),
- svs, new HTTPServerParams);
- srv.start();
- waitForTerminationRequest();
- srv.stop();
- }
- return Application::EXIT_OK;
- }
-
-private:
- bool _helpRequested;
-};
-
-int main(int argc, char** argv)
-{
- HTTPTimeServer app;
- return app.run(argc, argv);
-} \ No newline at end of file