Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Moved around some directories and updated build scripts.
  • Loading branch information
glynos committed Dec 26, 2012
commit e7bfb972a5c83d2e0e7f9717124088fcad5cd572
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ if (Boost_FOUND)
if(CPP-NETLIB_BUILD_TESTS)
enable_testing()
endif()
add_subdirectory(libs/network/src)
#add_subdirectory(libs/network/src)
if(CPP-NETLIB_BUILD_TESTS)
enable_testing()
add_subdirectory(libs/network/test)
#add_subdirectory(libs/network/test)
if (NOT MSVC)
add_subdirectory(libs/mime/test)
#add_subdirectory(libs/mime/test)
endif(NOT MSVC)
endif()
if(CPP-NETLIB_BUILD_EXAMPLES)
add_subdirectory(libs/network/example)
#add_subdirectory(libs/network/example)
endif()
endif(Boost_FOUND)

Expand All @@ -104,3 +104,10 @@ message(STATUS " CPP-NETLIB_BUILD_TESTS: ${CPP-NETLIB_BUILD_TESTS}\t(Buil
message(STATUS " CPP-NETLIB_BUILD_EXAMPLES: ${CPP-NETLIB_BUILD_EXAMPLES}\t(Build the examples using cpp-netlib: ON, OFF)")
message(STATUS " CPP-NETLIB_ALWAYS_LOGGING: ${CPP-NETLIB_ALWAYS_LOGGING}\t(Allow cpp-netlib to log debug messages even in non-debug mode: ON, OFF)")
message(STATUS " CPP-NETLIB_DISABLE_LOGGING: ${CPP-NETLIB_DISABLE_LOGGING}\t(Disable logging definitely, no logging code will be generated or compiled: ON, OFF)")

############################################################################
#
# The code following this point is for the new directory structure
#

add_subdirectory(uri)
30 changes: 15 additions & 15 deletions libs/network/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if( CPP-NETLIB_ALWAYS_LOGGING )
endif()

if( NOT CPP-NETLIB_DISABLE_LOGGING )
set( CPP-NETLIB_LOGGING_SRCS
logging/logging.cpp
set( CPP-NETLIB_LOGGING_SRCS
logging/logging.cpp
)
add_library(cppnetlib-logging ${CPP-NETLIB_LOGGING_SRCS})
foreach (src_file ${CPP-NETLIB_LOGGING_SRCS})
Expand All @@ -40,24 +40,24 @@ if( NOT CPP-NETLIB_DISABLE_LOGGING )
PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
endif()
endforeach(src_file)

# this library name is defined only if we created the target
# if not then it will be empty
set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )

endif()

set(CPP-NETLIB_URI_SRCS uri/uri.cpp uri/schemes.cpp uri/normalize.cpp)
add_library(cppnetlib-uri ${CPP-NETLIB_URI_SRCS})
foreach (src_file ${CPP-NETLIB_URI_SRCS})
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set_source_files_properties(${src_file}
PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
set_source_files_properties(${src_file}
PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
endif()
endforeach(src_file)

#set(CPP-NETLIB_URI_SRCS uri/uri.cpp uri/schemes.cpp uri/normalize.cpp)
#add_library(cppnetlib-uri ${CPP-NETLIB_URI_SRCS})
#foreach (src_file ${CPP-NETLIB_URI_SRCS})
#if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
# set_source_files_properties(${src_file}
# PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
#elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
# set_source_files_properties(${src_file}
# PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
#endif()
#endforeach(src_file)

set(CPP-NETLIB_MESSAGE_SRCS message/message.cpp)
add_library(cppnetlib-message ${CPP-NETLIB_MESSAGE_SRCS})
Expand Down
7 changes: 7 additions & 0 deletions message/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Glyn Matthews 2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

add_subdirectory(src)
add_subdirectory(test)
15 changes: 15 additions & 0 deletions message/src/directives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2011 Dean Michael Berris (dberris@google.com).
// Copyright 2011 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// This is the directives file where all standard directives on messages are
// pulled in and compiled into a library.

#ifdef NETWORK_NO_LIB
#undef NETWORK_NO_LIB
#endif

#include <network/message/directives/header.ipp>
#include <network/message/directives/remove_header.ipp>
15 changes: 15 additions & 0 deletions message/src/message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2011 Dean Michael Berris (dberris@google.com).
// Copyright 2011 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// This is the conglomeration of all message-related implementation files. All
// we're doing is including all the .ipp files that are relevant.

#ifdef NETWORK_NO_LIB
#undef NETWORK_NO_LIB
#endif

#include <network/message/message.ipp>
#include <network/message/message_base.ipp>
31 changes: 31 additions & 0 deletions message/src/message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Dean Michael Berris 2007.
// Copyright 2011 Dean Michael Berris (dberris@google.com).
// Copyright 2011 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_MESSAGE_HPP_20111021
#define NETWORK_MESSAGE_HPP_20111021

#include <network/message_fwd.hpp>
#include <network/detail/directive_base.hpp>
#include <network/detail/wrapper_base.hpp>
#include <network/message/directives.hpp>
#include <network/message/wrappers.hpp>
#include <network/message/transformers.hpp>

#include <network/message/modifiers/add_header.hpp>
#include <network/message/modifiers/remove_header.hpp>
#include <network/message/modifiers/clear_headers.hpp>
#include <network/message/modifiers/source.hpp>
#include <network/message/modifiers/destination.hpp>
#include <network/message/modifiers/body.hpp>

#include <network/message/message.hpp>

#ifdef NETWORK_DEBUG
#include <network/message/message_concept.hpp>
#endif

#endif // NETWORK_MESSAGE_HPP_20111021
48 changes: 48 additions & 0 deletions message/src/message/basic_message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
// Copyright 2011 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911
#define NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911

#include <network/message_base.hpp>
#include <boost/scoped_ptr.hpp>

namespace network {

struct basic_storage_pimpl;

struct basic_storage_base : message_base {
basic_storage_base();
basic_storage_base(basic_storage_base const &);
basic_storage_base(basic_storage_base &&);
virtual void set_destination(std::string const & destination);
virtual void set_source(std::string const & source);
virtual void append_header(std::string const & name,
std::string const & value);
virtual void remove_headers(std::string const & name);
virtual void remove_headers();
virtual void set_body(std::string const & body);
virtual void append_body(std::string const & data);

virtual void get_destination(std::string & destination);
virtual void get_source(std::string & source);
virtual void get_headers(function<void(std::string const &, std::string const &)> inserter);
virtual void get_headers(std::string const & name, function<void(std::string const &, std::string const &)> inserter);
virtual void get_body(std::string & body);
virtual void get_body(function<void(iterator_range<char const *>)> chunk_reader, size_t size);

virtual void swap(basic_storage_base & other);

virtual ~basic_storage_base();
protected:
scoped_ptr<basic_storage_pimpl> pimpl;
};

void swap(basic_storage_base & l, basic_storage_base & r);

} // namespace network

#endif /* NETWORK_MESSAGE_BASIC_MESSAGE_HPP_20110911 */
110 changes: 110 additions & 0 deletions message/src/message/basic_message.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
// Copyright 2011 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911
#define NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911

namespace network {

struct basic_storage_pimpl {
basic_storage_pimpl();
basic_storage_pimpl(basic_storage_pimpl const &);

virtual basic_storage_pimpl* clone();
protected:
friend struct basic_storage_base;
std::string source_, destination_;
typedef std::multimap<std::string, std::string> headers_container_type;
headers_container_type headers_;
std::string body_;
};

basic_storage_base::basic_storage_base()
: pimpl(new (std::nothrow) basic_storage_pimpl())
{}

basic_storage_base::basic_storage_base(basic_storage_base const & other)
: pimpl(other.clone())
{}

void basic_storage_base::set_destination(std::string const & destination) {
pimpl->destination_ = destination;
}

void basic_storage_base::set_source(std::string const & source) {
pimpl->source_ = source;
}

void basic_storage_base::append_header(std::string const & name,
std::string const & value) {
pimpl->headers_.insert(std::make_pair(name, value));
}

void basic_storage_base::remove_headers(std::string const & name) {
pimpl->headers_.erase(name);
}

void basic_storage_base::remove_headers() {
basic_storage_pimpl::headers_container_type().swap(pimpl->headers_);
}

void basic_storage_base::set_body(std::string const & body) {
pimpl->body = body;
}

void basic_storage_base::append_body(std::string const & data) {
pimpl->body.append(data);
}

void basic_storage_base::get_destination(std::string & destination) {
destination = pimpl->destination;
}

void basic_storage_base::get_source(std::string & source) {
source = pimpl->source;
}

void basic_storage_base::get_headers(function<void(std::string const &, std::string const &)> inserter) {
copy(pimpl->headers_, inserter);
}

void basic_storage_base::get_headers(std::string const & name, function<void(std::string const &, std::string const &)> inserter) {
basic_storage_pimpl::headers_container_type::const_iterator
it = pimpl->headers_.find(name),
pe = pimpl->headers_.end();
for (; it != pe; ++it)
inserter(it->first, it->second);
}

void basic_storage_base::get_body(std::string & body) {
// TODO use iostreams!
body = pimpl_->body;
}

void basic_storage_base::get_body(function<void(iterator_range<char const *>)> chunk_reader, size_t size) {
// TODO use iostreams!
std::string::const_iterator it = pimpl->body.begin(),
pe = pimpl->body.end();
std::advance(it, size);
chunk_reader(make_iterator_range(it, pe));
pimpl->body.assign(it, pe);
}

basic_storage_base::~basic_storage_base() {
pimpl->reset();
}

void basic_storage_base::swap(basic_storage_base & other) {
std::swap(pimpl, other.pimpl);
}

void swap(basic_storage_base & l, basic_storage_base & r) {
l.swap(r);
}

} /* network */

#endif /* NETWORK_MESSAGE_BASIC_MESSAGE_IPP_20110911 */
22 changes: 22 additions & 0 deletions message/src/message/directives.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Dean Michael Berris 2007.
// Copyright 2012 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_MESSAGE_DIRECTIVES_HPP__
#define NETWORK_MESSAGE_DIRECTIVES_HPP__

#include <network/message/directives/detail/string_directive.hpp>
#include <network/message/directives/header.hpp>
#include <network/message/directives/remove_header.hpp>

namespace network {

NETWORK_STRING_DIRECTIVE(source);
NETWORK_STRING_DIRECTIVE(destination);
NETWORK_STRING_DIRECTIVE(body);

} // namespace network

#endif // NETWORK_MESSAGE_DIRECTIVES_HPP__
49 changes: 49 additions & 0 deletions message/src/message/directives/detail/string_directive.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2010-2012 Dean Michael Berris <dberris@google.com>
// Copyright 2012 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_MESSAGE_DIRECTIVES_DETAIL_STRING_DIRECTIVE_HPP_20100915
#define NETWORK_MESSAGE_DIRECTIVES_DETAIL_STRING_DIRECTIVE_HPP_20100915

#include <boost/variant/variant.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>

// To create your own string directive, you can use the preprocessor macro
// NETWORK_STRING_DIRECTIVE which takes three parameters: the name of
// the directive, a name for the variable to use in the directive visitor,
// and the body to be implemented in the visitor. An example directive for
// setting the source of a message would look something like this given the
// NETWORK_STRING_DIRECTIVE macro:
//
// NETWORK_STRING_DIRECTIVE(source, source_,
// message.source(source_)
// , message.source=source_);
//

#ifndef NETWORK_STRING_DIRECTIVE
#define NETWORK_STRING_DIRECTIVE(name) \
struct name##_directive { \
std::string const & value; \
explicit name##_directive(std::string const & value_) \
: value(value_) {} \
name##_directive(name##_directive const & other) \
: value(other.value) {} \
template <class Message> \
void operator()(Message & message) const { \
message.set_##name(value); \
} \
}; \
\
inline name##_directive const \
name (std::string const & input) { \
return name##_directive(input); \
}
#endif /* NETWORK_STRING_DIRECTIVE */

#endif /* NETWORK_MESSAGE_DIRECTIVES_DETAIL_STRING_DIRECTIVE_HPP_20100915 */
Loading