From 8bc69c54f133e07b0746294ca75a71c6e81c5d89 Mon Sep 17 00:00:00 2001 From: rjawor Date: Fri, 31 Jul 2015 14:45:49 +0200 Subject: [PATCH] removed using namespace --- concordia-server/CMakeLists.txt | 7 +- concordia-server/concordia_server.cpp | 12 +- concordia-server/concordia_server.hpp | 4 +- concordia-server/concordia_server_process.cpp | 43 ++--- concordia-server/echo-cpp.cpp | 175 ------------------ concordia-server/hello_world.cpp | 46 ----- concordia-server/index_controller.cpp | 4 +- concordia-server/index_controller.hpp | 5 +- concordia-server/json_generator.cpp | 2 +- concordia-server/json_generator.hpp | 5 +- concordia-server/searcher_controller.cpp | 6 +- concordia-server/searcher_controller.hpp | 6 +- concordia-server/unit_dao.cpp | 13 ++ concordia-server/unit_dao.hpp | 22 +++ scripts/concordia-server.PID | 1 - tests/testCurl.sh | 2 +- 16 files changed, 74 insertions(+), 279 deletions(-) delete mode 100644 concordia-server/echo-cpp.cpp delete mode 100644 concordia-server/hello_world.cpp create mode 100644 concordia-server/unit_dao.cpp create mode 100644 concordia-server/unit_dao.hpp delete mode 100644 scripts/concordia-server.PID diff --git a/concordia-server/CMakeLists.txt b/concordia-server/CMakeLists.txt index 6df122f..a595eca 100644 --- a/concordia-server/CMakeLists.txt +++ b/concordia-server/CMakeLists.txt @@ -1,15 +1,10 @@ -add_executable(hello_world hello_world.cpp) -target_link_libraries(hello_world fcgi fcgi++) - -add_executable(echo-cpp echo-cpp.cpp) -target_link_libraries(echo-cpp fcgi fcgi++) - add_executable(concordia_server_process concordia_server_process.cpp concordia_server.cpp index_controller.cpp searcher_controller.cpp json_generator.cpp + unit_dao.cpp ) target_link_libraries(concordia_server_process fcgi fcgi++ pq concordia config++ log4cpp ${Boost_LIBRARIES} divsufsort utf8case) diff --git a/concordia-server/concordia_server.cpp b/concordia-server/concordia_server.cpp index 477b104..76b1714 100644 --- a/concordia-server/concordia_server.cpp +++ b/concordia-server/concordia_server.cpp @@ -23,11 +23,11 @@ ConcordiaServer::ConcordiaServer(const std::string & configFilePath) ConcordiaServer::~ConcordiaServer() { } -string ConcordiaServer::handleRequest(string & requestString) { +std::string ConcordiaServer::handleRequest(std::string & requestString) { rapidjson::StringBuffer outputJson; rapidjson::Writer jsonWriter(outputJson); - stringstream outputString; + std::stringstream outputString; try { outputString << "Content-type: application/json\r\n\r\n"; @@ -35,13 +35,13 @@ string ConcordiaServer::handleRequest(string & requestString) { bool hasError = d.Parse(requestString.c_str()).HasParseError(); if (hasError) { - stringstream errorstream; + std::stringstream errorstream; errorstream << "json parse error at offset: " << d.GetErrorOffset() << ", description: " << GetParseError_En(d.GetParseError()); JsonGenerator::signalError(jsonWriter, errorstream.str()); } else { // json parsed - string operation = d[OPERATION_PARAM].GetString(); - string sentence = d[SENTENCE_PARAM].GetString(); + std::string operation = d[OPERATION_PARAM].GetString(); + std::string sentence = d[SENTENCE_PARAM].GetString(); if (operation == ADD_SENTENCE_OP) { _indexController->addSentence(jsonWriter, sentence); } else if (operation == SIMPLE_SEARCH_OP) { @@ -54,7 +54,7 @@ string ConcordiaServer::handleRequest(string & requestString) { } } catch (ConcordiaException & e) { - stringstream errorstream; + std::stringstream errorstream; errorstream << "concordia error: " << e.what(); JsonGenerator::signalError(jsonWriter, errorstream.str()); } diff --git a/concordia-server/concordia_server.hpp b/concordia-server/concordia_server.hpp index a1efdae..59a66c3 100644 --- a/concordia-server/concordia_server.hpp +++ b/concordia-server/concordia_server.hpp @@ -14,8 +14,6 @@ #include "index_controller.hpp" #include "searcher_controller.hpp" -using namespace std; - class ConcordiaServer { public: /*! Constructor. @@ -28,7 +26,7 @@ public: */ virtual ~ConcordiaServer(); - string handleRequest(string & requestString); + std::string handleRequest(std::string & requestString); private: boost::shared_ptr _indexController; diff --git a/concordia-server/concordia_server_process.cpp b/concordia-server/concordia_server_process.cpp index 62f00a9..55576eb 100644 --- a/concordia-server/concordia_server_process.cpp +++ b/concordia-server/concordia_server_process.cpp @@ -9,21 +9,18 @@ #include "config.hpp" #include "concordia_server.hpp" -using namespace std; - static const unsigned long STDIN_MAX = 1000000; - -static string get_request_content(const FCGX_Request & request) { +static std::string get_request_content(const FCGX_Request & request) { char * content_length_str = FCGX_GetParam("CONTENT_LENGTH", request.envp); unsigned long content_length = STDIN_MAX; if (content_length_str) { content_length = strtol(content_length_str, &content_length_str, 10); if (*content_length_str) { - cerr << "Can't Parse 'CONTENT_LENGTH='" - << FCGX_GetParam("CONTENT_LENGTH", request.envp) - << "'. Consuming stdin up to " << STDIN_MAX << endl; + std::cerr << "Can't Parse 'CONTENT_LENGTH='" + << FCGX_GetParam("CONTENT_LENGTH", request.envp) + << "'. Consuming stdin up to " << STDIN_MAX << std::endl; } if (content_length > STDIN_MAX) { @@ -35,17 +32,17 @@ static string get_request_content(const FCGX_Request & request) { } char * content_buffer = new char[content_length]; - cin.read(content_buffer, content_length); - content_length = cin.gcount(); + std::cin.read(content_buffer, content_length); + content_length = std::cin.gcount(); // Chew up any remaining stdin - this shouldn't be necessary // but is because mod_fastcgi doesn't handle it correctly. // ignore() doesn't set the eof bit in some versions of glibc++ // so use gcount() instead of eof()... - do cin.ignore(1024); while (cin.gcount() == 1024); + do std::cin.ignore(1024); while (std::cin.gcount() == 1024); - string content(content_buffer, content_length); + std::string content(content_buffer, content_length); delete [] content_buffer; return content; } @@ -53,9 +50,9 @@ static string get_request_content(const FCGX_Request & request) { int main(int argc, char** argv) { // Backup the stdio streambufs - streambuf * cin_streambuf = cin.rdbuf(); - streambuf * cout_streambuf = cout.rdbuf(); - streambuf * cerr_streambuf = cerr.rdbuf(); + std::streambuf * cin_streambuf = std::cin.rdbuf(); + std::streambuf * cout_streambuf = std::cout.rdbuf(); + std::streambuf * cerr_streambuf = std::cerr.rdbuf(); ConcordiaServer concordiaServer(CONFIG_FILE_PATH); @@ -69,22 +66,22 @@ int main(int argc, char** argv) { fcgi_streambuf cout_fcgi_streambuf(request.out); fcgi_streambuf cerr_fcgi_streambuf(request.err); - cin.rdbuf(&cin_fcgi_streambuf); - cout.rdbuf(&cout_fcgi_streambuf); - cerr.rdbuf(&cerr_fcgi_streambuf); + std::cin.rdbuf(&cin_fcgi_streambuf); + std::cout.rdbuf(&cout_fcgi_streambuf); + std::cerr.rdbuf(&cerr_fcgi_streambuf); - string content = get_request_content(request); + std::string content = get_request_content(request); - string requestString(content); - cout << concordiaServer.handleRequest(requestString); + std::string requestString(content); + std::cout << concordiaServer.handleRequest(requestString); // Note: the fcgi_streambuf destructor will auto flush } // restore stdio streambufs - cin.rdbuf(cin_streambuf); - cout.rdbuf(cout_streambuf); - cerr.rdbuf(cerr_streambuf); + std::cin.rdbuf(cin_streambuf); + std::cout.rdbuf(cout_streambuf); + std::cerr.rdbuf(cerr_streambuf); return 0; } diff --git a/concordia-server/echo-cpp.cpp b/concordia-server/echo-cpp.cpp deleted file mode 100644 index e6fd8f9..0000000 --- a/concordia-server/echo-cpp.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * A simple FastCGI application example in C++. - * - * $Id: echo-cpp.cpp,v 1.10 2002/02/25 00:46:17 robs Exp $ - * - * Copyright (c) 2001 Rob Saccoccio and Chelsea Networks - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#ifdef _WIN32 -#include -#else -#include -extern char ** environ; -#endif -#include "fcgio.h" -#include "fcgi_config.h" // HAVE_IOSTREAM_WITHASSIGN_STREAMBUF - -using namespace std; - -// Maximum number of bytes allowed to be read from stdin -static const unsigned long STDIN_MAX = 1000000; - -static void penv(const char * const * envp) -{ - cout << "
\n";
-    for ( ; *envp; ++envp)
-    {
-        cout << *envp << "\n";
-    }
-    cout << "
\n"; -} - -static long gstdin(FCGX_Request * request, char ** content) -{ - char * clenstr = FCGX_GetParam("CONTENT_LENGTH", request->envp); - unsigned long clen = STDIN_MAX; - - if (clenstr) - { - clen = strtol(clenstr, &clenstr, 10); - if (*clenstr) - { - cerr << "can't parse \"CONTENT_LENGTH=" - << FCGX_GetParam("CONTENT_LENGTH", request->envp) - << "\"\n"; - clen = STDIN_MAX; - } - - // *always* put a cap on the amount of data that will be read - if (clen > STDIN_MAX) clen = STDIN_MAX; - - *content = new char[clen]; - - cin.read(*content, clen); - clen = cin.gcount(); - } - else - { - // *never* read stdin when CONTENT_LENGTH is missing or unparsable - *content = 0; - clen = 0; - } - - // Chew up any remaining stdin - this shouldn't be necessary - // but is because mod_fastcgi doesn't handle it correctly. - - // ignore() doesn't set the eof bit in some versions of glibc++ - // so use gcount() instead of eof()... - do cin.ignore(1024); while (cin.gcount() == 1024); - - return clen; -} - -int main (void) -{ - int count = 0; - long pid = getpid(); - - streambuf * cin_streambuf = cin.rdbuf(); - streambuf * cout_streambuf = cout.rdbuf(); - streambuf * cerr_streambuf = cerr.rdbuf(); - - FCGX_Request request; - - FCGX_Init(); - FCGX_InitRequest(&request, 0, 0); - - while (FCGX_Accept_r(&request) == 0) - { - // Note that the default bufsize (0) will cause the use of iostream - // methods that require positioning (such as peek(), seek(), - // unget() and putback()) to fail (in favour of more efficient IO). - fcgi_streambuf cin_fcgi_streambuf(request.in); - fcgi_streambuf cout_fcgi_streambuf(request.out); - fcgi_streambuf cerr_fcgi_streambuf(request.err); - -#if HAVE_IOSTREAM_WITHASSIGN_STREAMBUF - cin = &cin_fcgi_streambuf; - cout = &cout_fcgi_streambuf; - cerr = &cerr_fcgi_streambuf; -#else - cin.rdbuf(&cin_fcgi_streambuf); - cout.rdbuf(&cout_fcgi_streambuf); - cerr.rdbuf(&cerr_fcgi_streambuf); -#endif - - // Although FastCGI supports writing before reading, - // many http clients (browsers) don't support it (so - // the connection deadlocks until a timeout expires!). - char * content; - unsigned long clen = gstdin(&request, &content); - - cout << "Content-type: text/html\r\n" - "\r\n" - "echo-cpp\n" - "

echo-cpp

\n" - "

PID: " << pid << "

\n" - "

Request Number: " << ++count << "

\n"; - - cout << "

Request Environment

\n"; - penv(request.envp); - - cout << "

Process/Initial Environment

\n"; - penv(environ); - - cout << "

Standard Input - " << clen; - if (clen == STDIN_MAX) cout << " (STDIN_MAX)"; - cout << " bytes

\n"; - if (clen) cout.write(content, clen); - - if (content) delete []content; - - // If the output streambufs had non-zero bufsizes and - // were constructed outside of the accept loop (i.e. - // their destructor won't be called here), they would - // have to be flushed here. - } - -#if HAVE_IOSTREAM_WITHASSIGN_STREAMBUF - cin = cin_streambuf; - cout = cout_streambuf; - cerr = cerr_streambuf; -#else - cin.rdbuf(cin_streambuf); - cout.rdbuf(cout_streambuf); - cerr.rdbuf(cerr_streambuf); -#endif - - return 0; -} diff --git a/concordia-server/hello_world.cpp b/concordia-server/hello_world.cpp deleted file mode 100644 index 3e62e32..0000000 --- a/concordia-server/hello_world.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include "fcgio.h" - -using namespace std; - -int main(void) { - // Backup the stdio streambufs - streambuf * cin_streambuf = cin.rdbuf(); - streambuf * cout_streambuf = cout.rdbuf(); - streambuf * cerr_streambuf = cerr.rdbuf(); - - FCGX_Request request; - - FCGX_Init(); - FCGX_InitRequest(&request, 0, 0); - - while (FCGX_Accept_r(&request) == 0) { - fcgi_streambuf cin_fcgi_streambuf(request.in); - fcgi_streambuf cout_fcgi_streambuf(request.out); - fcgi_streambuf cerr_fcgi_streambuf(request.err); - - cin.rdbuf(&cin_fcgi_streambuf); - cout.rdbuf(&cout_fcgi_streambuf); - cerr.rdbuf(&cerr_fcgi_streambuf); - - cout << "Content-type: text/html\r\n" - << "\r\n" - << "\n" - << " \n" - << " Hello, World!\n" - << " \n" - << " \n" - << "

Hello, World!

\n" - << " \n" - << "\n"; - - // Note: the fcgi_streambuf destructor will auto flush - } - - // restore stdio streambufs - cin.rdbuf(cin_streambuf); - cout.rdbuf(cout_streambuf); - cerr.rdbuf(cerr_streambuf); - - return 0; -} diff --git a/concordia-server/index_controller.cpp b/concordia-server/index_controller.cpp index 76f6ee7..728d5c0 100644 --- a/concordia-server/index_controller.cpp +++ b/concordia-server/index_controller.cpp @@ -11,7 +11,7 @@ IndexController::~IndexController() { } -void IndexController::addSentence(rapidjson::Writer & jsonWriter, string & sentence) { +void IndexController::addSentence(rapidjson::Writer & jsonWriter, std::string & sentence) { try { Example example(sentence, 0); @@ -23,7 +23,7 @@ void IndexController::addSentence(rapidjson::Writer & j jsonWriter.String("success"); jsonWriter.EndObject(); } catch (ConcordiaException & e) { - stringstream errorstream; + std::stringstream errorstream; errorstream << "concordia error: " << e.what(); JsonGenerator::signalError(jsonWriter, errorstream.str()); } diff --git a/concordia-server/index_controller.hpp b/concordia-server/index_controller.hpp index 716450d..e004e5c 100644 --- a/concordia-server/index_controller.hpp +++ b/concordia-server/index_controller.hpp @@ -8,9 +8,6 @@ #include "rapidjson/writer.h" - -using namespace std; - class IndexController { public: /*! Constructor. @@ -21,7 +18,7 @@ public: */ virtual ~IndexController(); - void addSentence(rapidjson::Writer & jsonWriter, string & sentence); + void addSentence(rapidjson::Writer & jsonWriter, std::string & sentence); private: boost::shared_ptr _concordia; diff --git a/concordia-server/json_generator.cpp b/concordia-server/json_generator.cpp index 3bd7d84..9f06f2e 100644 --- a/concordia-server/json_generator.cpp +++ b/concordia-server/json_generator.cpp @@ -8,7 +8,7 @@ JsonGenerator::~JsonGenerator() { } -void JsonGenerator::signalError(rapidjson::Writer & jsonWriter, string message) { +void JsonGenerator::signalError(rapidjson::Writer & jsonWriter, std::string message) { jsonWriter.StartObject(); jsonWriter.String("status"); jsonWriter.String("error"); diff --git a/concordia-server/json_generator.hpp b/concordia-server/json_generator.hpp index db5c142..26e00e9 100644 --- a/concordia-server/json_generator.hpp +++ b/concordia-server/json_generator.hpp @@ -5,9 +5,6 @@ #include "rapidjson/writer.h" - -using namespace std; - class JsonGenerator { public: /*! Constructor. @@ -17,7 +14,7 @@ public: */ virtual ~JsonGenerator(); - static void signalError(rapidjson::Writer & jsonWriter, string message); + static void signalError(rapidjson::Writer & jsonWriter, std::string message); private: diff --git a/concordia-server/searcher_controller.cpp b/concordia-server/searcher_controller.cpp index 040822f..1d3d949 100644 --- a/concordia-server/searcher_controller.cpp +++ b/concordia-server/searcher_controller.cpp @@ -12,8 +12,8 @@ SearcherController::~SearcherController() { } -void SearcherController::simpleSearch(rapidjson::Writer & jsonWriter, string & pattern) { - vector result = _concordia->simpleSearch(pattern); +void SearcherController::simpleSearch(rapidjson::Writer & jsonWriter, std::string & pattern) { + std::vector result = _concordia->simpleSearch(pattern); jsonWriter.StartObject(); jsonWriter.String("status"); @@ -27,7 +27,7 @@ void SearcherController::simpleSearch(rapidjson::Writer jsonWriter.EndObject(); } -void SearcherController::concordiaSearch(rapidjson::Writer & jsonWriter, string & pattern) { +void SearcherController::concordiaSearch(rapidjson::Writer & jsonWriter, std::string & pattern) { jsonWriter.StartObject(); jsonWriter.String("status"); jsonWriter.String("error"); diff --git a/concordia-server/searcher_controller.hpp b/concordia-server/searcher_controller.hpp index 9d21c29..190c23c 100644 --- a/concordia-server/searcher_controller.hpp +++ b/concordia-server/searcher_controller.hpp @@ -9,8 +9,6 @@ #include "rapidjson/writer.h" -using namespace std; - class SearcherController { public: /*! Constructor. @@ -21,9 +19,9 @@ public: */ virtual ~SearcherController(); - void simpleSearch(rapidjson::Writer & jsonWriter, string & pattern); + void simpleSearch(rapidjson::Writer & jsonWriter, std::string & pattern); - void concordiaSearch(rapidjson::Writer & jsonWriter, string & pattern); + void concordiaSearch(rapidjson::Writer & jsonWriter, std::string & pattern); private: boost::shared_ptr _concordia; diff --git a/concordia-server/unit_dao.cpp b/concordia-server/unit_dao.cpp new file mode 100644 index 0000000..f004bea --- /dev/null +++ b/concordia-server/unit_dao.cpp @@ -0,0 +1,13 @@ +#include "unit_dao.hpp" + + +UnitDAO::UnitDAO() { +} + +UnitDAO::~UnitDAO() { +} + +SUFFIX_MARKER_TYPE UnitDAO::addSentence(std::string & sentence) { + +} + diff --git a/concordia-server/unit_dao.hpp b/concordia-server/unit_dao.hpp new file mode 100644 index 0000000..88bf868 --- /dev/null +++ b/concordia-server/unit_dao.hpp @@ -0,0 +1,22 @@ +#ifndef UNIT_DAO_HDR +#define UNIT_DAO_HDR + +#include + +#include + +class UnitDAO { +public: + /*! Constructor. + */ + UnitDAO(); + /*! Destructor. + */ + virtual ~UnitDAO(); + + SUFFIX_MARKER_TYPE addSentence(std::string & sentence); +private: + +}; + +#endif diff --git a/scripts/concordia-server.PID b/scripts/concordia-server.PID deleted file mode 100644 index 129a03b..0000000 --- a/scripts/concordia-server.PID +++ /dev/null @@ -1 +0,0 @@ -14823 diff --git a/tests/testCurl.sh b/tests/testCurl.sh index 975c4a0..df73f45 100755 --- a/tests/testCurl.sh +++ b/tests/testCurl.sh @@ -1,5 +1,5 @@ #!/bin/sh #curl -H "Content-Type: application/json" -X POST -d '{"operation":"addSentence", "sentence":"zupełnie nowe zdanie"}' http://localhost -curl -H "Content-Type: application/json" -X POST -d '{"operation":"simpleSearch", "sentence":"zupełnie snowe"}' http://localhost +curl -H "Content-Type: application/json" -X POST -d '{"operation":"simpleSearch", "sentence":"zupełnie nowe"}' http://localhost