mirror of
https://github.com/libretro/cannonball.git
synced 2026-10-17 14:24:55 +00:00
libretro: modernize CannonBall core
Synchronize the libretro core with the modern CannonBall engine. Add custom music and reset support, migrate XML handling and score persistence to pugixml, reduce compiler warnings, and remove the unused vendored Boost dependency.
This commit is contained in:
1 parent
343187efb5
commit
fc21962705
2867 files changed
+21770
-485881
No files matched your search
+6
-2
@@ -25,6 +25,7 @@ mpr-10378.16
|
||||
opr-10185.11
|
||||
opr-10186.47
|
||||
opr-10188.71
|
||||
opr-10188.71f
|
||||
opr-10189.70
|
||||
opr-10190.69
|
||||
opr-10191.68
|
||||
@@ -163,8 +164,6 @@ local.properties
|
||||
*.vspscc
|
||||
.builds
|
||||
*.dotCover
|
||||
*.o
|
||||
*.a
|
||||
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||
#packages/
|
||||
@@ -264,10 +263,15 @@ pip-log.txt
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
old_version
|
||||
|
||||
|
||||
#############
|
||||
## libretro
|
||||
#############
|
||||
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
*.dll
|
||||
*.dylib
|
||||
+2
-4
@@ -9,7 +9,6 @@ INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc
|
||||
endif
|
||||
|
||||
FLAGS += -D__LIBRETRO__
|
||||
#FLAGS += -DCANNONBOARD
|
||||
FLAGS += -DCOMPILE_SOUND_CODE
|
||||
|
||||
SOURCES_C :=
|
||||
@@ -19,6 +18,7 @@ else
|
||||
SOURCES_C += \
|
||||
$(LIBRETRO_COMM_DIR)/file/file_path.c \
|
||||
$(LIBRETRO_COMM_DIR)/file/file_path_io.c \
|
||||
$(LIBRETRO_COMM_DIR)/file/retro_dirent.c \
|
||||
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
|
||||
$(LIBRETRO_COMM_DIR)/compat/compat_snprintf.c \
|
||||
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \
|
||||
@@ -45,8 +45,6 @@ SOURCES_CXX := \
|
||||
$(CORE_DIR)/src/main/utils.cpp \
|
||||
$(CORE_DIR)/src/main/video.cpp \
|
||||
\
|
||||
$(CORE_DIR)/src/main/cannonboard/interface.cpp \
|
||||
$(CORE_DIR)/src/main/cannonboard/asyncserial.cpp
|
||||
|
||||
SOURCES_CXX += $(CORE_DIR)/src/main/engine/oanimseq.cpp \
|
||||
$(CORE_DIR)/src/main/engine/oattractai.cpp \
|
||||
@@ -84,7 +82,7 @@ SOURCES_CXX := \
|
||||
$(CORE_DIR)/src/main/hwvideo/hwsprites.cpp \
|
||||
$(CORE_DIR)/src/main/hwvideo/hwtiles.cpp \
|
||||
\
|
||||
$(CORE_DIR)/src/main/frontend/cabdiag.cpp \
|
||||
$(CORE_DIR)/deps/pugixml/pugixml.cpp \
|
||||
$(CORE_DIR)/src/main/frontend/config.cpp \
|
||||
$(CORE_DIR)/src/main/frontend/menu.cpp \
|
||||
$(CORE_DIR)/src/main/frontend/ttrial.cpp
|
||||
@@ -1,87 +1,95 @@
|
||||
Cannonball - OutRun Engine
|
||||
==========================
|
||||
# CannonBall Libretro
|
||||
|
||||
See [Reassembler Blog](http://reassembler.blogspot.co.uk/).
|
||||
CannonBall is an enhanced game engine for Sega's 1986 OutRun arcade
|
||||
game. The original 68000 and Z80 code was rewritten in C++ by Chris
|
||||
White, enabling enhancements such as smoother frame rates, widescreen
|
||||
rendering and additional game modes.
|
||||
|
||||
Credits
|
||||
-------
|
||||
This repository contains the Libretro core and synchronizes it with the
|
||||
modern CannonBall engine while retaining the Libretro integration.
|
||||
|
||||
* Chris White - Project creator.
|
||||
* Arun Horne - Cross platform work.
|
||||
## Requirements
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
CannonBall requires legally obtained ROM files from the OutRun Revision
|
||||
B arcade set. No copyrighted game data is included in this repository.
|
||||
|
||||
Cannonball has been successfully built for Windows, Mac OS X, Linux, Open Pandora and the Raspberry Pi.
|
||||
For instructions on downloading the CannonBall support files, arranging
|
||||
the ROM files and starting the core, see:
|
||||
|
||||
* Install your favourite C++ environment (e.g. GCC, Visual Studio, Xcode, MingGW etc.)
|
||||
* Install [CMake](http://www.cmake.org/). This generates your platform and compiler build files.
|
||||
* Extract the [Boost Library](http://www.boost.org/) somewhere, for example: c:\coding\lib\boost_1_51_0
|
||||
* Extract the [SDL Library](http://www.libsdl.org/download-1.2.php) somewhere, for example: c:\coding\lib\SDL-1.2.15
|
||||
* Read the SDL documentation & compile the SDL Library for your system.
|
||||
* Windows only, download and install the [Direct 8.1 SDK](http://stackoverflow.com/questions/5192384/looking-for-the-old-directx-8-1-sdk)
|
||||
* Extract the Cannonball code somewhere, for example: c:\coding\cannonball
|
||||
* You may need to create a .cmake file for your system to configure specific options. See the cmake subdirectory for more details. If not, the default.cmake file will be used.
|
||||
https://docs.libretro.com/library/cannonball/
|
||||
|
||||
Build
|
||||
-----
|
||||
The core supports the `.game` and `.88` content entry points.
|
||||
|
||||
* Run CMake to generate the relevant build files for your compiler. You can optionally pass -DTARGET=filename to pass a custom .cmake file
|
||||
* Compile using your chosen compiler. Further details below.
|
||||
## Features
|
||||
|
||||
###
|
||||
- original, 30, 60 and 120 FPS rendering modes
|
||||
- widescreen and high-resolution rendering
|
||||
- Continuous and Time Trial game modes
|
||||
- analog steering, accelerator and brake controls
|
||||
- force feedback on supported frontend and input-driver combinations
|
||||
- custom track support
|
||||
- optional custom music support
|
||||
- additional car palette options
|
||||
- Libretro core reset support
|
||||
- persistent configuration and high scores
|
||||
- Libretro core options and input remapping
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
Feature availability may depend on the Libretro frontend, operating
|
||||
system and selected input driver.
|
||||
|
||||
### Non-IDE (e.g. straight GCC)
|
||||
|
||||
cmake -G "Insert Generator Name Here" ../cmake
|
||||
make
|
||||
## Building the Libretro core
|
||||
|
||||
### MinGW
|
||||
The Libretro build uses `Makefile` and `Makefile.common`.
|
||||
|
||||
cmake -G "MinGW Makefiles" -DTARGET=mingw ../cmake
|
||||
mingw32-make
|
||||
|
||||
### Visual Studio 2010
|
||||
Run:
|
||||
|
||||
cmake -G "Visual Studio 10" ../cmake
|
||||
make platform=<target> -j<number-of-jobs>
|
||||
|
||||
### Mac OSX
|
||||
For example, on macOS:
|
||||
|
||||
cmake -G "Unix Makefiles" -DTARGET:STRING=macosx ../cmake
|
||||
make
|
||||
make platform=osx -j"$(sysctl -n hw.ncpu)"
|
||||
|
||||
* Copy SDL.DLL and the roms subdirectory to the build directory.
|
||||
* Right click the 'cannonball' project in the IDE and choose 'Set as StartUp project'.
|
||||
* You can then compile, debug and run from Visual Studio as expected.
|
||||
The resulting core uses the platform-appropriate shared-library
|
||||
extension, such as:
|
||||
|
||||
Run
|
||||
---
|
||||
- `cannonball_libretro.so` on Linux and other Unix-like systems
|
||||
- `cannonball_libretro.dylib` on macOS
|
||||
- `cannonball_libretro.dll` on Windows
|
||||
|
||||
* Copy the OutRun revision B romset to the roms subdirectory. Rename the files if necessary.
|
||||
* Copy or link the roms subdirectory to whereever your executable resides.
|
||||
Available targets and platform-specific settings are defined in the
|
||||
Makefile.
|
||||
|
||||
###
|
||||
## Dependencies
|
||||
|
||||
ln -s ../roms roms
|
||||
./outrun
|
||||
|
||||
|
||||
Building SDL-1.2.15
|
||||
-------------------
|
||||
The Libretro core includes the required Libretro common sources and
|
||||
pugixml in the repository.
|
||||
|
||||
### Darwin
|
||||
Configuration and high-score XML handling use pugixml. The previous
|
||||
vendored Boost dependency is no longer required.
|
||||
|
||||
./configure --prefix=~/SDL-1.2.15/build --disable-assembly
|
||||
The Libretro build does not require SDL2. SDL2 and CMake are used by the
|
||||
standalone CannonBall application instead.
|
||||
|
||||
### MinGW
|
||||
## Standalone CannonBall
|
||||
|
||||
See: [Setting up MSYS MinGW build system for compiling SDL OpenGL applications](http://blog.pantokrator.net/2006/08/08/setting-up-msysmingw-build-system-for-compiling-sdlopengl-applications/).
|
||||
Documentation and source code for the standalone application are
|
||||
available from the original project:
|
||||
|
||||
Execute the below commands from the msys environment.
|
||||
|
||||
./configure --prefix=/mingw --enable-stdio-redirect=no
|
||||
make
|
||||
make install
|
||||
- Repository: https://github.com/djyt/cannonball
|
||||
- Manual and wiki: https://github.com/djyt/cannonball/wiki
|
||||
- Development blog: http://reassembler.blogspot.co.uk/
|
||||
|
||||
## Credits
|
||||
|
||||
- Chris White — CannonBall creator and original engine implementation
|
||||
- Arun Horne — cross-platform work
|
||||
- Libretro contributors — Libretro integration and maintenance
|
||||
- CannonBall contributors — continued engine development
|
||||
|
||||
## License
|
||||
|
||||
CannonBall is distributed under a non-commercial license. See the
|
||||
repository license files for the complete terms.
|
||||
|
||||
The original OutRun ROM files and other copyrighted game data are not
|
||||
included.
|
||||
+106
-138
@@ -1,21 +1,32 @@
|
||||
cmake_minimum_required (VERSION 2.6.2)
|
||||
# -----------------------------------------------------------------------------
|
||||
# CannonBall CMake setup
|
||||
#
|
||||
# For ports, please try not to edit this file directly.
|
||||
# Everything should go into a win64.cmake equivalent.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required (VERSION 3.3.2) # Might compile lower, but untested
|
||||
project (cannonball)
|
||||
|
||||
set(DCMAKE default.cmake)
|
||||
set(CMDIR ../cmake)
|
||||
# -----------------------------------------------------------------------------
|
||||
# Directory Setup
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Uncomment for debug output
|
||||
#set(Boost_DEBUG 1)
|
||||
# CMake default file (override with -DTARGET=file)
|
||||
set(DCMAKE win64-opengl.cmake)
|
||||
|
||||
# Source location
|
||||
set(main_cpp_base ../src/main)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Platform Specific Setup
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Include relevant CMAKE file (default, mingw, pandora etc.)
|
||||
if(TARGET)
|
||||
set(TCMAKE ${TARGET}.cmake)
|
||||
if(EXISTS ${CMDIR}/${TCMAKE})
|
||||
message("CMake files for ${TARGET} found, using ${TCMAKE}")
|
||||
include(${TCMAKE})
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${TARGET}")
|
||||
message("CMake files for ${TARGET} found")
|
||||
include(${TARGET})
|
||||
else()
|
||||
message("CMake files for ${TARGET} not found, using ${DCMAKE}")
|
||||
include(${DCMAKE})
|
||||
@@ -25,38 +36,20 @@ else()
|
||||
include(${DCMAKE})
|
||||
endif(TARGET)
|
||||
|
||||
set(BOOST_INCLUDEDIR ${lib_base}/boost_1_54_0)
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
# Include
|
||||
include_directories(
|
||||
"${main_cpp_base}"
|
||||
"${BOOST_INCLUDEDIR}"
|
||||
)
|
||||
|
||||
# Create compile time setup
|
||||
file(WRITE ${main_cpp_base}/setup.hpp
|
||||
"// This file is AUTO GENERATED by CMake.
|
||||
#pragma once
|
||||
#include \"SDL_video.h\"
|
||||
const static char* FILENAME_CONFIG = \"${xml_directory}config.xml\";
|
||||
const static char* FILENAME_SCORES = \"${xml_directory}hiscores\";
|
||||
const static char* FILENAME_TTRIAL = \"${xml_directory}hiscores_timetrial\";
|
||||
const static char* FILENAME_CONT = \"${xml_directory}hiscores_continuous\";
|
||||
const static int SDL_FLAGS = ${sdl_flags};
|
||||
"
|
||||
)
|
||||
# -----------------------------------------------------------------------------
|
||||
# Project Source Files
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
set(src_main
|
||||
"${main_cpp_base}/globals.hpp"
|
||||
"${main_cpp_base}/romloader.hpp"
|
||||
"${main_cpp_base}/roms.hpp"
|
||||
"${main_cpp_base}/trackloader.hpp"
|
||||
"${main_cpp_base}/setup.hpp"
|
||||
"${main_cpp_base}/stdint.hpp"
|
||||
"${main_cpp_base}/main.hpp"
|
||||
"${main_cpp_base}/video.hpp"
|
||||
"${main_cpp_base}/utils.hpp"
|
||||
"${main_cpp_base}/windirent.h"
|
||||
|
||||
"${main_cpp_base}/main.cpp"
|
||||
"${main_cpp_base}/romloader.cpp"
|
||||
@@ -70,6 +63,7 @@ set(src_frontend
|
||||
"${main_cpp_base}/frontend/cabdiag.hpp"
|
||||
"${main_cpp_base}/frontend/config.hpp"
|
||||
"${main_cpp_base}/frontend/menu.hpp"
|
||||
"${main_cpp_base}/frontend/menulabels.hpp"
|
||||
"${main_cpp_base}/frontend/ttrial.hpp"
|
||||
|
||||
"${main_cpp_base}/frontend/cabdiag.cpp"
|
||||
@@ -97,81 +91,34 @@ set(src_hwaudio
|
||||
"${main_cpp_base}/hwaudio/soundchip.cpp"
|
||||
"${main_cpp_base}/hwaudio/ym2151.cpp"
|
||||
)
|
||||
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl2/audio.hpp"
|
||||
"${main_cpp_base}/sdl2/timer.hpp"
|
||||
"${main_cpp_base}/sdl2/input.hpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl2/audio.cpp"
|
||||
"${main_cpp_base}/sdl2/timer.cpp"
|
||||
"${main_cpp_base}/sdl2/input.cpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.cpp"
|
||||
)
|
||||
|
||||
if(SDL2)
|
||||
if(OPENGL)
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl2/audio.hpp"
|
||||
"${main_cpp_base}/sdl2/timer.hpp"
|
||||
"${main_cpp_base}/sdl2/input.hpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.hpp"
|
||||
"${main_cpp_base}/sdl2/rendergl.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl2/audio.cpp"
|
||||
"${main_cpp_base}/sdl2/timer.cpp"
|
||||
"${main_cpp_base}/sdl2/input.cpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.cpp"
|
||||
"${main_cpp_base}/sdl2/rendergl.cpp"
|
||||
)
|
||||
elseif(OPENGLES)
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl2/audio.hpp"
|
||||
"${main_cpp_base}/sdl2/timer.hpp"
|
||||
"${main_cpp_base}/sdl2/input.hpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.hpp"
|
||||
"${main_cpp_base}/sdl2/rendergles.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl2/audio.cpp"
|
||||
"${main_cpp_base}/sdl2/timer.cpp"
|
||||
"${main_cpp_base}/sdl2/input.cpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.cpp"
|
||||
"${main_cpp_base}/sdl2/rendergles.cpp"
|
||||
)
|
||||
else()
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl2/audio.hpp"
|
||||
"${main_cpp_base}/sdl2/timer.hpp"
|
||||
"${main_cpp_base}/sdl2/input.hpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.hpp"
|
||||
"${main_cpp_base}/sdl2/rendersurface.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl2/audio.cpp"
|
||||
"${main_cpp_base}/sdl2/timer.cpp"
|
||||
"${main_cpp_base}/sdl2/input.cpp"
|
||||
"${main_cpp_base}/sdl2/renderbase.cpp"
|
||||
"${main_cpp_base}/sdl2/rendersurface.cpp"
|
||||
)
|
||||
endif()
|
||||
else() #Using legacy, unmantained SDL1.x
|
||||
if(OPENGL)
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl/audio.hpp"
|
||||
"${main_cpp_base}/sdl/timer.hpp"
|
||||
"${main_cpp_base}/sdl/input.hpp"
|
||||
"${main_cpp_base}/sdl/renderbase.hpp"
|
||||
"${main_cpp_base}/sdl/rendergl.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl/audio.cpp"
|
||||
"${main_cpp_base}/sdl/timer.cpp"
|
||||
"${main_cpp_base}/sdl/input.cpp"
|
||||
"${main_cpp_base}/sdl/renderbase.cpp"
|
||||
"${main_cpp_base}/sdl/rendergl.cpp"
|
||||
)
|
||||
else()
|
||||
set(src_sdl
|
||||
"${main_cpp_base}/sdl/audio.hpp"
|
||||
"${main_cpp_base}/sdl/timer.hpp"
|
||||
"${main_cpp_base}/sdl/input.hpp"
|
||||
"${main_cpp_base}/sdl/renderbase.hpp"
|
||||
"${main_cpp_base}/sdl/rendersw.hpp"
|
||||
|
||||
"${main_cpp_base}/sdl/audio.cpp"
|
||||
"${main_cpp_base}/sdl/timer.cpp"
|
||||
"${main_cpp_base}/sdl/input.cpp"
|
||||
"${main_cpp_base}/sdl/renderbase.cpp"
|
||||
"${main_cpp_base}/sdl/rendersw.cpp"
|
||||
)
|
||||
endif()
|
||||
if(OPENGL)
|
||||
set(src_render
|
||||
"${main_cpp_base}/sdl2/rendergl.hpp"
|
||||
"${main_cpp_base}/sdl2/rendergl.cpp"
|
||||
)
|
||||
elseif(OPENGLES)
|
||||
set(src_render
|
||||
"${main_cpp_base}/sdl2/rendergles.hpp"
|
||||
"${main_cpp_base}/sdl2/rendergles.cpp"
|
||||
)
|
||||
else()
|
||||
set(src_render
|
||||
"${main_cpp_base}/sdl2/rendersurface.hpp"
|
||||
"${main_cpp_base}/sdl2/rendersurface.cpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(src_directx
|
||||
@@ -179,13 +126,6 @@ set(src_directx
|
||||
"${main_cpp_base}/directx/ffeedback.cpp"
|
||||
)
|
||||
|
||||
set(src_cannonboard
|
||||
"${main_cpp_base}/cannonboard/asyncserial.hpp"
|
||||
"${main_cpp_base}/cannonboard/interface.hpp"
|
||||
"${main_cpp_base}/cannonboard/asyncserial.cpp"
|
||||
"${main_cpp_base}/cannonboard/interface.cpp"
|
||||
)
|
||||
|
||||
set(src_engine
|
||||
"${main_cpp_base}/engine/oaddresses.hpp"
|
||||
"${main_cpp_base}/engine/oanimseq.hpp"
|
||||
@@ -214,7 +154,6 @@ set(src_engine
|
||||
"${main_cpp_base}/engine/otraffic.hpp"
|
||||
"${main_cpp_base}/engine/outils.hpp"
|
||||
"${main_cpp_base}/engine/outrun.hpp"
|
||||
"${main_cpp_base}/engine/ozoom_lookup.hpp"
|
||||
|
||||
"${main_cpp_base}/engine/oanimseq.cpp"
|
||||
"${main_cpp_base}/engine/oattractai.cpp"
|
||||
@@ -242,6 +181,11 @@ set(src_engine
|
||||
"${main_cpp_base}/engine/outrun.cpp"
|
||||
)
|
||||
|
||||
set(src_engine_data
|
||||
"${main_cpp_base}/engine/data/ozoom_lookup.hpp"
|
||||
"${main_cpp_base}/engine/data/sprite_pals.hpp"
|
||||
)
|
||||
|
||||
set(src_engine_audio
|
||||
"${main_cpp_base}/engine/audio/commands.hpp"
|
||||
"${main_cpp_base}/engine/audio/osound.hpp"
|
||||
@@ -252,34 +196,42 @@ set(src_engine_audio
|
||||
"${main_cpp_base}/engine/audio/osoundint.cpp"
|
||||
)
|
||||
|
||||
# Group files into relevant filters for Visual Studio build
|
||||
SOURCE_GROUP(src FILES ${src_main})
|
||||
SOURCE_GROUP(src\\frontend FILES ${src_frontend})
|
||||
SOURCE_GROUP(src\\hwvideo FILES ${src_hwvideo})
|
||||
SOURCE_GROUP(src\\hwaudio FILES ${src_hwaudio})
|
||||
SOURCE_GROUP(src\\sdl FILES ${src_sdl})
|
||||
SOURCE_GROUP(src\\directx FILES ${src_directx})
|
||||
SOURCE_GROUP(src\\cannonboard FILES ${src_cannonboard})
|
||||
SOURCE_GROUP(src\\engine FILES ${src_engine})
|
||||
SOURCE_GROUP(src\\engine\\audio FILES ${src_engine_audio})
|
||||
|
||||
set(SRCS
|
||||
${src_main}
|
||||
${src_frontend}
|
||||
${src_hwvideo}
|
||||
${src_hwaudio}
|
||||
${src_sdl}
|
||||
${src_render}
|
||||
${src_directx}
|
||||
${src_cannonboard}
|
||||
${src_engine}
|
||||
${src_engine_data}
|
||||
${src_engine_audio}
|
||||
)
|
||||
|
||||
# Group files into relevant filters for Visual Studio build
|
||||
SOURCE_GROUP(src FILES ${src_main})
|
||||
SOURCE_GROUP(src\\frontend FILES ${src_frontend})
|
||||
SOURCE_GROUP(src\\hwvideo FILES ${src_hwvideo})
|
||||
SOURCE_GROUP(src\\hwaudio FILES ${src_hwaudio})
|
||||
SOURCE_GROUP(src\\sdl FILES ${src_sdl})
|
||||
SOURCE_GROUP(src\\sdl FILES ${src_render})
|
||||
SOURCE_GROUP(src\\directx FILES ${src_directx})
|
||||
SOURCE_GROUP(src\\engine FILES ${src_engine})
|
||||
SOURCE_GROUP(src\\engine\\data FILES ${src_engine_data})
|
||||
SOURCE_GROUP(src\\engine\\audio FILES ${src_engine_audio})
|
||||
|
||||
# Add Icon For Windows Builds
|
||||
if(WIN32)
|
||||
set(SRCS ${SRCS} ../res/cannonball.rc)
|
||||
endif(WIN32)
|
||||
|
||||
add_executable(cannonball ${SRCS})
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Compiler Definitions
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(OPENGL)
|
||||
add_definitions(-DWITH_OPENGL)
|
||||
endif()
|
||||
@@ -288,28 +240,44 @@ if(OPENGLES)
|
||||
add_definitions(-DWITH_OPENGLES)
|
||||
endif()
|
||||
|
||||
if(CANNONBOARD)
|
||||
add_definitions(-DCANNONBOARD)
|
||||
endif()
|
||||
# -----------------------------------------------------------------------------
|
||||
# Library Setup
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
add_executable(cannonball ${SRCS})
|
||||
set(SDL2_DIR ${sdl2_dir})
|
||||
find_package(SDL2 REQUIRED)
|
||||
message("SDL2 Include : ${SDL2_INCLUDE_DIRS}")
|
||||
message("SDL2 Libraries: ${SDL2_LIBRARIES}")
|
||||
|
||||
# Copy Configuration file to current build
|
||||
|
||||
if(SDL2)
|
||||
configure_file(../res/config_sdl2.xml ./config.xml
|
||||
COPYONLY
|
||||
# Include
|
||||
include_directories(
|
||||
${main_cpp_base}
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
else()
|
||||
|
||||
link_directories(
|
||||
${platform_link_dirs}
|
||||
)
|
||||
|
||||
target_link_libraries(cannonball
|
||||
${SDL2_LIBRARIES}
|
||||
${platform_link_libs}
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Copy useful files to build destination
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
configure_file(../res/config.xml ./config.xml
|
||||
COPYONLY
|
||||
COPYONLY
|
||||
)
|
||||
endif()
|
||||
|
||||
# Copy Resource files
|
||||
configure_file(../res/tilemap.bin ./res/tilemap.bin
|
||||
COPYONLY
|
||||
)
|
||||
configure_file(../res/tilepatch.bin ./res/tilepatch.bin
|
||||
COPYONLY
|
||||
)
|
||||
configure_file(../res/gamecontrollerdb.txt ./res/gamecontrollerdb.txt
|
||||
COPYONLY
|
||||
)
|
||||
@@ -1,21 +0,0 @@
|
||||
# Default CMake Setup. Used for Debian Builds.
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL
|
||||
SDLmain
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_DOUBLEBUF | SDL_SWSURFACE")
|
||||
@@ -1,62 +0,0 @@
|
||||
# Default CMake Setup. Used for Win32 Builds.
|
||||
# Uses OpenGL for Graphics.
|
||||
# For DirectX, assumes DXSDK is already configured and pointing to your DirectX setup.
|
||||
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl_root ${lib_base}/SDL-1.2.15)
|
||||
|
||||
if (NOT DEFINED ENV{DXSDK})
|
||||
message(FATAL_ERROR "Warning: DirectX SDK Variable DXSDK Not Defined!")
|
||||
endif()
|
||||
|
||||
# Use OpenGL for rendering.
|
||||
set(OPENGL 1)
|
||||
|
||||
# Use CannonBoard Serial Support
|
||||
set(CANNONBOARD 0)
|
||||
|
||||
include_directories(
|
||||
"${sdl_root}/include"
|
||||
)
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL
|
||||
SDLmain
|
||||
opengl32 # For OpenGL
|
||||
glu32 # For OpenGL
|
||||
dxguid # Direct X Haptic Support
|
||||
dinput8 # Direct X Haptic Support
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"$ENV{DXSDK}/lib"
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
if (CANNONBOARD)
|
||||
# Search for additional boost libraries needed for CannonBoard support: Threading & System
|
||||
set(BOOST_INCLUDEDIR ${lib_base}/boost_1_54_0)
|
||||
find_package(Boost COMPONENTS thread system REQUIRED)
|
||||
|
||||
link_libraries(cannonball
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
${Boost_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
# Windows 32 C++ Flags for Serial Port Support
|
||||
add_definitions(-D_WIN32_WINNT=0x0501)
|
||||
|
||||
# This will tell the Boost config system not to automatically select which libraries to link against.
|
||||
add_definitions(-DBOOST_ALL_NO_LIB)
|
||||
endif()
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
|
||||
# SDL Software Rendering Flags (ignored if OpenGL used)
|
||||
set(sdl_flags "SDL_SWSURFACE | SDL_DOUBLEBUF")
|
||||
@@ -0,0 +1,11 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
# CannonBall Linux Setup
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Use OpenGL for rendering.
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
# Platform Specific Libraries
|
||||
set(platform_link_libs
|
||||
${OPENGL_LIBRARIES}
|
||||
)
|
||||
@@ -1,39 +0,0 @@
|
||||
# Default CMake Setup. Used for Mac OS x builds
|
||||
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
|
||||
message( STATUS "Architecture: ${ARCHITECTURE}" )
|
||||
|
||||
# For INTeL 32bit Mac OS X 10.5+
|
||||
set(CMAKE_CXX_FLAGS " -O2 -force_cpusubtype_ALL -arch ${ARCHITECTURE} -m32 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.7")
|
||||
|
||||
# # For PowerPC 32bit Mac OS X 10.5+
|
||||
# set(CMAKE_CXX_FLAGS " -std=c++11 -stdlib=libstdc++ -O2 -faltivec -force_cpusubtype_ALL -mmacosx-version-min=10.5 -arch ppc -m32 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7")
|
||||
|
||||
# Use OpenGL for rendering
|
||||
set(OPENGL 1)
|
||||
|
||||
find_package(SDL REQUIRED)
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
include_directories(${SDL_INCLUDE_DIR} "${lib_base}/include/" "~/Library/Frameworks/SDL.framework/Headers" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/X11/include/" ${Boost_INCLUDE_DIRS})
|
||||
|
||||
find_library(COCOA_LIBRARY Cocoa)
|
||||
find_library(GLUT_LIBRARY GLUT )
|
||||
find_library(OpenGL_LIBRARY OpenGL )
|
||||
|
||||
link_libraries(cannonball
|
||||
${SDL_LIBRARY}
|
||||
${COCOA_LIBRARY}
|
||||
${GLUT_LIBRARY}
|
||||
${OpenGL_LIBRARY}
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_DOUBLEBUF | SDL_SWSURFACE")
|
||||
@@ -1,42 +0,0 @@
|
||||
# MinGW Compiler
|
||||
# You can use the MAME Toolchain, but copy the 'i686-w64-mingw32' subdirectory over the main MinGW directory.
|
||||
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl_root ${lib_base}/SDL-1.2.15)
|
||||
set(SDL_INCLUDE_DIR ${lib_base}/SDL-1.2.15/include)
|
||||
|
||||
if (NOT DEFINED ENV{DXSDK})
|
||||
message(FATAL_ERROR "Warning: DirectX SDK Variable DXSDK Not Defined!")
|
||||
endif()
|
||||
|
||||
find_package(SDL REQUIRED)
|
||||
|
||||
# Use OpenGL for rendering.
|
||||
set(OPENGL 1)
|
||||
|
||||
# Use CannonBoard Serial Support (Not yet tested on MINGW build)
|
||||
set(CANNONBOARD 0)
|
||||
|
||||
include_directories(
|
||||
"${SDL_INCLUDE_DIR}"
|
||||
# You may need to remove the next line based on your DirectX setup
|
||||
"$ENV{DXSDK}/include"
|
||||
)
|
||||
|
||||
link_libraries(cannonball
|
||||
${SDL_LIBRARY}
|
||||
SDLmain
|
||||
opengl32 # For OpenGL
|
||||
glu32 # For OpenGL
|
||||
dxguid
|
||||
dinput8
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Ofast -static-libgcc -static-libstdc++")
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
|
||||
# SDL Software Rendering Flags (ignored if OpenGL used)
|
||||
set(sdl_flags "SDL_SWSURFACE | SDL_DOUBLEBUF")
|
||||
@@ -1,22 +0,0 @@
|
||||
# Default CMake Setup. Used for Pandora Builds.
|
||||
|
||||
set(lib_base /mnt/utmp/codeblocks/usr)
|
||||
set(sdl_root ${lib_base}/include/SDL)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-DPANDORA)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory home/)
|
||||
set(sdl_flags "SDL_HWSURFACE")
|
||||
@@ -0,0 +1,36 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
# CannonBall Raspberry Pi4 (Smarty Hardware)
|
||||
#
|
||||
# I am using Visual Studio 2019 and cross-compiling on a PC with VisualGDB
|
||||
# (https://visualgdb.com/)
|
||||
#
|
||||
# This works well in terms of being able to use the Visual Studio debugger,
|
||||
# but if your environment is different, you may need a different cmake file.
|
||||
#
|
||||
# I referred to the following tutorial:
|
||||
# https://gnutoolchains.com/raspberry/tutorial/
|
||||
#
|
||||
# I downloaded the 2019-07-10 raspbian-buster-full executable from here:
|
||||
# https://gnutoolchains.com/raspberry/
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Library Locations
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl2_dir ${lib_base}/SDL2-2.0.12)
|
||||
|
||||
# Use OpenGLES for rendering.
|
||||
set(OPENGLES 1)
|
||||
|
||||
# GCC Specific flags (optimize for Pi4 CPU)
|
||||
set(CMAKE_CXX_FLAGS "-O3 -mtune=cortex-a72")
|
||||
|
||||
# Platform Specific Libraries
|
||||
set(platform_link_libs
|
||||
SDL2
|
||||
GLESv2
|
||||
)
|
||||
|
||||
# Platform Specific Link Directories
|
||||
set(platform_link_dirs
|
||||
|
||||
)
|
||||
@@ -1,25 +0,0 @@
|
||||
# CMake setup used for SDL2 Builds.
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL2)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL2
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-O3 -DSDL2)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_WINDOW_RESIZABLE")
|
||||
|
||||
# Set SDL2 instead of SDL1
|
||||
set(SDL2 1)
|
||||
@@ -1,25 +0,0 @@
|
||||
# CMake setup used for SDL2 Builds on Raspberry Pi.
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL2)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL2
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-O3 -DSDL2 -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_WINDOW_RESIZABLE")
|
||||
|
||||
# Set SDL2 instead of SDL1
|
||||
set(SDL2 1)
|
||||
@@ -1,28 +0,0 @@
|
||||
# CMake setup used for SDL2 Builds.
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL2)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL2
|
||||
GL
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-O3 -DSDL2 -DWITH_OPENGL)
|
||||
#add_definitions(-O0 -ggdb -DSDL2 -DWITH_OPENGL)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_WINDOW_RESIZABLE")
|
||||
|
||||
# Set SDL2 instead of SDL1
|
||||
set(SDL2 1)
|
||||
set(OPENGL 1)
|
||||
@@ -1,28 +0,0 @@
|
||||
# CMake setup used for SDL2 Builds.
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL2)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL2
|
||||
GLESv2
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-O3 -DSDL2 -DWITH_OPENGLES)
|
||||
#add_definitions(-O0 -ggdb -DSDL2 -DWITH_OPENGLES)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_WINDOW_RESIZABLE")
|
||||
|
||||
# Set SDL2 instead of SDL1
|
||||
set(SDL2 1)
|
||||
set(OPENGLES 1)
|
||||
@@ -1,30 +0,0 @@
|
||||
# CMake setup used for SDL2/GLES builds on Raspberry Pi
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-I/opt/vc/include -L/opt/vc/lib")
|
||||
|
||||
set(lib_base /usr/include)
|
||||
set(sdl_root ${lib_base}/SDL2)
|
||||
|
||||
include_directories("${sdl_root}")
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL2
|
||||
brcmGLESv2
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
add_definitions(-O3 -DSDL2 -DWITH_OPENGLES -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard)
|
||||
#add_definitions(-O0 -ggdb -DSDL2 -DWITH_OPENGLES)
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
set(sdl_flags "SDL_WINDOW_RESIZABLE")
|
||||
|
||||
# Set SDL2 instead of SDL1
|
||||
set(SDL2 1)
|
||||
set(OPENGLES 1)
|
||||
@@ -1,72 +0,0 @@
|
||||
# Default CMake Setup. Used for Win32 Builds.
|
||||
# Uses OpenGL for Graphics.
|
||||
# For DirectX, assumes DXSDK is already configured and pointing to your DirectX setup.
|
||||
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl_root ${lib_base}/SDL-1.2.15)
|
||||
|
||||
if (NOT DEFINED ENV{DXSDK})
|
||||
message(FATAL_ERROR "Warning: DirectX SDK Variable DXSDK Not Defined!")
|
||||
endif()
|
||||
|
||||
# Use OpenGL for rendering.
|
||||
set(OPENGL 0)
|
||||
|
||||
# Use CannonBoard Serial Support
|
||||
set(CANNONBOARD 1)
|
||||
|
||||
#foreach(flag_var
|
||||
#CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
#CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
#if(${flag_var} MATCHES "/MD")
|
||||
#string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
||||
#endif(${flag_var} MATCHES "/MD")
|
||||
#endforeach(flag_var)
|
||||
|
||||
include_directories(
|
||||
"${sdl_root}/include"
|
||||
)
|
||||
|
||||
link_libraries(cannonball
|
||||
SDL
|
||||
SDLmain
|
||||
opengl32 # For OpenGL
|
||||
glu32 # For OpenGL
|
||||
dxguid # Direct X Haptic Support
|
||||
dinput8 # Direct X Haptic Support
|
||||
)
|
||||
|
||||
# Linking
|
||||
link_directories(
|
||||
"$ENV{DXSDK}/lib"
|
||||
"${sdl_root}/lib"
|
||||
)
|
||||
|
||||
if (CANNONBOARD)
|
||||
set(Boost_USE_STATIC_LIBS OFF)
|
||||
|
||||
# Search for additional boost libraries needed for CannonBoard support: Threading & System
|
||||
set(BOOST_INCLUDEDIR ${lib_base}/boost_1_54_0)
|
||||
find_package(Boost COMPONENTS thread system REQUIRED)
|
||||
|
||||
link_libraries(cannonball
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
${Boost_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
# Windows 32 C++ Flags for Serial Port Support
|
||||
add_definitions(-D_WIN32_WINNT=0x0501)
|
||||
|
||||
# This will tell the Boost config system not to automatically select which libraries to link against.
|
||||
add_definitions(-DBOOST_ALL_NO_LIB)
|
||||
endif()
|
||||
|
||||
# Location for Cannonball to create save files
|
||||
# Used to auto-generate setup.hpp with various file paths
|
||||
set(xml_directory ./)
|
||||
|
||||
# SDL Software Rendering Flags (ignored if OpenGL used)
|
||||
set(sdl_flags "SDL_SWSURFACE | SDL_DOUBLEBUF")
|
||||
@@ -0,0 +1,11 @@
|
||||
SET(CMAKE_SYSTEM_NAME Linux)
|
||||
SET(VISUALGDB_TOOLCHAIN_TYPE Linux)
|
||||
SET(VISUALGDB_TOOLCHAIN_SUBTYPE GCC)
|
||||
SET(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT}/bin/arm-linux-gnueabihf-gcc.exe")
|
||||
SET(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT}/bin/arm-linux-gnueabihf-g++.exe")
|
||||
SET(CMAKE_ASM_COMPILER "${TOOLCHAIN_ROOT}/bin/arm-linux-gnueabihf-g++.exe")
|
||||
SET(CMAKE_SYSROOT "$ENV{TOOLCHAIN_ROOT}/arm-linux-gnueabihf/sysroot")
|
||||
|
||||
if(EXISTS "$ENV{TOOLCHAIN_ROOT}/Qt/v5-CMake/Qt5Cross.cmake")
|
||||
include("$ENV{TOOLCHAIN_ROOT}/Qt/v5-CMake/Qt5Cross.cmake")
|
||||
endif()
|
||||
@@ -0,0 +1,24 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
# CannonBall Windows Setup
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Library Locations
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl2_dir ${lib_base}/SDL2-2.0.12)
|
||||
set(dx8_dir c:/dxsdk)
|
||||
|
||||
# Use OpenGL for rendering.
|
||||
set(OPENGL 1)
|
||||
|
||||
# Platform Specific Libraries
|
||||
set(platform_link_libs
|
||||
opengl32 # For OpenGL
|
||||
glu32 # For OpenGL
|
||||
dxguid # Direct X Haptic Support
|
||||
dinput8 # Direct X Haptic Support
|
||||
)
|
||||
|
||||
# Platform Specific Link Directories
|
||||
set(platform_link_dirs
|
||||
"${dx8_dir}/lib"
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
# CannonBall Windows Setup
|
||||
#
|
||||
# Extra libraries are required to use OpenGLES on Windows.
|
||||
# Quite a long install process.
|
||||
# Download & Compile Angle: https://opensource.google/projects/angle
|
||||
#
|
||||
# Other notes:
|
||||
# http://mickcharlesbeaver.blogspot.com/2017/11/using-opengl-es-20-with-sdl2-via-angle.html
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Library Locations
|
||||
set(lib_base c:/coding/lib)
|
||||
set(sdl2_dir ${lib_base}/SDL2-2.0.12)
|
||||
set(angle_dir ${lib_base}/angle/out/Debug)
|
||||
set(dx8_dir c:/dxsdk)
|
||||
|
||||
# Use OpenGLES for rendering.
|
||||
set(OPENGLES 1)
|
||||
|
||||
# Platform Specific Libraries
|
||||
set(platform_link_libs
|
||||
"${angle_dir}/libEGL.dll.lib"
|
||||
"${angle_dir}/libGLESv2.dll.lib"
|
||||
dxguid # Direct X Haptic Support
|
||||
dinput8 # Direct X Haptic Support
|
||||
)
|
||||
|
||||
# Platform Specific Link Directories
|
||||
set(platform_link_dirs
|
||||
"${dx8_dir}/lib"
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
|
||||
|
||||
# Support both 32 and 64 bit builds
|
||||
if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2main.lib")
|
||||
else ()
|
||||
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2main.lib")
|
||||
endif ()
|
||||
|
||||
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
|
||||
-199
@@ -1,199 +0,0 @@
|
||||
// Boost string_algo library compare.hpp header file -------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2006.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_COMPARE_HPP
|
||||
#define BOOST_STRING_COMPARE_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <locale>
|
||||
|
||||
/*! \file
|
||||
Defines element comparison predicates. Many algorithms in this library can
|
||||
take an additional argument with a predicate used to compare elements.
|
||||
This makes it possible, for instance, to have case insensitive versions
|
||||
of the algorithms.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
// is_equal functor -----------------------------------------------//
|
||||
|
||||
//! is_equal functor
|
||||
/*!
|
||||
Standard STL equal_to only handle comparison between arguments
|
||||
of the same type. This is a less restrictive version which wraps operator ==.
|
||||
*/
|
||||
struct is_equal
|
||||
{
|
||||
//! Function operator
|
||||
/*!
|
||||
Compare two operands for equality
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
return Arg1==Arg2;
|
||||
}
|
||||
};
|
||||
|
||||
//! case insensitive version of is_equal
|
||||
/*!
|
||||
Case insensitive comparison predicate. Comparison is done using
|
||||
specified locales.
|
||||
*/
|
||||
struct is_iequal
|
||||
{
|
||||
//! Constructor
|
||||
/*!
|
||||
\param Loc locales used for comparison
|
||||
*/
|
||||
is_iequal( const std::locale& Loc=std::locale() ) :
|
||||
m_Loc( Loc ) {}
|
||||
|
||||
//! Function operator
|
||||
/*!
|
||||
Compare two operands. Case is ignored.
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) || defined(__PSL1GHT__) || defined(__PS3__)
|
||||
return std::toupper(Arg1)==std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
std::locale m_Loc;
|
||||
};
|
||||
|
||||
// is_less functor -----------------------------------------------//
|
||||
|
||||
//! is_less functor
|
||||
/*!
|
||||
Convenient version of standard std::less. Operation is templated, therefore it is
|
||||
not required to specify the exact types upon the construction
|
||||
*/
|
||||
struct is_less
|
||||
{
|
||||
//! Functor operation
|
||||
/*!
|
||||
Compare two operands using > operator
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
return Arg1<Arg2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! case insensitive version of is_less
|
||||
/*!
|
||||
Case insensitive comparison predicate. Comparison is done using
|
||||
specified locales.
|
||||
*/
|
||||
struct is_iless
|
||||
{
|
||||
//! Constructor
|
||||
/*!
|
||||
\param Loc locales used for comparison
|
||||
*/
|
||||
is_iless( const std::locale& Loc=std::locale() ) :
|
||||
m_Loc( Loc ) {}
|
||||
|
||||
//! Function operator
|
||||
/*!
|
||||
Compare two operands. Case is ignored.
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) || defined(__PSL1GHT__) || defined(__PS3__)
|
||||
return std::toupper(Arg1)<std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
std::locale m_Loc;
|
||||
};
|
||||
|
||||
// is_not_greater functor -----------------------------------------------//
|
||||
|
||||
//! is_not_greater functor
|
||||
/*!
|
||||
Convenient version of standard std::not_greater_to. Operation is templated, therefore it is
|
||||
not required to specify the exact types upon the construction
|
||||
*/
|
||||
struct is_not_greater
|
||||
{
|
||||
//! Functor operation
|
||||
/*!
|
||||
Compare two operands using > operator
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
return Arg1<=Arg2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! case insensitive version of is_not_greater
|
||||
/*!
|
||||
Case insensitive comparison predicate. Comparison is done using
|
||||
specified locales.
|
||||
*/
|
||||
struct is_not_igreater
|
||||
{
|
||||
//! Constructor
|
||||
/*!
|
||||
\param Loc locales used for comparison
|
||||
*/
|
||||
is_not_igreater( const std::locale& Loc=std::locale() ) :
|
||||
m_Loc( Loc ) {}
|
||||
|
||||
//! Function operator
|
||||
/*!
|
||||
Compare two operands. Case is ignored.
|
||||
*/
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) || defined(__PSL1GHT__) || defined(__PS3__)
|
||||
return std::toupper(Arg1)<=std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)<=std::toupper<T2>(Arg2,m_Loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
std::locale m_Loc;
|
||||
};
|
||||
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull names to the boost namespace
|
||||
using algorithm::is_equal;
|
||||
using algorithm::is_iequal;
|
||||
using algorithm::is_less;
|
||||
using algorithm::is_iless;
|
||||
using algorithm::is_not_greater;
|
||||
using algorithm::is_not_igreater;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_COMPARE_HPP
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
// Boost string_algo library config.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_CONFIG_HPP
|
||||
#define BOOST_STRING_CONFIG_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#ifdef BOOST_STRING_DEDUCED_TYPENAME
|
||||
# error "macro already defined!"
|
||||
#endif
|
||||
|
||||
#define BOOST_STRING_TYPENAME BOOST_DEDUCED_TYPENAME
|
||||
|
||||
// Metrowerks workaround
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
#pragma parse_func_templ off
|
||||
#endif
|
||||
|
||||
#endif // BOOST_STRING_CONFIG_HPP
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
// Boost string_algo library constants.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_CONSTANTS_HPP
|
||||
#define BOOST_STRING_CONSTANTS_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
//! Token compression mode
|
||||
/*!
|
||||
Specifies token compression mode for the token_finder.
|
||||
*/
|
||||
enum token_compress_mode_type
|
||||
{
|
||||
token_compress_on, //!< Compress adjacent tokens
|
||||
token_compress_off //!< Do not compress adjacent tokens
|
||||
};
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull the names to the boost namespace
|
||||
using algorithm::token_compress_on;
|
||||
using algorithm::token_compress_off;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_STRING_CONSTANTS_HPP
|
||||
|
||||
-639
@@ -1,639 +0,0 @@
|
||||
// Boost string_algo library finder.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2006.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_FINDER_DETAIL_HPP
|
||||
#define BOOST_STRING_FINDER_DETAIL_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/algorithm/string/constants.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/empty.hpp>
|
||||
#include <boost/range/as_literal.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
namespace detail {
|
||||
|
||||
|
||||
// find first functor -----------------------------------------------//
|
||||
|
||||
// find a subsequence in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, functor returns <End,End>
|
||||
*/
|
||||
template<typename SearchIteratorT,typename PredicateT>
|
||||
struct first_finderF
|
||||
{
|
||||
typedef SearchIteratorT search_iterator_type;
|
||||
|
||||
// Construction
|
||||
template< typename SearchT >
|
||||
first_finderF( const SearchT& Search, PredicateT Comp ) :
|
||||
m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {}
|
||||
first_finderF(
|
||||
search_iterator_type SearchBegin,
|
||||
search_iterator_type SearchEnd,
|
||||
PredicateT Comp ) :
|
||||
m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
|
||||
// Outer loop
|
||||
for(input_iterator_type OuterIt=Begin;
|
||||
OuterIt!=End;
|
||||
++OuterIt)
|
||||
{
|
||||
// Sanity check
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
input_iterator_type InnerIt=OuterIt;
|
||||
search_iterator_type SubstrIt=m_Search.begin();
|
||||
for(;
|
||||
InnerIt!=End && SubstrIt!=m_Search.end();
|
||||
++InnerIt,++SubstrIt)
|
||||
{
|
||||
if( !( m_Comp(*InnerIt,*SubstrIt) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
// Substring matching succeeded
|
||||
if ( SubstrIt==m_Search.end() )
|
||||
return result_type( OuterIt, InnerIt );
|
||||
}
|
||||
|
||||
return result_type( End, End );
|
||||
}
|
||||
|
||||
private:
|
||||
iterator_range<search_iterator_type> m_Search;
|
||||
PredicateT m_Comp;
|
||||
};
|
||||
|
||||
// find last functor -----------------------------------------------//
|
||||
|
||||
// find the last match a subsequence in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, returns <End,End>
|
||||
*/
|
||||
template<typename SearchIteratorT, typename PredicateT>
|
||||
struct last_finderF
|
||||
{
|
||||
typedef SearchIteratorT search_iterator_type;
|
||||
typedef first_finderF<
|
||||
search_iterator_type,
|
||||
PredicateT> first_finder_type;
|
||||
|
||||
// Construction
|
||||
template< typename SearchT >
|
||||
last_finderF( const SearchT& Search, PredicateT Comp ) :
|
||||
m_Search(::boost::begin(Search), ::boost::end(Search)), m_Comp(Comp) {}
|
||||
last_finderF(
|
||||
search_iterator_type SearchBegin,
|
||||
search_iterator_type SearchEnd,
|
||||
PredicateT Comp ) :
|
||||
m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return findit( Begin, End, category() );
|
||||
}
|
||||
|
||||
private:
|
||||
// forward iterator
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::forward_iterator_tag ) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
first_finder_type first_finder(
|
||||
m_Search.begin(), m_Search.end(), m_Comp );
|
||||
|
||||
result_type M=first_finder( Begin, End );
|
||||
result_type Last=M;
|
||||
|
||||
while( M )
|
||||
{
|
||||
Last=M;
|
||||
M=first_finder( ::boost::end(M), End );
|
||||
}
|
||||
|
||||
return Last;
|
||||
}
|
||||
|
||||
// bidirectional iterator
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::bidirectional_iterator_tag ) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
|
||||
// Outer loop
|
||||
for(input_iterator_type OuterIt=End;
|
||||
OuterIt!=Begin; )
|
||||
{
|
||||
input_iterator_type OuterIt2=--OuterIt;
|
||||
|
||||
input_iterator_type InnerIt=OuterIt2;
|
||||
search_iterator_type SubstrIt=m_Search.begin();
|
||||
for(;
|
||||
InnerIt!=End && SubstrIt!=m_Search.end();
|
||||
++InnerIt,++SubstrIt)
|
||||
{
|
||||
if( !( m_Comp(*InnerIt,*SubstrIt) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
// Substring matching succeeded
|
||||
if( SubstrIt==m_Search.end() )
|
||||
return result_type( OuterIt2, InnerIt );
|
||||
}
|
||||
|
||||
return result_type( End, End );
|
||||
}
|
||||
|
||||
private:
|
||||
iterator_range<search_iterator_type> m_Search;
|
||||
PredicateT m_Comp;
|
||||
};
|
||||
|
||||
// find n-th functor -----------------------------------------------//
|
||||
|
||||
// find the n-th match of a subsequence in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, returns <End,End>
|
||||
*/
|
||||
template<typename SearchIteratorT, typename PredicateT>
|
||||
struct nth_finderF
|
||||
{
|
||||
typedef SearchIteratorT search_iterator_type;
|
||||
typedef first_finderF<
|
||||
search_iterator_type,
|
||||
PredicateT> first_finder_type;
|
||||
typedef last_finderF<
|
||||
search_iterator_type,
|
||||
PredicateT> last_finder_type;
|
||||
|
||||
// Construction
|
||||
template< typename SearchT >
|
||||
nth_finderF(
|
||||
const SearchT& Search,
|
||||
int Nth,
|
||||
PredicateT Comp) :
|
||||
m_Search(::boost::begin(Search), ::boost::end(Search)),
|
||||
m_Nth(Nth),
|
||||
m_Comp(Comp) {}
|
||||
nth_finderF(
|
||||
search_iterator_type SearchBegin,
|
||||
search_iterator_type SearchEnd,
|
||||
int Nth,
|
||||
PredicateT Comp) :
|
||||
m_Search(SearchBegin, SearchEnd),
|
||||
m_Nth(Nth),
|
||||
m_Comp(Comp) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
if(m_Nth>=0)
|
||||
{
|
||||
return find_forward(Begin, End, m_Nth);
|
||||
}
|
||||
else
|
||||
{
|
||||
return find_backward(Begin, End, -m_Nth);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
// Implementation helpers
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_forward(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
// Sanity check
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
// Instantiate find functor
|
||||
first_finder_type first_finder(
|
||||
m_Search.begin(), m_Search.end(), m_Comp );
|
||||
|
||||
result_type M( Begin, Begin );
|
||||
|
||||
for( unsigned int n=0; n<=N; ++n )
|
||||
{
|
||||
// find next match
|
||||
M=first_finder( ::boost::end(M), End );
|
||||
|
||||
if ( !M )
|
||||
{
|
||||
// Subsequence not found, return
|
||||
return M;
|
||||
}
|
||||
}
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_backward(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
// Sanity check
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
// Instantiate find functor
|
||||
last_finder_type last_finder(
|
||||
m_Search.begin(), m_Search.end(), m_Comp );
|
||||
|
||||
result_type M( End, End );
|
||||
|
||||
for( unsigned int n=1; n<=N; ++n )
|
||||
{
|
||||
// find next match
|
||||
M=last_finder( Begin, ::boost::begin(M) );
|
||||
|
||||
if ( !M )
|
||||
{
|
||||
// Subsequence not found, return
|
||||
return M;
|
||||
}
|
||||
}
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
iterator_range<search_iterator_type> m_Search;
|
||||
int m_Nth;
|
||||
PredicateT m_Comp;
|
||||
};
|
||||
|
||||
// find head/tail implementation helpers ---------------------------//
|
||||
|
||||
template<typename ForwardIteratorT>
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::forward_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=Begin;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=End; ++Index,++It ) {};
|
||||
|
||||
return result_type( Begin, It );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::random_access_iterator_tag )
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type(Begin,Begin+N);
|
||||
}
|
||||
|
||||
// Find head implementation
|
||||
template<typename ForwardIteratorT>
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return ::boost::algorithm::detail::find_head_impl( Begin, End, N, category() );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::forward_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
unsigned int Index=0;
|
||||
input_iterator_type It=Begin;
|
||||
input_iterator_type It2=Begin;
|
||||
|
||||
// Advance It2 by N increments
|
||||
for( Index=0; Index<N && It2!=End; ++Index,++It2 ) {};
|
||||
|
||||
// Advance It, It2 to the end
|
||||
for(; It2!=End; ++It,++It2 ) {};
|
||||
|
||||
return result_type( It, It2 );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::bidirectional_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=End;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=Begin; ++Index,--It ) {};
|
||||
|
||||
return result_type( It, End );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::random_access_iterator_tag )
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type( End-N, End );
|
||||
}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return ::boost::algorithm::detail::find_tail_impl( Begin, End, N, category() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// find head functor -----------------------------------------------//
|
||||
|
||||
|
||||
// find a head in the sequence ( functor )
|
||||
/*
|
||||
This functor find a head of the specified range. For
|
||||
a specified N, the head is a subsequence of N starting
|
||||
elements of the range.
|
||||
*/
|
||||
struct head_finderF
|
||||
{
|
||||
// Construction
|
||||
head_finderF( int N ) : m_N(N) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
if(m_N>=0)
|
||||
{
|
||||
return ::boost::algorithm::detail::find_head_impl( Begin, End, m_N );
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_range<ForwardIteratorT> Res=
|
||||
::boost::algorithm::detail::find_tail_impl( Begin, End, -m_N );
|
||||
|
||||
return ::boost::make_iterator_range(Begin, Res.begin());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int m_N;
|
||||
};
|
||||
|
||||
// find tail functor -----------------------------------------------//
|
||||
|
||||
|
||||
// find a tail in the sequence ( functor )
|
||||
/*
|
||||
This functor find a tail of the specified range. For
|
||||
a specified N, the head is a subsequence of N starting
|
||||
elements of the range.
|
||||
*/
|
||||
struct tail_finderF
|
||||
{
|
||||
// Construction
|
||||
tail_finderF( int N ) : m_N(N) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
if(m_N>=0)
|
||||
{
|
||||
return ::boost::algorithm::detail::find_tail_impl( Begin, End, m_N );
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_range<ForwardIteratorT> Res=
|
||||
::boost::algorithm::detail::find_head_impl( Begin, End, -m_N );
|
||||
|
||||
return ::boost::make_iterator_range(Res.end(), End);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int m_N;
|
||||
};
|
||||
|
||||
// find token functor -----------------------------------------------//
|
||||
|
||||
// find a token in a sequence ( functor )
|
||||
/*
|
||||
This find functor finds a token specified be a predicate
|
||||
in a sequence. It is equivalent of std::find algorithm,
|
||||
with an exception that it return range instead of a single
|
||||
iterator.
|
||||
|
||||
If bCompress is set to true, adjacent matching tokens are
|
||||
concatenated into one match.
|
||||
*/
|
||||
template< typename PredicateT >
|
||||
struct token_finderF
|
||||
{
|
||||
// Construction
|
||||
token_finderF(
|
||||
PredicateT Pred,
|
||||
token_compress_mode_type eCompress=token_compress_off ) :
|
||||
m_Pred(Pred), m_eCompress(eCompress) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
ForwardIteratorT It=std::find_if( Begin, End, m_Pred );
|
||||
|
||||
if( It==End )
|
||||
{
|
||||
return result_type( End, End );
|
||||
}
|
||||
else
|
||||
{
|
||||
ForwardIteratorT It2=It;
|
||||
|
||||
if( m_eCompress==token_compress_on )
|
||||
{
|
||||
// Find first non-matching character
|
||||
while( It2!=End && m_Pred(*It2) ) ++It2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Advance by one position
|
||||
++It2;
|
||||
}
|
||||
|
||||
return result_type( It, It2 );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
PredicateT m_Pred;
|
||||
token_compress_mode_type m_eCompress;
|
||||
};
|
||||
|
||||
// find range functor -----------------------------------------------//
|
||||
|
||||
// find a range in the sequence ( functor )
|
||||
/*
|
||||
This functor actually does not perform any find operation.
|
||||
It always returns given iterator range as a result.
|
||||
*/
|
||||
template<typename ForwardIterator1T>
|
||||
struct range_finderF
|
||||
{
|
||||
typedef ForwardIterator1T input_iterator_type;
|
||||
typedef iterator_range<input_iterator_type> result_type;
|
||||
|
||||
// Construction
|
||||
range_finderF(
|
||||
input_iterator_type Begin,
|
||||
input_iterator_type End ) : m_Range(Begin, End) {}
|
||||
|
||||
range_finderF(const iterator_range<input_iterator_type>& Range) :
|
||||
m_Range(Range) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIterator2T >
|
||||
iterator_range<ForwardIterator2T>
|
||||
operator()(
|
||||
ForwardIterator2T,
|
||||
ForwardIterator2T ) const
|
||||
{
|
||||
#if BOOST_WORKAROUND( __MWERKS__, <= 0x3003 )
|
||||
return iterator_range<const ForwardIterator2T>(this->m_Range);
|
||||
#else
|
||||
return m_Range;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
iterator_range<input_iterator_type> m_Range;
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
} // namespace algorithm
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_STRING_FINDER_DETAIL_HPP
|
||||
@@ -1,77 +0,0 @@
|
||||
// Boost string_algo library predicate.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_PREDICATE_DETAIL_HPP
|
||||
#define BOOST_STRING_PREDICATE_DETAIL_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
namespace detail {
|
||||
|
||||
// ends_with predicate implementation ----------------------------------//
|
||||
|
||||
template<
|
||||
typename ForwardIterator1T,
|
||||
typename ForwardIterator2T,
|
||||
typename PredicateT>
|
||||
inline bool ends_with_iter_select(
|
||||
ForwardIterator1T Begin,
|
||||
ForwardIterator1T End,
|
||||
ForwardIterator2T SubBegin,
|
||||
ForwardIterator2T SubEnd,
|
||||
PredicateT Comp,
|
||||
std::bidirectional_iterator_tag)
|
||||
{
|
||||
ForwardIterator1T it=End;
|
||||
ForwardIterator2T pit=SubEnd;
|
||||
for(;it!=Begin && pit!=SubBegin;)
|
||||
{
|
||||
if( !(Comp(*(--it),*(--pit))) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return pit==SubBegin;
|
||||
}
|
||||
|
||||
template<
|
||||
typename ForwardIterator1T,
|
||||
typename ForwardIterator2T,
|
||||
typename PredicateT>
|
||||
inline bool ends_with_iter_select(
|
||||
ForwardIterator1T Begin,
|
||||
ForwardIterator1T End,
|
||||
ForwardIterator2T SubBegin,
|
||||
ForwardIterator2T SubEnd,
|
||||
PredicateT Comp,
|
||||
std::forward_iterator_tag)
|
||||
{
|
||||
if ( SubBegin==SubEnd )
|
||||
{
|
||||
// empty subsequence check
|
||||
return true;
|
||||
}
|
||||
|
||||
iterator_range<ForwardIterator1T> Result
|
||||
=last_finder(
|
||||
::boost::make_iterator_range(SubBegin, SubEnd),
|
||||
Comp)(Begin, End);
|
||||
|
||||
return !Result.empty() && Result.end()==End;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace algorithm
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_PREDICATE_DETAIL_HPP
|
||||
Vendored
-334
@@ -1,334 +0,0 @@
|
||||
// Boost string_algo library find.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_FIND_HPP
|
||||
#define BOOST_STRING_FIND_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/as_literal.hpp>
|
||||
|
||||
#include <boost/algorithm/string/finder.hpp>
|
||||
#include <boost/algorithm/string/compare.hpp>
|
||||
#include <boost/algorithm/string/constants.hpp>
|
||||
|
||||
/*! \file
|
||||
Defines a set of find algorithms. The algorithms are searching
|
||||
for a substring of the input. The result is given as an \c iterator_range
|
||||
delimiting the substring.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
// Generic find -----------------------------------------------//
|
||||
|
||||
//! Generic find algorithm
|
||||
/*!
|
||||
Search the input using the given finder.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Finder Finder object used for searching.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c RangeT::iterator or
|
||||
\c RangeT::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
*/
|
||||
template<typename RangeT, typename FinderT>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
|
||||
find(
|
||||
RangeT& Input,
|
||||
const FinderT& Finder)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
|
||||
|
||||
return Finder(::boost::begin(lit_input),::boost::end(lit_input));
|
||||
}
|
||||
|
||||
// find_first -----------------------------------------------//
|
||||
|
||||
//! Find first algorithm
|
||||
/*!
|
||||
Search for the first occurrence of the substring in the input.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c RangeT::iterator or
|
||||
\c RangeT::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
find_first(
|
||||
Range1T& Input,
|
||||
const Range2T& Search)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search));
|
||||
}
|
||||
|
||||
//! Find first algorithm ( case insensitive )
|
||||
/*!
|
||||
Search for the first occurrence of the substring in the input.
|
||||
Searching is case insensitive.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
ifind_first(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search,is_iequal(Loc)));
|
||||
}
|
||||
|
||||
// find_last -----------------------------------------------//
|
||||
|
||||
//! Find last algorithm
|
||||
/*!
|
||||
Search for the last occurrence of the substring in the input.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
find_last(
|
||||
Range1T& Input,
|
||||
const Range2T& Search)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search));
|
||||
}
|
||||
|
||||
//! Find last algorithm ( case insensitive )
|
||||
/*!
|
||||
Search for the last match a string in the input.
|
||||
Searching is case insensitive.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
ifind_last(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search, is_iequal(Loc)));
|
||||
}
|
||||
|
||||
// find_nth ----------------------------------------------------------------------//
|
||||
|
||||
//! Find n-th algorithm
|
||||
/*!
|
||||
Search for the n-th (zero-indexed) occurrence of the substring in the
|
||||
input.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index (zero-indexed) of the match to be found.
|
||||
For negative N, the matches are counted from the end of string.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
find_nth(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
int Nth)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth));
|
||||
}
|
||||
|
||||
//! Find n-th algorithm ( case insensitive ).
|
||||
/*!
|
||||
Search for the n-th (zero-indexed) occurrence of the substring in the
|
||||
input. Searching is case insensitive.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index (zero-indexed) of the match to be found.
|
||||
For negative N, the matches are counted from the end of string.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
|
||||
ifind_nth(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
int Nth,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth,is_iequal(Loc)));
|
||||
}
|
||||
|
||||
// find_head ----------------------------------------------------------------------//
|
||||
|
||||
//! Find head algorithm
|
||||
/*!
|
||||
Get the head of the input. Head is a prefix of the string of the
|
||||
given size. If the input is shorter then required, whole input is considered
|
||||
to be the head.
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, at most size(Input)-|N| characters are extracted.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
\c Range1T::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename RangeT>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
|
||||
find_head(
|
||||
RangeT& Input,
|
||||
int N)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::head_finder(N));
|
||||
}
|
||||
|
||||
// find_tail ----------------------------------------------------------------------//
|
||||
|
||||
//! Find tail algorithm
|
||||
/*!
|
||||
Get the tail of the input. Tail is a suffix of the string of the
|
||||
given size. If the input is shorter then required, whole input is considered
|
||||
to be the tail.
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the tail.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, at most size(Input)-|N| characters are extracted.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c RangeT::iterator or
|
||||
\c RangeT::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename RangeT>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
|
||||
find_tail(
|
||||
RangeT& Input,
|
||||
int N)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::tail_finder(N));
|
||||
}
|
||||
|
||||
// find_token --------------------------------------------------------------------//
|
||||
|
||||
//! Find token algorithm
|
||||
/*!
|
||||
Look for a given token in the string. Token is a character that matches the
|
||||
given predicate.
|
||||
If the "token compress mode" is enabled, adjacent tokens are considered to be one match.
|
||||
|
||||
\param Input A input string.
|
||||
\param Pred A unary predicate to identify a token
|
||||
\param eCompress Enable/Disable compressing of adjacent tokens
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c RangeT::iterator or
|
||||
\c RangeT::const_iterator, depending on the constness of
|
||||
the input parameter.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename RangeT, typename PredicateT>
|
||||
inline iterator_range<
|
||||
BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
|
||||
find_token(
|
||||
RangeT& Input,
|
||||
PredicateT Pred,
|
||||
token_compress_mode_type eCompress=token_compress_off)
|
||||
{
|
||||
return ::boost::algorithm::find(Input, ::boost::algorithm::token_finder(Pred, eCompress));
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull names to the boost namespace
|
||||
using algorithm::find;
|
||||
using algorithm::find_first;
|
||||
using algorithm::ifind_first;
|
||||
using algorithm::find_last;
|
||||
using algorithm::ifind_last;
|
||||
using algorithm::find_nth;
|
||||
using algorithm::ifind_nth;
|
||||
using algorithm::find_head;
|
||||
using algorithm::find_tail;
|
||||
using algorithm::find_token;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_FIND_HPP
|
||||
-270
@@ -1,270 +0,0 @@
|
||||
// Boost string_algo library finder.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2006.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_FINDER_HPP
|
||||
#define BOOST_STRING_FINDER_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/const_iterator.hpp>
|
||||
|
||||
#include <boost/algorithm/string/constants.hpp>
|
||||
#include <boost/algorithm/string/detail/finder.hpp>
|
||||
#include <boost/algorithm/string/compare.hpp>
|
||||
|
||||
/*! \file
|
||||
Defines Finder generators. Finder object is a functor which is able to
|
||||
find a substring matching a specific criteria in the input.
|
||||
Finders are used as a pluggable components for replace, find
|
||||
and split facilities. This header contains generator functions
|
||||
for finders provided in this library.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
// Finder generators ------------------------------------------//
|
||||
|
||||
//! "First" finder
|
||||
/*!
|
||||
Construct the \c first_finder. The finder searches for the first
|
||||
occurrence of the string in a given input.
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c first_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
inline detail::first_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
is_equal>
|
||||
first_finder( const RangeT& Search )
|
||||
{
|
||||
return
|
||||
detail::first_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
is_equal>( ::boost::as_literal(Search), is_equal() ) ;
|
||||
}
|
||||
|
||||
//! "First" finder
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename RangeT,typename PredicateT>
|
||||
inline detail::first_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
PredicateT>
|
||||
first_finder(
|
||||
const RangeT& Search, PredicateT Comp )
|
||||
{
|
||||
return
|
||||
detail::first_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
PredicateT>( ::boost::as_literal(Search), Comp );
|
||||
}
|
||||
|
||||
//! "Last" finder
|
||||
/*!
|
||||
Construct the \c last_finder. The finder searches for the last
|
||||
occurrence of the string in a given input.
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c last_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
inline detail::last_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
is_equal>
|
||||
last_finder( const RangeT& Search )
|
||||
{
|
||||
return
|
||||
detail::last_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
is_equal>( ::boost::as_literal(Search), is_equal() );
|
||||
}
|
||||
//! "Last" finder
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename RangeT, typename PredicateT>
|
||||
inline detail::last_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
PredicateT>
|
||||
last_finder( const RangeT& Search, PredicateT Comp )
|
||||
{
|
||||
return
|
||||
detail::last_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
PredicateT>( ::boost::as_literal(Search), Comp ) ;
|
||||
}
|
||||
|
||||
//! "Nth" finder
|
||||
/*!
|
||||
Construct the \c nth_finder. The finder searches for the n-th (zero-indexed)
|
||||
occurrence of the string in a given input.
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index of the match to be find
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c nth_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
inline detail::nth_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
is_equal>
|
||||
nth_finder(
|
||||
const RangeT& Search,
|
||||
int Nth)
|
||||
{
|
||||
return
|
||||
detail::nth_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
is_equal>( ::boost::as_literal(Search), Nth, is_equal() ) ;
|
||||
}
|
||||
//! "Nth" finder
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename RangeT, typename PredicateT>
|
||||
inline detail::nth_finderF<
|
||||
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
|
||||
PredicateT>
|
||||
nth_finder(
|
||||
const RangeT& Search,
|
||||
int Nth,
|
||||
PredicateT Comp )
|
||||
{
|
||||
return
|
||||
detail::nth_finderF<
|
||||
BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type,
|
||||
PredicateT>( ::boost::as_literal(Search), Nth, Comp );
|
||||
}
|
||||
|
||||
//! "Head" finder
|
||||
/*!
|
||||
Construct the \c head_finder. The finder returns a head of a given
|
||||
input. The head is a prefix of a string up to n elements in
|
||||
size. If an input has less then n elements, whole input is
|
||||
considered a head.
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param N The size of the head
|
||||
\return An instance of the \c head_finder object
|
||||
*/
|
||||
inline detail::head_finderF
|
||||
head_finder( int N )
|
||||
{
|
||||
return detail::head_finderF(N);
|
||||
}
|
||||
|
||||
//! "Tail" finder
|
||||
/*!
|
||||
Construct the \c tail_finder. The finder returns a tail of a given
|
||||
input. The tail is a suffix of a string up to n elements in
|
||||
size. If an input has less then n elements, whole input is
|
||||
considered a head.
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param N The size of the head
|
||||
\return An instance of the \c tail_finder object
|
||||
*/
|
||||
inline detail::tail_finderF
|
||||
tail_finder( int N )
|
||||
{
|
||||
return detail::tail_finderF(N);
|
||||
}
|
||||
|
||||
//! "Token" finder
|
||||
/*!
|
||||
Construct the \c token_finder. The finder searches for a token
|
||||
specified by a predicate. It is similar to std::find_if
|
||||
algorithm, with an exception that it return a range of
|
||||
instead of a single iterator.
|
||||
|
||||
If "compress token mode" is enabled, adjacent matching tokens are
|
||||
concatenated into one match. Thus the finder can be used to
|
||||
search for continuous segments of characters satisfying the
|
||||
given predicate.
|
||||
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Pred An element selection predicate
|
||||
\param eCompress Compress flag
|
||||
\return An instance of the \c token_finder object
|
||||
*/
|
||||
template< typename PredicateT >
|
||||
inline detail::token_finderF<PredicateT>
|
||||
token_finder(
|
||||
PredicateT Pred,
|
||||
token_compress_mode_type eCompress=token_compress_off )
|
||||
{
|
||||
return detail::token_finderF<PredicateT>( Pred, eCompress );
|
||||
}
|
||||
|
||||
//! "Range" finder
|
||||
/*!
|
||||
Construct the \c range_finder. The finder does not perform
|
||||
any operation. It simply returns the given range for
|
||||
any input.
|
||||
|
||||
\param Begin Beginning of the range
|
||||
\param End End of the range
|
||||
\param Range The range.
|
||||
\return An instance of the \c range_finger object
|
||||
*/
|
||||
template< typename ForwardIteratorT >
|
||||
inline detail::range_finderF<ForwardIteratorT>
|
||||
range_finder(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End )
|
||||
{
|
||||
return detail::range_finderF<ForwardIteratorT>( Begin, End );
|
||||
}
|
||||
|
||||
//! "Range" finder
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template< typename ForwardIteratorT >
|
||||
inline detail::range_finderF<ForwardIteratorT>
|
||||
range_finder( iterator_range<ForwardIteratorT> Range )
|
||||
{
|
||||
return detail::range_finderF<ForwardIteratorT>( Range );
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull the names to the boost namespace
|
||||
using algorithm::first_finder;
|
||||
using algorithm::last_finder;
|
||||
using algorithm::nth_finder;
|
||||
using algorithm::head_finder;
|
||||
using algorithm::tail_finder;
|
||||
using algorithm::token_finder;
|
||||
using algorithm::range_finder;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_FINDER_HPP
|
||||
-475
@@ -1,475 +0,0 @@
|
||||
// Boost string_algo library predicate.hpp header file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003.
|
||||
//
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org/ for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_PREDICATE_HPP
|
||||
#define BOOST_STRING_PREDICATE_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/const_iterator.hpp>
|
||||
#include <boost/range/as_literal.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
|
||||
#include <boost/algorithm/string/compare.hpp>
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
#include <boost/algorithm/string/detail/predicate.hpp>
|
||||
|
||||
/*! \file boost/algorithm/string/predicate.hpp
|
||||
Defines string-related predicates.
|
||||
The predicates determine whether a substring is contained in the input string
|
||||
under various conditions: a string starts with the substring, ends with the
|
||||
substring, simply contains the substring or if both strings are equal.
|
||||
Additionaly the algorithm \c all() checks all elements of a container to satisfy a
|
||||
condition.
|
||||
|
||||
All predicates provide the strong exception guarantee.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
// starts_with predicate -----------------------------------------------//
|
||||
|
||||
//! 'Starts with' predicate
|
||||
/*!
|
||||
This predicate holds when the test string is a prefix of the Input.
|
||||
In other words, if the input starts with the test.
|
||||
When the optional predicate is specified, it is used for character-wise
|
||||
comparison.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Comp An element comparison predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T, typename PredicateT>
|
||||
inline bool starts_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
PredicateT Comp)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
|
||||
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range1T>::type Iterator1T;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range2T>::type Iterator2T;
|
||||
|
||||
Iterator1T InputEnd=::boost::end(lit_input);
|
||||
Iterator2T TestEnd=::boost::end(lit_test);
|
||||
|
||||
Iterator1T it=::boost::begin(lit_input);
|
||||
Iterator2T pit=::boost::begin(lit_test);
|
||||
for(;
|
||||
it!=InputEnd && pit!=TestEnd;
|
||||
++it,++pit)
|
||||
{
|
||||
if( !(Comp(*it,*pit)) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return pit==TestEnd;
|
||||
}
|
||||
|
||||
//! 'Starts with' predicate
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool starts_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test)
|
||||
{
|
||||
return ::boost::algorithm::starts_with(Input, Test, is_equal());
|
||||
}
|
||||
|
||||
//! 'Starts with' predicate ( case insensitive )
|
||||
/*!
|
||||
This predicate holds when the test string is a prefix of the Input.
|
||||
In other words, if the input starts with the test.
|
||||
Elements are compared case insensitively.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool istarts_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::starts_with(Input, Test, is_iequal(Loc));
|
||||
}
|
||||
|
||||
|
||||
// ends_with predicate -----------------------------------------------//
|
||||
|
||||
//! 'Ends with' predicate
|
||||
/*!
|
||||
This predicate holds when the test string is a suffix of the Input.
|
||||
In other words, if the input ends with the test.
|
||||
When the optional predicate is specified, it is used for character-wise
|
||||
comparison.
|
||||
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Comp An element comparison predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T, typename PredicateT>
|
||||
inline bool ends_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
PredicateT Comp)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
|
||||
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range1T>::type Iterator1T;
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<Iterator1T>::iterator_category category;
|
||||
|
||||
return detail::
|
||||
ends_with_iter_select(
|
||||
::boost::begin(lit_input),
|
||||
::boost::end(lit_input),
|
||||
::boost::begin(lit_test),
|
||||
::boost::end(lit_test),
|
||||
Comp,
|
||||
category());
|
||||
}
|
||||
|
||||
|
||||
//! 'Ends with' predicate
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool ends_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test)
|
||||
{
|
||||
return ::boost::algorithm::ends_with(Input, Test, is_equal());
|
||||
}
|
||||
|
||||
//! 'Ends with' predicate ( case insensitive )
|
||||
/*!
|
||||
This predicate holds when the test container is a suffix of the Input.
|
||||
In other words, if the input ends with the test.
|
||||
Elements are compared case insensitively.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool iends_with(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::ends_with(Input, Test, is_iequal(Loc));
|
||||
}
|
||||
|
||||
// contains predicate -----------------------------------------------//
|
||||
|
||||
//! 'Contains' predicate
|
||||
/*!
|
||||
This predicate holds when the test container is contained in the Input.
|
||||
When the optional predicate is specified, it is used for character-wise
|
||||
comparison.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Comp An element comparison predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T, typename PredicateT>
|
||||
inline bool contains(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
PredicateT Comp)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
|
||||
|
||||
if (::boost::empty(lit_test))
|
||||
{
|
||||
// Empty range is contained always
|
||||
return true;
|
||||
}
|
||||
|
||||
// Use the temporary variable to make VACPP happy
|
||||
bool bResult=(::boost::algorithm::first_finder(lit_test,Comp)(::boost::begin(lit_input), ::boost::end(lit_input)));
|
||||
return bResult;
|
||||
}
|
||||
|
||||
//! 'Contains' predicate
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool contains(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test)
|
||||
{
|
||||
return ::boost::algorithm::contains(Input, Test, is_equal());
|
||||
}
|
||||
|
||||
//! 'Contains' predicate ( case insensitive )
|
||||
/*!
|
||||
This predicate holds when the test container is contained in the Input.
|
||||
Elements are compared case insensitively.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool icontains(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::contains(Input, Test, is_iequal(Loc));
|
||||
}
|
||||
|
||||
// equals predicate -----------------------------------------------//
|
||||
|
||||
//! 'Equals' predicate
|
||||
/*!
|
||||
This predicate holds when the test container is equal to the
|
||||
input container i.e. all elements in both containers are same.
|
||||
When the optional predicate is specified, it is used for character-wise
|
||||
comparison.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Comp An element comparison predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This is a two-way version of \c std::equal algorithm
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T, typename PredicateT>
|
||||
inline bool equals(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
PredicateT Comp)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
|
||||
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range1T>::type Iterator1T;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range2T>::type Iterator2T;
|
||||
|
||||
Iterator1T InputEnd=::boost::end(lit_input);
|
||||
Iterator2T TestEnd=::boost::end(lit_test);
|
||||
|
||||
Iterator1T it=::boost::begin(lit_input);
|
||||
Iterator2T pit=::boost::begin(lit_test);
|
||||
for(;
|
||||
it!=InputEnd && pit!=TestEnd;
|
||||
++it,++pit)
|
||||
{
|
||||
if( !(Comp(*it,*pit)) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return (pit==TestEnd) && (it==InputEnd);
|
||||
}
|
||||
|
||||
//! 'Equals' predicate
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool equals(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test)
|
||||
{
|
||||
return ::boost::algorithm::equals(Input, Test, is_equal());
|
||||
}
|
||||
|
||||
//! 'Equals' predicate ( case insensitive )
|
||||
/*!
|
||||
This predicate holds when the test container is equal to the
|
||||
input container i.e. all elements in both containers are same.
|
||||
Elements are compared case insensitively.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Test A test sequence
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return The result of the test
|
||||
|
||||
\note This is a two-way version of \c std::equal algorithm
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool iequals(
|
||||
const Range1T& Input,
|
||||
const Range2T& Test,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::equals(Input, Test, is_iequal(Loc));
|
||||
}
|
||||
|
||||
// lexicographical_compare predicate -----------------------------//
|
||||
|
||||
//! Lexicographical compare predicate
|
||||
/*!
|
||||
This predicate is an overload of std::lexicographical_compare
|
||||
for range arguments
|
||||
|
||||
It check whether the first argument is lexicographically less
|
||||
then the second one.
|
||||
|
||||
If the optional predicate is specified, it is used for character-wise
|
||||
comparison
|
||||
|
||||
\param Arg1 First argument
|
||||
\param Arg2 Second argument
|
||||
\param Pred Comparison predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T, typename PredicateT>
|
||||
inline bool lexicographical_compare(
|
||||
const Range1T& Arg1,
|
||||
const Range2T& Arg2,
|
||||
PredicateT Pred)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_arg1(::boost::as_literal(Arg1));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_arg2(::boost::as_literal(Arg2));
|
||||
|
||||
return std::lexicographical_compare(
|
||||
::boost::begin(lit_arg1),
|
||||
::boost::end(lit_arg1),
|
||||
::boost::begin(lit_arg2),
|
||||
::boost::end(lit_arg2),
|
||||
Pred);
|
||||
}
|
||||
|
||||
//! Lexicographical compare predicate
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool lexicographical_compare(
|
||||
const Range1T& Arg1,
|
||||
const Range2T& Arg2)
|
||||
{
|
||||
return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_less());
|
||||
}
|
||||
|
||||
//! Lexicographical compare predicate (case-insensitive)
|
||||
/*!
|
||||
This predicate is an overload of std::lexicographical_compare
|
||||
for range arguments.
|
||||
It check whether the first argument is lexicographically less
|
||||
then the second one.
|
||||
Elements are compared case insensitively
|
||||
|
||||
|
||||
\param Arg1 First argument
|
||||
\param Arg2 Second argument
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
inline bool ilexicographical_compare(
|
||||
const Range1T& Arg1,
|
||||
const Range2T& Arg2,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_iless(Loc));
|
||||
}
|
||||
|
||||
|
||||
// all predicate -----------------------------------------------//
|
||||
|
||||
//! 'All' predicate
|
||||
/*!
|
||||
This predicate holds it all its elements satisfy a given
|
||||
condition, represented by the predicate.
|
||||
|
||||
\param Input An input sequence
|
||||
\param Pred A predicate
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename RangeT, typename PredicateT>
|
||||
inline bool all(
|
||||
const RangeT& Input,
|
||||
PredicateT Pred)
|
||||
{
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
|
||||
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<RangeT>::type Iterator1T;
|
||||
|
||||
Iterator1T InputEnd=::boost::end(lit_input);
|
||||
for( Iterator1T It=::boost::begin(lit_input); It!=InputEnd; ++It)
|
||||
{
|
||||
if (!Pred(*It))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull names to the boost namespace
|
||||
using algorithm::starts_with;
|
||||
using algorithm::istarts_with;
|
||||
using algorithm::ends_with;
|
||||
using algorithm::iends_with;
|
||||
using algorithm::contains;
|
||||
using algorithm::icontains;
|
||||
using algorithm::equals;
|
||||
using algorithm::iequals;
|
||||
using algorithm::all;
|
||||
using algorithm::lexicographical_compare;
|
||||
using algorithm::ilexicographical_compare;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_PREDICATE_HPP
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGN_HPP
|
||||
#define BOOST_ALIGN_ALIGN_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_STD_ALIGN)
|
||||
#include <boost/align/detail/align_cxx11.hpp>
|
||||
#else
|
||||
#include <boost/align/detail/align.hpp>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGN_DOWN_HPP
|
||||
#define BOOST_ALIGN_ALIGN_DOWN_HPP
|
||||
|
||||
#include <boost/align/detail/align_down.hpp>
|
||||
#include <boost/align/align_down_forward.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR inline std::size_t align_down(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT
|
||||
{
|
||||
return value & ~(alignment - 1);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGN_DOWN_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGN_DOWN_FORWARD_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR std::size_t align_down(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGN_UP_HPP
|
||||
#define BOOST_ALIGN_ALIGN_UP_HPP
|
||||
|
||||
#include <boost/align/detail/align_up.hpp>
|
||||
#include <boost/align/align_up_forward.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR inline std::size_t align_up(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT
|
||||
{
|
||||
return (value + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGN_UP_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGN_UP_FORWARD_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR std::size_t align_up(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_ALLOC_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_ALLOC_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_HAS_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(__APPLE_CC__) || defined(macintosh)
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_ALIGN_USE_ALLOCATE)
|
||||
#include <boost/align/detail/aligned_alloc.hpp>
|
||||
#elif defined(_MSC_VER) && !defined(UNDER_CE)
|
||||
#include <boost/align/detail/aligned_alloc_msvc.hpp>
|
||||
#elif defined(__MINGW32__) && (__MSVCRT_VERSION__ >= 0x0700)
|
||||
#include <boost/align/detail/aligned_alloc_msvc.hpp>
|
||||
#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
|
||||
#include <boost/align/detail/aligned_alloc_posix.hpp>
|
||||
#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
#include <boost/align/detail/aligned_alloc_macos.hpp>
|
||||
#elif defined(__ANDROID__)
|
||||
#include <boost/align/detail/aligned_alloc_android.hpp>
|
||||
#elif defined(__SunOS_5_11) || defined(__SunOS_5_12)
|
||||
#include <boost/align/detail/aligned_alloc_posix.hpp>
|
||||
#elif defined(sun) || defined(__sun)
|
||||
#include <boost/align/detail/aligned_alloc_sunos.hpp>
|
||||
#elif (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)
|
||||
#include <boost/align/detail/aligned_alloc_posix.hpp>
|
||||
#else
|
||||
#include <boost/align/detail/aligned_alloc.hpp>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
|
||||
|
||||
#include <boost/align/detail/addressof.hpp>
|
||||
#include <boost/align/detail/is_alignment_constant.hpp>
|
||||
#include <boost/align/detail/max_objects.hpp>
|
||||
#include <boost/align/detail/max_size.hpp>
|
||||
#include <boost/align/aligned_alloc.hpp>
|
||||
#include <boost/align/aligned_allocator_forward.hpp>
|
||||
#include <boost/align/alignment_of.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <new>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class T, std::size_t Alignment>
|
||||
class aligned_allocator {
|
||||
BOOST_STATIC_ASSERT(detail::
|
||||
is_alignment_constant<Alignment>::value);
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef void* void_pointer;
|
||||
typedef const void* const_void_pointer;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
|
||||
private:
|
||||
enum {
|
||||
min_align = detail::max_size<Alignment,
|
||||
alignment_of<value_type>::value>::value
|
||||
};
|
||||
|
||||
public:
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef aligned_allocator<U, Alignment> other;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
|
||||
aligned_allocator() = default;
|
||||
#else
|
||||
aligned_allocator() BOOST_NOEXCEPT { }
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
aligned_allocator(const aligned_allocator<U, Alignment>&)
|
||||
BOOST_NOEXCEPT { }
|
||||
|
||||
pointer address(reference value) const BOOST_NOEXCEPT {
|
||||
return detail::addressof(value);
|
||||
}
|
||||
|
||||
const_pointer address(const_reference value) const BOOST_NOEXCEPT {
|
||||
return detail::addressof(value);
|
||||
}
|
||||
|
||||
pointer allocate(size_type size, const_void_pointer = 0) {
|
||||
void* p = 0;
|
||||
if (size > 0) {
|
||||
p = aligned_alloc(min_align, sizeof(T) * size);
|
||||
if (!p) {
|
||||
boost::throw_exception(std::bad_alloc());
|
||||
}
|
||||
}
|
||||
return static_cast<T*>(p);
|
||||
}
|
||||
|
||||
void deallocate(pointer ptr, size_type) {
|
||||
boost::alignment::aligned_free(ptr);
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT {
|
||||
return detail::max_objects<T>::value;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class U, class... Args>
|
||||
void construct(U* ptr, Args&&... args) {
|
||||
::new((void*)ptr) U(std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
template<class U, class V>
|
||||
void construct(U* ptr, V&& value) {
|
||||
::new((void*)ptr) U(std::forward<V>(value));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
template<class U, class V>
|
||||
void construct(U* ptr, const V& value) {
|
||||
::new((void*)ptr) U(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
void construct(U* ptr) {
|
||||
::new((void*)ptr) U();
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void destroy(U* ptr) {
|
||||
(void)ptr;
|
||||
ptr->~U();
|
||||
}
|
||||
};
|
||||
|
||||
template<std::size_t Alignment>
|
||||
class aligned_allocator<void, Alignment> {
|
||||
BOOST_STATIC_ASSERT(detail::
|
||||
is_alignment_constant<Alignment>::value);
|
||||
|
||||
public:
|
||||
typedef void value_type;
|
||||
typedef void* pointer;
|
||||
typedef const void* const_pointer;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef aligned_allocator<U, Alignment> other;
|
||||
};
|
||||
};
|
||||
|
||||
template<class T1, class T2, std::size_t Alignment>
|
||||
inline bool operator==(const aligned_allocator<T1, Alignment>&,
|
||||
const aligned_allocator<T2, Alignment>&) BOOST_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T1, class T2, std::size_t Alignment>
|
||||
inline bool operator!=(const aligned_allocator<T1, Alignment>&,
|
||||
const aligned_allocator<T2, Alignment>&) BOOST_NOEXCEPT
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-178
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2016 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP
|
||||
|
||||
#include <boost/align/detail/addressof.hpp>
|
||||
#include <boost/align/detail/is_alignment_constant.hpp>
|
||||
#include <boost/align/detail/max_align.hpp>
|
||||
#include <boost/align/detail/max_size.hpp>
|
||||
#include <boost/align/align.hpp>
|
||||
#include <boost/align/aligned_allocator_adaptor_forward.hpp>
|
||||
#include <boost/align/alignment_of.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <new>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class Allocator, std::size_t Alignment>
|
||||
class aligned_allocator_adaptor
|
||||
: public Allocator {
|
||||
BOOST_STATIC_ASSERT(detail::
|
||||
is_alignment_constant<Alignment>::value);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef std::allocator_traits<Allocator> traits;
|
||||
|
||||
typedef typename traits::
|
||||
template rebind_alloc<char> char_alloc;
|
||||
|
||||
typedef typename traits::
|
||||
template rebind_traits<char> char_traits;
|
||||
|
||||
typedef typename char_traits::pointer char_ptr;
|
||||
#else
|
||||
typedef typename Allocator::
|
||||
template rebind<char>::other char_alloc;
|
||||
|
||||
typedef typename char_alloc::pointer char_ptr;
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef typename traits::value_type value_type;
|
||||
typedef typename traits::size_type size_type;
|
||||
#else
|
||||
typedef typename Allocator::value_type value_type;
|
||||
typedef typename Allocator::size_type size_type;
|
||||
#endif
|
||||
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef void* void_pointer;
|
||||
typedef const void* const_void_pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
private:
|
||||
enum {
|
||||
min_align = detail::max_size<Alignment,
|
||||
detail::max_align<value_type, char_ptr>::value>::value
|
||||
};
|
||||
|
||||
public:
|
||||
template<class U>
|
||||
struct rebind {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef aligned_allocator_adaptor<typename traits::
|
||||
template rebind_alloc<U>, Alignment> other;
|
||||
#else
|
||||
typedef aligned_allocator_adaptor<typename Allocator::
|
||||
template rebind<U>::other, Alignment> other;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
|
||||
aligned_allocator_adaptor() = default;
|
||||
#else
|
||||
aligned_allocator_adaptor()
|
||||
: Allocator() { }
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class A>
|
||||
explicit aligned_allocator_adaptor(A&& alloc) BOOST_NOEXCEPT
|
||||
: Allocator(std::forward<A>(alloc)) { }
|
||||
#else
|
||||
template<class A>
|
||||
explicit aligned_allocator_adaptor(const A& alloc) BOOST_NOEXCEPT
|
||||
: Allocator(alloc) { }
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
aligned_allocator_adaptor(const aligned_allocator_adaptor<U,
|
||||
Alignment>& other) BOOST_NOEXCEPT
|
||||
: Allocator(other.base()) { }
|
||||
|
||||
Allocator& base() BOOST_NOEXCEPT {
|
||||
return static_cast<Allocator&>(*this);
|
||||
}
|
||||
|
||||
const Allocator& base() const BOOST_NOEXCEPT {
|
||||
return static_cast<const Allocator&>(*this);
|
||||
}
|
||||
|
||||
pointer allocate(size_type size) {
|
||||
std::size_t s = size * sizeof(value_type);
|
||||
std::size_t n = s + min_align - 1;
|
||||
char_alloc a(base());
|
||||
char_ptr p = a.allocate(sizeof p + n);
|
||||
void* r = detail::addressof(*p) + sizeof p;
|
||||
(void)align(min_align, s, r, n);
|
||||
::new((void*)(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
|
||||
return static_cast<pointer>(r);
|
||||
}
|
||||
|
||||
pointer allocate(size_type size, const_void_pointer hint) {
|
||||
std::size_t s = size * sizeof(value_type);
|
||||
std::size_t n = s + min_align - 1;
|
||||
char_ptr h = char_ptr();
|
||||
if (hint) {
|
||||
h = *(static_cast<const char_ptr*>(hint) - 1);
|
||||
}
|
||||
char_alloc a(base());
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
char_ptr p = char_traits::allocate(a, sizeof p + n, h);
|
||||
#else
|
||||
char_ptr p = a.allocate(sizeof p + n, h);
|
||||
#endif
|
||||
void* r = detail::addressof(*p) + sizeof p;
|
||||
(void)align(min_align, s, r, n);
|
||||
::new((void*)(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
|
||||
return static_cast<pointer>(r);
|
||||
}
|
||||
|
||||
void deallocate(pointer ptr, size_type size) {
|
||||
char_ptr* p = (char_ptr*)ptr - 1;
|
||||
char_ptr r = *p;
|
||||
p->~char_ptr();
|
||||
char_alloc a(base());
|
||||
a.deallocate(r, sizeof r + size * sizeof(value_type) +
|
||||
min_align - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<class A1, class A2, std::size_t Alignment>
|
||||
inline bool operator==(const aligned_allocator_adaptor<A1,
|
||||
Alignment>& a, const aligned_allocator_adaptor<A2,
|
||||
Alignment>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return a.base() == b.base();
|
||||
}
|
||||
|
||||
template<class A1, class A2, std::size_t Alignment>
|
||||
inline bool operator!=(const aligned_allocator_adaptor<A1,
|
||||
Alignment>& a, const aligned_allocator_adaptor<A2,
|
||||
Alignment>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class Allocator, std::size_t Alignment = 1>
|
||||
class aligned_allocator_adaptor;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class T, std::size_t Alignment = 1>
|
||||
class aligned_allocator;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-32
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_DELETE_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_DELETE_HPP
|
||||
|
||||
#include <boost/align/aligned_alloc.hpp>
|
||||
#include <boost/align/aligned_delete_forward.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
struct aligned_delete {
|
||||
template<class T>
|
||||
void operator()(T* ptr) const
|
||||
BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) {
|
||||
if (ptr) {
|
||||
ptr->~T();
|
||||
boost::alignment::aligned_free(ptr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
struct aligned_delete;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2016 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNMENT_OF_HPP
|
||||
#define BOOST_ALIGN_ALIGNMENT_OF_HPP
|
||||
|
||||
#include <boost/align/detail/element_type.hpp>
|
||||
#include <boost/align/alignment_of_forward.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#include <boost/align/detail/alignment_of_msvc.hpp>
|
||||
#elif defined(__GNUC__) && defined(__unix__) && !defined(__LP64__)
|
||||
#include <boost/align/detail/alignment_of.hpp>
|
||||
#elif defined(BOOST_CLANG) && !defined(__x86_64__)
|
||||
#include <boost/align/detail/alignment_of.hpp>
|
||||
#elif !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
#include <boost/align/detail/alignment_of_cxx11.hpp>
|
||||
#elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
|
||||
#include <boost/align/detail/alignment_of_gcc.hpp>
|
||||
#elif defined(__CODEGEARC__)
|
||||
#include <boost/align/detail/alignment_of_codegear.hpp>
|
||||
#elif defined(BOOST_CLANG)
|
||||
#include <boost/align/detail/alignment_of_clang.hpp>
|
||||
#elif __GNUC__ > 4
|
||||
#include <boost/align/detail/alignment_of_gcc.hpp>
|
||||
#elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)
|
||||
#include <boost/align/detail/alignment_of_gcc.hpp>
|
||||
#else
|
||||
#include <boost/align/detail/alignment_of.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: detail::alignment_of<typename detail::element_type<T>::type> { };
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
|
||||
template<class T>
|
||||
constexpr std::size_t alignment_of_v = alignment_of<T>::value;
|
||||
#endif
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
|
||||
#define BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
template<class T>
|
||||
struct alignment_of;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
(c) 2015 NumScale SAS
|
||||
(c) 2015 LRI UMR 8623 CNRS/University Paris Sud XI
|
||||
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_ASSUME_ALIGNED_HPP
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#include <boost/align/detail/assume_aligned_msvc.hpp>
|
||||
#elif defined(BOOST_CLANG) && defined(__has_builtin)
|
||||
#include <boost/align/detail/assume_aligned_clang.hpp>
|
||||
#elif BOOST_GCC_VERSION >= 40700
|
||||
#include <boost/align/detail/assume_aligned_gcc.hpp>
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#include <boost/align/detail/assume_aligned_intel.hpp>
|
||||
#else
|
||||
#include <boost/align/detail/assume_aligned.hpp>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ADDRESSOF_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ADDRESSOF_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ADDRESSOF)
|
||||
#include <memory>
|
||||
#else
|
||||
#include <boost/core/addressof.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ADDRESSOF)
|
||||
using std::addressof;
|
||||
#else
|
||||
using boost::addressof;
|
||||
#endif
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2016 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGN_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGN_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* align(std::size_t alignment, std::size_t size,
|
||||
void*& ptr, std::size_t& space)
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
if (size <= space) {
|
||||
char* p = (char*)(((std::size_t)ptr + alignment - 1) &
|
||||
~(alignment - 1));
|
||||
std::size_t n = space - (p - static_cast<char*>(ptr));
|
||||
if (size <= n) {
|
||||
ptr = p;
|
||||
space = n;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
using std::align;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/align/align_down_forward.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return (void*)(align_down((std::size_t)ptr, alignment));
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/align/align_up_forward.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return (void*)(align_up((std::size_t)ptr, alignment));
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/align/align.hpp>
|
||||
#include <boost/align/alignment_of.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
enum {
|
||||
min_align = alignment_of<void*>::value
|
||||
};
|
||||
if (alignment < min_align) {
|
||||
alignment = min_align;
|
||||
}
|
||||
std::size_t n = size + alignment - min_align;
|
||||
void* r = 0;
|
||||
void* p = std::malloc(sizeof(void*) + n);
|
||||
if (p) {
|
||||
r = static_cast<char*>(p) + sizeof p;
|
||||
(void)align(alignment, size, r, n);
|
||||
*(static_cast<void**>(r) - 1) = p;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
if (ptr) {
|
||||
std::free(*(static_cast<void**>(ptr) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <malloc.h>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return ::memalign(alignment, size);
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (alignment < sizeof(void*)) {
|
||||
alignment = sizeof(void*);
|
||||
}
|
||||
void* p;
|
||||
if (::posix_memalign(&p, alignment, size) != 0) {
|
||||
p = 0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <malloc.h>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return ::_aligned_malloc(size, alignment);
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
::_aligned_free(ptr);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
if (alignment < sizeof(void*)) {
|
||||
alignment = sizeof(void*);
|
||||
}
|
||||
void* p;
|
||||
if (::posix_memalign(&p, alignment, size) != 0) {
|
||||
p = 0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline void* aligned_alloc(std::size_t alignment, std::size_t size)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return ::memalign(alignment, size);
|
||||
}
|
||||
|
||||
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
|
||||
|
||||
#include <boost/align/detail/min_size.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct alignof_helper {
|
||||
char value;
|
||||
T object;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: min_size<sizeof(T), sizeof(alignof_helper<T>) - sizeof(T)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: integral_constant<std::size_t, __alignof(T)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: integral_constant<std::size_t, alignof(T)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
using std::alignment_of;
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: integral_constant<std::size_t, __alignof__(T)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
|
||||
|
||||
#include <boost/align/detail/min_size.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct alignof_helper {
|
||||
T first;
|
||||
char value;
|
||||
T second;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct alignment_of
|
||||
: min_size<sizeof(T),
|
||||
sizeof(alignof_helper<T>) - (sizeof(T) << 1)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
(c) 2015 NumScale SAS
|
||||
(c) 2015 LRI UMR 8623 CNRS/University Paris Sud XI
|
||||
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
|
||||
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
|
||||
|
||||
#endif
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP
|
||||
|
||||
#if __has_builtin(__builtin_assume_aligned)
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
|
||||
(p) = (__typeof__(p))(__builtin_assume_aligned((p), (n)))
|
||||
#else
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
(c) 2015 NumScale SAS
|
||||
(c) 2015 LRI UMR 8623 CNRS/University Paris Sud XI
|
||||
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
|
||||
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
|
||||
(p) = (__typeof__(p))(__builtin_assume_aligned((p), (n)))
|
||||
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
(c) 2015 NumScale SAS
|
||||
(c) 2015 LRI UMR 8623 CNRS/University Paris Sud XI
|
||||
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP
|
||||
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
|
||||
__assume_aligned((p), (n))
|
||||
|
||||
#endif
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
(c) 2015 NumScale SAS
|
||||
(c) 2015 LRI UMR 8623 CNRS/University Paris Sud XI
|
||||
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
|
||||
__assume(((std::size_t)(p) & ((n) - 1)) == 0)
|
||||
|
||||
#endif
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
|
||||
#define BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <cstddef>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
using std::remove_reference;
|
||||
using std::remove_all_extents;
|
||||
using std::remove_cv;
|
||||
#else
|
||||
template<class T>
|
||||
struct remove_reference {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_reference<T&> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class T>
|
||||
struct remove_reference<T&&> {
|
||||
typedef T type;
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
struct remove_all_extents {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_all_extents<T[]>
|
||||
: remove_all_extents<T> { };
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct remove_all_extents<T[N]>
|
||||
: remove_all_extents<T> { };
|
||||
|
||||
template<class T>
|
||||
struct remove_const {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_const<const T> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_volatile {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_volatile<volatile T> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct remove_cv
|
||||
: remove_volatile<typename remove_const<T>::type> { };
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
struct element_type
|
||||
: remove_cv<typename remove_all_extents<typename
|
||||
remove_reference<T>::type>::type> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2016 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP
|
||||
#define BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
using std::integral_constant;
|
||||
#else
|
||||
template<class T, T Value>
|
||||
struct integral_constant {
|
||||
typedef T value_type;
|
||||
typedef integral_constant type;
|
||||
|
||||
BOOST_CONSTEXPR operator value_type() const BOOST_NOEXCEPT {
|
||||
return Value;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR value_type operator()() const BOOST_NOEXCEPT {
|
||||
return Value;
|
||||
}
|
||||
|
||||
BOOST_STATIC_CONSTEXPR T value = Value;
|
||||
};
|
||||
#endif
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
|
||||
#define BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
|
||||
|
||||
#include <boost/align/detail/is_alignment.hpp>
|
||||
#include <boost/align/is_aligned_forward.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
inline bool is_aligned(const void* ptr, std::size_t alignment)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return is_aligned((std::size_t)ptr, alignment);
|
||||
}
|
||||
|
||||
inline bool is_aligned(std::size_t alignment, const void* ptr)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_ASSERT(detail::is_alignment(alignment));
|
||||
return is_aligned((std::size_t)ptr, alignment);
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP
|
||||
#define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
BOOST_CONSTEXPR inline bool is_alignment(std::size_t value)
|
||||
BOOST_NOEXCEPT
|
||||
{
|
||||
return (value > 0) && ((value & (value - 1)) == 0);
|
||||
}
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP
|
||||
#define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<std::size_t N>
|
||||
struct is_alignment_constant
|
||||
: integral_constant<bool, (N > 0) && ((N & (N - 1)) == 0)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP
|
||||
#define BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP
|
||||
|
||||
#include <boost/align/detail/max_size.hpp>
|
||||
#include <boost/align/alignment_of.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class A, class B>
|
||||
struct max_align
|
||||
: max_size<alignment_of<A>::value, alignment_of<B>::value> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP
|
||||
#define BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct max_objects
|
||||
: integral_constant<std::size_t,
|
||||
~static_cast<std::size_t>(0) / sizeof(T)> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_MAX_SIZE_HPP
|
||||
#define BOOST_ALIGN_DETAIL_MAX_SIZE_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<std::size_t A, std::size_t B>
|
||||
struct max_size
|
||||
: integral_constant<std::size_t, (A > B) ? A : B> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_DETAIL_MIN_SIZE_HPP
|
||||
#define BOOST_ALIGN_DETAIL_MIN_SIZE_HPP
|
||||
|
||||
#include <boost/align/detail/integral_constant.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
namespace detail {
|
||||
|
||||
template<std::size_t A, std::size_t B>
|
||||
struct min_size
|
||||
: integral_constant<std::size_t, (A < B) ? A : B> { };
|
||||
|
||||
} /* .detail */
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_IS_ALIGNED_HPP
|
||||
#define BOOST_ALIGN_IS_ALIGNED_HPP
|
||||
|
||||
#include <boost/align/detail/is_aligned.hpp>
|
||||
#include <boost/align/is_aligned_forward.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR inline bool is_aligned(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT
|
||||
{
|
||||
return (value & (alignment - 1)) == 0;
|
||||
}
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
(c) 2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#ifndef BOOST_ALIGN_IS_ALIGNED_FORWARD_HPP
|
||||
#define BOOST_ALIGN_IS_ALIGNED_FORWARD_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace alignment {
|
||||
|
||||
BOOST_CONSTEXPR bool is_aligned(std::size_t value,
|
||||
std::size_t alignment) BOOST_NOEXCEPT;
|
||||
|
||||
} /* .alignment */
|
||||
} /* .boost */
|
||||
|
||||
#endif
|
||||
Vendored
-325
@@ -1,325 +0,0 @@
|
||||
// See http://www.boost.org/libs/any for Documentation.
|
||||
|
||||
#ifndef BOOST_ANY_INCLUDED
|
||||
#define BOOST_ANY_INCLUDED
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// what: variant type boost::any
|
||||
// who: contributed by Kevlin Henney,
|
||||
// with features contributed and bugs found by
|
||||
// Antony Polukhin, Ed Brey, Mark Rodgers,
|
||||
// Peter Dimov, and James Curran
|
||||
// when: July 2001, April 2013 - May 2013
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include <boost/type_index.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/decay.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/add_reference.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class any
|
||||
{
|
||||
public: // structors
|
||||
|
||||
any() BOOST_NOEXCEPT
|
||||
: content(0)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
any(const ValueType & value)
|
||||
: content(new holder<
|
||||
BOOST_DEDUCED_TYPENAME remove_cv<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>::type
|
||||
>(value))
|
||||
{
|
||||
}
|
||||
|
||||
any(const any & other)
|
||||
: content(other.content ? other.content->clone() : 0)
|
||||
{
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
// Move constructor
|
||||
any(any&& other) BOOST_NOEXCEPT
|
||||
: content(other.content)
|
||||
{
|
||||
other.content = 0;
|
||||
}
|
||||
|
||||
// Perfect forwarding of ValueType
|
||||
template<typename ValueType>
|
||||
any(ValueType&& value
|
||||
, typename boost::disable_if<boost::is_same<any&, ValueType> >::type* = 0 // disable if value has type `any&`
|
||||
, typename boost::disable_if<boost::is_const<ValueType> >::type* = 0) // disable if value has type `const ValueType&&`
|
||||
: content(new holder< typename decay<ValueType>::type >(static_cast<ValueType&&>(value)))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~any() BOOST_NOEXCEPT
|
||||
{
|
||||
delete content;
|
||||
}
|
||||
|
||||
public: // modifiers
|
||||
|
||||
any & swap(any & rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
std::swap(content, rhs.content);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename ValueType>
|
||||
any & operator=(const ValueType & rhs)
|
||||
{
|
||||
any(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
any & operator=(any rhs)
|
||||
{
|
||||
any(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#else
|
||||
any & operator=(const any& rhs)
|
||||
{
|
||||
any(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// move assignement
|
||||
any & operator=(any&& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
rhs.swap(*this);
|
||||
any().swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Perfect forwarding of ValueType
|
||||
template <class ValueType>
|
||||
any & operator=(ValueType&& rhs)
|
||||
{
|
||||
any(static_cast<ValueType&&>(rhs)).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
public: // queries
|
||||
|
||||
bool empty() const BOOST_NOEXCEPT
|
||||
{
|
||||
return !content;
|
||||
}
|
||||
|
||||
void clear() BOOST_NOEXCEPT
|
||||
{
|
||||
any().swap(*this);
|
||||
}
|
||||
|
||||
const boost::typeindex::type_info& type() const BOOST_NOEXCEPT
|
||||
{
|
||||
return content ? content->type() : boost::typeindex::type_id<void>().type_info();
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
private: // types
|
||||
#else
|
||||
public: // types (public so any_cast can be non-friend)
|
||||
#endif
|
||||
|
||||
class placeholder
|
||||
{
|
||||
public: // structors
|
||||
|
||||
virtual ~placeholder()
|
||||
{
|
||||
}
|
||||
|
||||
public: // queries
|
||||
|
||||
virtual const boost::typeindex::type_info& type() const BOOST_NOEXCEPT = 0;
|
||||
|
||||
virtual placeholder * clone() const = 0;
|
||||
|
||||
};
|
||||
|
||||
template<typename ValueType>
|
||||
class holder : public placeholder
|
||||
{
|
||||
public: // structors
|
||||
|
||||
holder(const ValueType & value)
|
||||
: held(value)
|
||||
{
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
holder(ValueType&& value)
|
||||
: held(static_cast< ValueType&& >(value))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
public: // queries
|
||||
|
||||
virtual const boost::typeindex::type_info& type() const BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::typeindex::type_id<ValueType>().type_info();
|
||||
}
|
||||
|
||||
virtual placeholder * clone() const
|
||||
{
|
||||
return new holder(held);
|
||||
}
|
||||
|
||||
public: // representation
|
||||
|
||||
ValueType held;
|
||||
|
||||
private: // intentionally left unimplemented
|
||||
holder & operator=(const holder &);
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
|
||||
private: // representation
|
||||
|
||||
template<typename ValueType>
|
||||
friend ValueType * any_cast(any *) BOOST_NOEXCEPT;
|
||||
|
||||
template<typename ValueType>
|
||||
friend ValueType * unsafe_any_cast(any *) BOOST_NOEXCEPT;
|
||||
|
||||
#else
|
||||
|
||||
public: // representation (public so any_cast can be non-friend)
|
||||
|
||||
#endif
|
||||
|
||||
placeholder * content;
|
||||
|
||||
};
|
||||
|
||||
inline void swap(any & lhs, any & rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE bad_any_cast :
|
||||
#ifndef BOOST_NO_RTTI
|
||||
public std::bad_cast
|
||||
#else
|
||||
public std::exception
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
return "boost::bad_any_cast: "
|
||||
"failed conversion using boost::any_cast";
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ValueType>
|
||||
ValueType * any_cast(any * operand) BOOST_NOEXCEPT
|
||||
{
|
||||
return operand && operand->type() == boost::typeindex::type_id<ValueType>()
|
||||
? &static_cast<any::holder<BOOST_DEDUCED_TYPENAME remove_cv<ValueType>::type> *>(operand->content)->held
|
||||
: 0;
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
inline const ValueType * any_cast(const any * operand) BOOST_NOEXCEPT
|
||||
{
|
||||
return any_cast<ValueType>(const_cast<any *>(operand));
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
ValueType any_cast(any & operand)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
|
||||
|
||||
|
||||
nonref * result = any_cast<nonref>(&operand);
|
||||
if(!result)
|
||||
boost::throw_exception(bad_any_cast());
|
||||
|
||||
// Attempt to avoid construction of a temporary object in cases when
|
||||
// `ValueType` is not a reference. Example:
|
||||
// `static_cast<std::string>(*result);`
|
||||
// which is equal to `std::string(*result);`
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
|
||||
boost::is_reference<ValueType>,
|
||||
ValueType,
|
||||
BOOST_DEDUCED_TYPENAME boost::add_reference<ValueType>::type
|
||||
>::type ref_type;
|
||||
|
||||
return static_cast<ref_type>(*result);
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType any_cast(const any & operand)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
|
||||
return any_cast<const nonref &>(const_cast<any &>(operand));
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename ValueType>
|
||||
inline ValueType any_cast(any&& operand)
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(
|
||||
boost::is_rvalue_reference<ValueType&&>::value /*true if ValueType is rvalue or just a value*/
|
||||
|| boost::is_const< typename boost::remove_reference<ValueType>::type >::value,
|
||||
"boost::any_cast shall not be used for getting nonconst references to temporary objects"
|
||||
);
|
||||
return any_cast<ValueType>(operand);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Note: The "unsafe" versions of any_cast are not part of the
|
||||
// public interface and may be removed at any time. They are
|
||||
// required where we know what type is stored in the any and can't
|
||||
// use typeid() comparison, e.g., when our types may travel across
|
||||
// different shared libraries.
|
||||
template<typename ValueType>
|
||||
inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT
|
||||
{
|
||||
return &static_cast<any::holder<ValueType> *>(operand->content)->held;
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
inline const ValueType * unsafe_any_cast(const any * operand) BOOST_NOEXCEPT
|
||||
{
|
||||
return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
|
||||
}
|
||||
}
|
||||
|
||||
// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
|
||||
//
|
||||
// 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)
|
||||
|
||||
#endif
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
#ifndef BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP
|
||||
#define BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// archive/archive_exception.hpp:
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <exception>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/archive/detail/decl.hpp>
|
||||
|
||||
// note: the only reason this is in here is that windows header
|
||||
// includes #define exception_code _exception_code (arrrgghhhh!).
|
||||
// the most expedient way to address this is be sure that this
|
||||
// header is always included whenever this header file is included.
|
||||
#if defined(BOOST_WINDOWS)
|
||||
#include <excpt.h>
|
||||
#endif
|
||||
|
||||
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
|
||||
|
||||
namespace boost {
|
||||
namespace archive {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// exceptions thrown by archives
|
||||
//
|
||||
class BOOST_SYMBOL_VISIBLE archive_exception :
|
||||
public virtual std::exception
|
||||
{
|
||||
private:
|
||||
char m_buffer[128];
|
||||
protected:
|
||||
BOOST_ARCHIVE_DECL unsigned int
|
||||
append(unsigned int l, const char * a);
|
||||
BOOST_ARCHIVE_DECL
|
||||
archive_exception() BOOST_NOEXCEPT;
|
||||
public:
|
||||
typedef enum {
|
||||
no_exception, // initialized without code
|
||||
other_exception, // any excepton not listed below
|
||||
unregistered_class, // attempt to serialize a pointer of
|
||||
// an unregistered class
|
||||
invalid_signature, // first line of archive does not contain
|
||||
// expected string
|
||||
unsupported_version,// archive created with library version
|
||||
// subsequent to this one
|
||||
pointer_conflict, // an attempt has been made to directly
|
||||
// serialize an object which has
|
||||
// already been serialized through a pointer.
|
||||
// Were this permitted, the archive load would result
|
||||
// in the creation of an extra copy of the obect.
|
||||
incompatible_native_format, // attempt to read native binary format
|
||||
// on incompatible platform
|
||||
array_size_too_short,// array being loaded doesn't fit in array allocated
|
||||
input_stream_error, // error on input stream
|
||||
invalid_class_name, // class name greater than the maximum permitted.
|
||||
// most likely a corrupted archive or an attempt
|
||||
// to insert virus via buffer overrun method.
|
||||
unregistered_cast, // base - derived relationship not registered with
|
||||
// void_cast_register
|
||||
unsupported_class_version, // type saved with a version # greater than the
|
||||
// one used by the program. This indicates that the program
|
||||
// needs to be rebuilt.
|
||||
multiple_code_instantiation, // code for implementing serialization for some
|
||||
// type has been instantiated in more than one module.
|
||||
output_stream_error // error on input stream
|
||||
} exception_code;
|
||||
exception_code code;
|
||||
|
||||
BOOST_ARCHIVE_DECL archive_exception(
|
||||
exception_code c,
|
||||
const char * e1 = NULL,
|
||||
const char * e2 = NULL
|
||||
) BOOST_NOEXCEPT;
|
||||
BOOST_ARCHIVE_DECL archive_exception(archive_exception const &) BOOST_NOEXCEPT ;
|
||||
virtual BOOST_ARCHIVE_DECL ~archive_exception() BOOST_NOEXCEPT_OR_NOTHROW ;
|
||||
virtual BOOST_ARCHIVE_DECL const char * what() const BOOST_NOEXCEPT_OR_NOTHROW ;
|
||||
};
|
||||
|
||||
}// namespace archive
|
||||
}// namespace boost
|
||||
|
||||
#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
|
||||
|
||||
#endif //BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// abi_prefix.hpp
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/config/abi_prefix.hpp> // must be the last header
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4251 4231 4660 4275)
|
||||
#endif
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// abi_suffix.hpp
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
|
||||
|
||||
Vendored
-57
@@ -1,57 +0,0 @@
|
||||
#ifndef BOOST_ARCHIVE_DETAIL_DECL_HPP
|
||||
#define BOOST_ARCHIVE_DETAIL_DECL_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2///////// 3/////////4/////////5/////////6/////////7/////////8
|
||||
// decl.hpp
|
||||
//
|
||||
// (c) Copyright Robert Ramey 2004
|
||||
// Use, modification, and distribution is subject to 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)
|
||||
|
||||
// See library home page at http://www.boost.org/libs/serialization
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
// This header implements separate compilation features as described in
|
||||
// http://www.boost.org/more/separate_compilation.html
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SERIALIZATION_DYN_LINK))
|
||||
#if defined(BOOST_ARCHIVE_SOURCE)
|
||||
#define BOOST_ARCHIVE_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
#define BOOST_ARCHIVE_DECL BOOST_SYMBOL_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_WARCHIVE_SOURCE)
|
||||
#define BOOST_WARCHIVE_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
#define BOOST_WARCHIVE_DECL BOOST_SYMBOL_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_WARCHIVE_SOURCE) || defined(BOOST_ARCHIVE_SOURCE)
|
||||
#define BOOST_ARCHIVE_OR_WARCHIVE_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
#define BOOST_ARCHIVE_OR_WARCHIVE_DECL BOOST_SYMBOL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if ! defined(BOOST_ARCHIVE_DECL)
|
||||
#define BOOST_ARCHIVE_DECL
|
||||
#endif
|
||||
#if ! defined(BOOST_WARCHIVE_DECL)
|
||||
#define BOOST_WARCHIVE_DECL
|
||||
#endif
|
||||
#if ! defined(BOOST_ARCHIVE_OR_WARCHIVE_DECL)
|
||||
#define BOOST_ARCHIVE_OR_WARCHIVE_DECL
|
||||
#endif
|
||||
|
||||
#endif // BOOST_ARCHIVE_DETAIL_DECL_HPP
|
||||
Vendored
-121
@@ -1,121 +0,0 @@
|
||||
//
|
||||
// asio.hpp
|
||||
// ~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// See www.boost.org/libs/asio for documentation.
|
||||
//
|
||||
|
||||
#ifndef BOOST_ASIO_HPP
|
||||
#define BOOST_ASIO_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/async_result.hpp>
|
||||
#include <boost/asio/basic_datagram_socket.hpp>
|
||||
#include <boost/asio/basic_deadline_timer.hpp>
|
||||
#include <boost/asio/basic_io_object.hpp>
|
||||
#include <boost/asio/basic_raw_socket.hpp>
|
||||
#include <boost/asio/basic_seq_packet_socket.hpp>
|
||||
#include <boost/asio/basic_serial_port.hpp>
|
||||
#include <boost/asio/basic_signal_set.hpp>
|
||||
#include <boost/asio/basic_socket_acceptor.hpp>
|
||||
#include <boost/asio/basic_socket_iostream.hpp>
|
||||
#include <boost/asio/basic_socket_streambuf.hpp>
|
||||
#include <boost/asio/basic_stream_socket.hpp>
|
||||
#include <boost/asio/basic_streambuf.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/buffered_read_stream_fwd.hpp>
|
||||
#include <boost/asio/buffered_read_stream.hpp>
|
||||
#include <boost/asio/buffered_stream_fwd.hpp>
|
||||
#include <boost/asio/buffered_stream.hpp>
|
||||
#include <boost/asio/buffered_write_stream_fwd.hpp>
|
||||
#include <boost/asio/buffered_write_stream.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <boost/asio/completion_condition.hpp>
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/asio/coroutine.hpp>
|
||||
#include <boost/asio/datagram_socket_service.hpp>
|
||||
#include <boost/asio/deadline_timer_service.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/generic/basic_endpoint.hpp>
|
||||
#include <boost/asio/generic/datagram_protocol.hpp>
|
||||
#include <boost/asio/generic/raw_protocol.hpp>
|
||||
#include <boost/asio/generic/seq_packet_protocol.hpp>
|
||||
#include <boost/asio/generic/stream_protocol.hpp>
|
||||
#include <boost/asio/handler_alloc_hook.hpp>
|
||||
#include <boost/asio/handler_continuation_hook.hpp>
|
||||
#include <boost/asio/handler_invoke_hook.hpp>
|
||||
#include <boost/asio/handler_type.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/ip/address.hpp>
|
||||
#include <boost/asio/ip/address_v4.hpp>
|
||||
#include <boost/asio/ip/address_v6.hpp>
|
||||
#include <boost/asio/ip/basic_endpoint.hpp>
|
||||
#include <boost/asio/ip/basic_resolver.hpp>
|
||||
#include <boost/asio/ip/basic_resolver_entry.hpp>
|
||||
#include <boost/asio/ip/basic_resolver_iterator.hpp>
|
||||
#include <boost/asio/ip/basic_resolver_query.hpp>
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
#include <boost/asio/ip/icmp.hpp>
|
||||
#include <boost/asio/ip/multicast.hpp>
|
||||
#include <boost/asio/ip/resolver_query_base.hpp>
|
||||
#include <boost/asio/ip/resolver_service.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
#include <boost/asio/ip/unicast.hpp>
|
||||
#include <boost/asio/ip/v6_only.hpp>
|
||||
#include <boost/asio/is_read_buffered.hpp>
|
||||
#include <boost/asio/is_write_buffered.hpp>
|
||||
#include <boost/asio/local/basic_endpoint.hpp>
|
||||
#include <boost/asio/local/connect_pair.hpp>
|
||||
#include <boost/asio/local/datagram_protocol.hpp>
|
||||
#include <boost/asio/local/stream_protocol.hpp>
|
||||
#include <boost/asio/placeholders.hpp>
|
||||
#include <boost/asio/posix/basic_descriptor.hpp>
|
||||
#include <boost/asio/posix/basic_stream_descriptor.hpp>
|
||||
#include <boost/asio/posix/descriptor_base.hpp>
|
||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||
#include <boost/asio/posix/stream_descriptor_service.hpp>
|
||||
#include <boost/asio/raw_socket_service.hpp>
|
||||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/read_at.hpp>
|
||||
#include <boost/asio/read_until.hpp>
|
||||
#include <boost/asio/seq_packet_socket_service.hpp>
|
||||
#include <boost/asio/serial_port.hpp>
|
||||
#include <boost/asio/serial_port_base.hpp>
|
||||
#include <boost/asio/serial_port_service.hpp>
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/asio/signal_set_service.hpp>
|
||||
#include <boost/asio/socket_acceptor_service.hpp>
|
||||
#include <boost/asio/socket_base.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/stream_socket_service.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/asio/time_traits.hpp>
|
||||
#include <boost/asio/version.hpp>
|
||||
#include <boost/asio/wait_traits.hpp>
|
||||
#include <boost/asio/waitable_timer_service.hpp>
|
||||
#include <boost/asio/windows/basic_handle.hpp>
|
||||
#include <boost/asio/windows/basic_object_handle.hpp>
|
||||
#include <boost/asio/windows/basic_random_access_handle.hpp>
|
||||
#include <boost/asio/windows/basic_stream_handle.hpp>
|
||||
#include <boost/asio/windows/object_handle.hpp>
|
||||
#include <boost/asio/windows/object_handle_service.hpp>
|
||||
#include <boost/asio/windows/overlapped_ptr.hpp>
|
||||
#include <boost/asio/windows/random_access_handle.hpp>
|
||||
#include <boost/asio/windows/random_access_handle_service.hpp>
|
||||
#include <boost/asio/windows/stream_handle.hpp>
|
||||
#include <boost/asio/windows/stream_handle_service.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
#include <boost/asio/write_at.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_HPP
|
||||
Vendored
-96
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// async_result.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_ASYNC_RESULT_HPP
|
||||
#define BOOST_ASIO_ASYNC_RESULT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <boost/asio/handler_type.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// An interface for customising the behaviour of an initiating function.
|
||||
/**
|
||||
* This template may be specialised for user-defined handler types.
|
||||
*/
|
||||
template <typename Handler>
|
||||
class async_result
|
||||
{
|
||||
public:
|
||||
/// The return type of the initiating function.
|
||||
typedef void type;
|
||||
|
||||
/// Construct an async result from a given handler.
|
||||
/**
|
||||
* When using a specalised async_result, the constructor has an opportunity
|
||||
* to initialise some state associated with the handler, which is then
|
||||
* returned from the initiating function.
|
||||
*/
|
||||
explicit async_result(Handler&)
|
||||
{
|
||||
}
|
||||
|
||||
/// Obtain the value to be returned from the initiating function.
|
||||
type get()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Helper template to deduce the true type of a handler, capture a local copy
|
||||
// of the handler, and then create an async_result for the handler.
|
||||
template <typename Handler, typename Signature>
|
||||
struct async_result_init
|
||||
{
|
||||
explicit async_result_init(BOOST_ASIO_MOVE_ARG(Handler) orig_handler)
|
||||
: handler(BOOST_ASIO_MOVE_CAST(Handler)(orig_handler)),
|
||||
result(handler)
|
||||
{
|
||||
}
|
||||
|
||||
typename handler_type<Handler, Signature>::type handler;
|
||||
async_result<typename handler_type<Handler, Signature>::type> result;
|
||||
};
|
||||
|
||||
template <typename Handler, typename Signature>
|
||||
struct async_result_type_helper
|
||||
{
|
||||
typedef typename async_result<
|
||||
typename handler_type<Handler, Signature>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
# define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
void_or_deduced
|
||||
#elif defined(_MSC_VER) && (_MSC_VER < 1500)
|
||||
# define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
typename ::boost::asio::detail::async_result_type_helper<h, sig>::type
|
||||
#else
|
||||
# define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
||||
typename ::boost::asio::async_result< \
|
||||
typename ::boost::asio::handler_type<h, sig>::type>::type
|
||||
#endif
|
||||
|
||||
#endif // BOOST_ASIO_ASYNC_RESULT_HPP
|
||||
-951
@@ -1,951 +0,0 @@
|
||||
//
|
||||
// basic_datagram_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
||||
#define BOOST_ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/asio/basic_socket.hpp>
|
||||
#include <boost/asio/datagram_socket_service.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/detail/type_traits.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides datagram-oriented socket functionality.
|
||||
/**
|
||||
* The basic_datagram_socket class template provides asynchronous and blocking
|
||||
* datagram-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename DatagramSocketService = datagram_socket_service<Protocol> >
|
||||
class basic_datagram_socket
|
||||
: public basic_socket<Protocol, DatagramSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename DatagramSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename DatagramSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_datagram_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a datagram socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*/
|
||||
explicit basic_datagram_socket(boost::asio::io_service& io_service)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_datagram_socket.
|
||||
/**
|
||||
* This constructor creates and opens a datagram socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a datagram socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the datagram
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(boost::asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, DatagramSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a datagram socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_datagram_socket from another.
|
||||
/**
|
||||
* This constructor moves a datagram socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_datagram_socket(basic_datagram_socket&& other)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST(basic_datagram_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_datagram_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a datagram socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_datagram_socket& operator=(basic_datagram_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, DatagramSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST(basic_datagram_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_datagram_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a datagram socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename DatagramSocketService1>
|
||||
basic_datagram_socket(
|
||||
basic_datagram_socket<Protocol1, DatagramSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, DatagramSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_datagram_socket<
|
||||
Protocol1, DatagramSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_datagram_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This assignment operator moves a datagram socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_datagram_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_datagram_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename DatagramSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_datagram_socket>::type& operator=(
|
||||
basic_datagram_socket<Protocol1, DatagramSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, DatagramSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_datagram_socket<
|
||||
Protocol1, DatagramSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code socket.send(boost::asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the datagram socket. The function
|
||||
* call will block until the data has been sent successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected datagram socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the datagram socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the datagram socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint destination(
|
||||
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.send_to(boost::asio::buffer(data, size), destination);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send a datagram to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send a datagram to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint destination(
|
||||
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.async_send_to(
|
||||
* boost::asio::buffer(data, size), destination, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, 0,
|
||||
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send a datagram to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.receive(boost::asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the datagram socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected datagram
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the datagram
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* datagram socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the datagram
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* datagram socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint sender_endpoint;
|
||||
* socket.receive_from(
|
||||
* boost::asio::buffer(data, size), sender_endpoint);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive a datagram. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive a datagram. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.async_receive_from(
|
||||
* boost::asio::buffer(data, size), sender_endpoint, handler); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive a datagram. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the datagram. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_DATAGRAM_SOCKET_HPP
|
||||
-520
@@ -1,520 +0,0 @@
|
||||
//
|
||||
// basic_deadline_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
|
||||
#define BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <cstddef>
|
||||
#include <boost/asio/basic_io_object.hpp>
|
||||
#include <boost/asio/deadline_timer_service.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_deadline_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A deadline timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use the boost::asio::deadline_timer typedef.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait:
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* boost::asio::deadline_timer timer(io_service);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(const boost::system::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* boost::asio::deadline_timer timer(io_service,
|
||||
* boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active deadline_timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_from_now(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const boost::system::error_code& e)
|
||||
* {
|
||||
* if (e != boost::asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The boost::asio::basic_deadline_timer::expires_from_now() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @li If a wait handler is cancelled, the boost::system::error_code passed to
|
||||
* it contains the value boost::asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Time,
|
||||
typename TimeTraits = boost::asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
class basic_deadline_timer
|
||||
: public basic_io_object<TimerService>
|
||||
{
|
||||
public:
|
||||
/// The time traits type.
|
||||
typedef TimeTraits traits_type;
|
||||
|
||||
/// The time type.
|
||||
typedef typename traits_type::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename traits_type::duration_type duration_type;
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_deadline_timer(boost::asio::io_service& io_service)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_deadline_timer(boost::asio::io_service& io_service,
|
||||
const time_type& expiry_time)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_deadline_timer(boost::asio::io_service& io_service,
|
||||
const duration_type& expiry_time)
|
||||
: basic_io_object<TimerService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.expires_from_now(this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.cancel(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.cancel_one(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.cancel_one(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return this->service.expires_at(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.expires_at(
|
||||
this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_type& expiry_time,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return this->service.expires_from_now(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration_type& expiry_time,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.wait(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(boost::system::error_code& ec)
|
||||
{
|
||||
this->service.wait(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (boost::system::error_code))
|
||||
async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
|
||||
Vendored
-243
@@ -1,243 +0,0 @@
|
||||
//
|
||||
// basic_io_object.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
||||
#define BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE)
|
||||
namespace detail
|
||||
{
|
||||
// Type trait used to determine whether a service supports move.
|
||||
template <typename IoObjectService>
|
||||
class service_has_move
|
||||
{
|
||||
private:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
template <typename T, typename U>
|
||||
static auto asio_service_has_move_eval(T* t, U* u)
|
||||
-> decltype(t->move_construct(*u, *u), char());
|
||||
static char (&asio_service_has_move_eval(...))[2];
|
||||
|
||||
public:
|
||||
static const bool value =
|
||||
sizeof(asio_service_has_move_eval(
|
||||
static_cast<service_type*>(0),
|
||||
static_cast<implementation_type*>(0))) == 1;
|
||||
};
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE)
|
||||
|
||||
/// Base class for all I/O objects.
|
||||
/**
|
||||
* @note All I/O objects are non-copyable. However, when using C++0x, certain
|
||||
* I/O objects do support move construction and move assignment.
|
||||
*/
|
||||
#if !defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
template <typename IoObjectService>
|
||||
#else
|
||||
template <typename IoObjectService,
|
||||
bool Movable = detail::service_has_move<IoObjectService>::value>
|
||||
#endif
|
||||
class basic_io_object
|
||||
{
|
||||
public:
|
||||
/// The type of the service that will be used to provide I/O operations.
|
||||
typedef IoObjectService service_type;
|
||||
|
||||
/// The underlying implementation type of I/O object.
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
/**
|
||||
* This function may be used to obtain the io_service object that the I/O
|
||||
* object uses to dispatch handlers for asynchronous operations.
|
||||
*
|
||||
* @return A reference to the io_service object that the I/O object will use
|
||||
* to dispatch handlers. Ownership is not transferred to the caller.
|
||||
*/
|
||||
boost::asio::io_service& get_io_service()
|
||||
{
|
||||
return service.get_io_service();
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().construct(get_implementation()); @endcode
|
||||
*/
|
||||
explicit basic_io_object(boost::asio::io_service& io_service)
|
||||
: service(boost::asio::use_service<IoObjectService>(io_service))
|
||||
{
|
||||
service.construct(implementation);
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_construct(
|
||||
* get_implementation(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object(basic_io_object&& other);
|
||||
|
||||
/// Move-assign a basic_io_object.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().move_assign(get_implementation(),
|
||||
* other.get_service(), other.get_implementation()); @endcode
|
||||
*
|
||||
* @note Available only for services that support movability,
|
||||
*/
|
||||
basic_io_object& operator=(basic_io_object&& other);
|
||||
#endif // defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Protected destructor to prevent deletion through this type.
|
||||
/**
|
||||
* Performs:
|
||||
* @code get_service().destroy(get_implementation()); @endcode
|
||||
*/
|
||||
~basic_io_object()
|
||||
{
|
||||
service.destroy(implementation);
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
service_type& get_service()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
/// Get the service associated with the I/O object.
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return service;
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_service().) The service associated with the I/O
|
||||
/// object.
|
||||
/**
|
||||
* @note Available only for services that do not support movability.
|
||||
*/
|
||||
service_type& service;
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
/// Get the underlying implementation of the I/O object.
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
/// (Deprecated: Use get_implementation().) The underlying implementation of
|
||||
/// the I/O object.
|
||||
implementation_type implementation;
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
basic_io_object& operator=(const basic_io_object&);
|
||||
};
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE)
|
||||
// Specialisation for movable objects.
|
||||
template <typename IoObjectService>
|
||||
class basic_io_object<IoObjectService, true>
|
||||
{
|
||||
public:
|
||||
typedef IoObjectService service_type;
|
||||
typedef typename service_type::implementation_type implementation_type;
|
||||
|
||||
boost::asio::io_service& get_io_service()
|
||||
{
|
||||
return service_->get_io_service();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit basic_io_object(boost::asio::io_service& io_service)
|
||||
: service_(&boost::asio::use_service<IoObjectService>(io_service))
|
||||
{
|
||||
service_->construct(implementation);
|
||||
}
|
||||
|
||||
basic_io_object(basic_io_object&& other)
|
||||
: service_(&other.get_service())
|
||||
{
|
||||
service_->move_construct(implementation, other.implementation);
|
||||
}
|
||||
|
||||
~basic_io_object()
|
||||
{
|
||||
service_->destroy(implementation);
|
||||
}
|
||||
|
||||
basic_io_object& operator=(basic_io_object&& other)
|
||||
{
|
||||
service_->move_assign(implementation,
|
||||
*other.service_, other.implementation);
|
||||
service_ = other.service_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
service_type& get_service()
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
const service_type& get_service() const
|
||||
{
|
||||
return *service_;
|
||||
}
|
||||
|
||||
implementation_type& get_implementation()
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
const implementation_type& get_implementation() const
|
||||
{
|
||||
return implementation;
|
||||
}
|
||||
|
||||
implementation_type implementation;
|
||||
|
||||
private:
|
||||
basic_io_object(const basic_io_object&);
|
||||
void operator=(const basic_io_object&);
|
||||
|
||||
IoObjectService* service_;
|
||||
};
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE)
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_IO_OBJECT_HPP
|
||||
Vendored
-942
@@ -1,942 +0,0 @@
|
||||
//
|
||||
// basic_raw_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_RAW_SOCKET_HPP
|
||||
#define BOOST_ASIO_BASIC_RAW_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/asio/basic_socket.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/detail/type_traits.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/raw_socket_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides raw-oriented socket functionality.
|
||||
/**
|
||||
* The basic_raw_socket class template provides asynchronous and blocking
|
||||
* raw-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename RawSocketService = raw_socket_service<Protocol> >
|
||||
class basic_raw_socket
|
||||
: public basic_socket<Protocol, RawSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename RawSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename RawSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_raw_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a raw socket without opening it. The open()
|
||||
* function must be called before data can be sent or received on the socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*/
|
||||
explicit basic_raw_socket(boost::asio::io_service& io_service)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_raw_socket.
|
||||
/**
|
||||
* This constructor creates and opens a raw socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a raw socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the raw
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(boost::asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, RawSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_raw_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a raw socket object to hold an existing
|
||||
* native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the raw socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_raw_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_raw_socket from another.
|
||||
/**
|
||||
* This constructor moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_raw_socket(basic_raw_socket&& other)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST(basic_raw_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_raw_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_raw_socket& operator=(basic_raw_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, RawSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST(basic_raw_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_raw_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This constructor moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename RawSocketService1>
|
||||
basic_raw_socket(basic_raw_socket<Protocol1, RawSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, RawSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_raw_socket<
|
||||
Protocol1, RawSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_raw_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This assignment operator moves a raw socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_raw_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_raw_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename RawSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_raw_socket>::type& operator=(
|
||||
basic_raw_socket<Protocol1, RawSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, RawSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_raw_socket<
|
||||
Protocol1, RawSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code socket.send(boost::asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One ore more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @note The send operation can only be used with a connected socket. Use
|
||||
* the send_to function to send data on an unconnected raw socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
/**
|
||||
* This function is used to send data on the raw socket. The function call
|
||||
* will block until the data has been sent successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_send operation can only be used with a connected socket.
|
||||
* Use the async_send_to function to send data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint destination(
|
||||
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.send_to(boost::asio::buffer(data, size), destination);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send_to(
|
||||
this->get_implementation(), buffers, destination, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send_to");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send raw data to the specified endpoint.
|
||||
/**
|
||||
* This function is used to send raw data to the specified remote endpoint.
|
||||
* The function call will block until the data has been sent successfully or
|
||||
* an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_to(this->get_implementation(),
|
||||
buffers, destination, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send raw data to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint destination(
|
||||
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
|
||||
* socket.async_send_to(
|
||||
* boost::asio::buffer(data, size), destination, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(this->get_implementation(),
|
||||
buffers, destination, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send raw data to the specified
|
||||
* remote endpoint. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent to the remote endpoint.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param destination The remote endpoint to which the data will be sent.
|
||||
* Copies will be made of the endpoint as required.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send_to(const ConstBufferSequence& buffers,
|
||||
const endpoint_type& destination, socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send_to(
|
||||
this->get_implementation(), buffers, destination, flags,
|
||||
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.receive(boost::asio::buffer(data, size)); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the raw socket. The function
|
||||
* call will block until data has been received successfully or an error
|
||||
* occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @note The receive operation can only be used with a connected socket. Use
|
||||
* the receive_from function to receive data on an unconnected raw
|
||||
* socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the raw
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* raw socket.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the raw
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The async_receive operation can only be used with a connected socket.
|
||||
* Use the async_receive_from function to receive data on an unconnected
|
||||
* raw socket.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* boost::asio::ip::udp::endpoint sender_endpoint;
|
||||
* socket.receive_from(
|
||||
* boost::asio::buffer(data, size), sender_endpoint);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive_from");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive raw data with the endpoint of the sender.
|
||||
/**
|
||||
* This function is used to receive raw data. The function call will block
|
||||
* until data has been received successfully or an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive_from(this->get_implementation(),
|
||||
buffers, sender_endpoint, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive raw data. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code socket.async_receive_from(
|
||||
* boost::asio::buffer(data, size), 0, sender_endpoint, handler); @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, 0,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive raw data. The function
|
||||
* call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param sender_endpoint An endpoint object that receives the endpoint of
|
||||
* the remote sender of the data. Ownership of the sender_endpoint object
|
||||
* is retained by the caller, which must guarantee that it is valid until the
|
||||
* handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive_from(const MutableBufferSequence& buffers,
|
||||
endpoint_type& sender_endpoint, socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive_from(
|
||||
this->get_implementation(), buffers, sender_endpoint, flags,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_RAW_SOCKET_HPP
|
||||
-567
@@ -1,567 +0,0 @@
|
||||
//
|
||||
// basic_seq_packet_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
#define BOOST_ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/asio/basic_socket.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/seq_packet_socket_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides sequenced packet socket functionality.
|
||||
/**
|
||||
* The basic_seq_packet_socket class template provides asynchronous and blocking
|
||||
* sequenced packet socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename SeqPacketSocketService = seq_packet_socket_service<Protocol> >
|
||||
class basic_seq_packet_socket
|
||||
: public basic_socket<Protocol, SeqPacketSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename SeqPacketSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename SeqPacketSocketService::native_handle_type
|
||||
native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_seq_packet_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket without opening it. The
|
||||
* socket needs to be opened and then connected or accepted before data can
|
||||
* be sent or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*/
|
||||
explicit basic_seq_packet_socket(boost::asio::io_service& io_service)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_seq_packet_socket.
|
||||
/**
|
||||
* This constructor creates and opens a sequenced_packet socket. The socket
|
||||
* needs to be connected or accepted before data can be sent or received on
|
||||
* it.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket, opening it and binding it to the
|
||||
/// given local endpoint.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket and automatically opens
|
||||
* it bound to the specified endpoint on the local machine. The protocol used
|
||||
* is the protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the sequenced
|
||||
* packet socket will be bound.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(boost::asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_seq_packet_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a sequenced packet socket object to hold an
|
||||
* existing native socket.
|
||||
*
|
||||
* @param io_service The io_service object that the sequenced packet socket
|
||||
* will use to dispatch handlers for any asynchronous operations performed on
|
||||
* the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_seq_packet_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_seq_packet_socket(basic_seq_packet_socket&& other)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST(basic_seq_packet_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_seq_packet_socket& operator=(basic_seq_packet_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, SeqPacketSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST(basic_seq_packet_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename SeqPacketSocketService1>
|
||||
basic_seq_packet_socket(
|
||||
basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, SeqPacketSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_seq_packet_socket<
|
||||
Protocol1, SeqPacketSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_seq_packet_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This assignment operator moves a sequenced packet socket from one object to
|
||||
* another.
|
||||
*
|
||||
* @param other The other basic_seq_packet_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_seq_packet_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename SeqPacketSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_seq_packet_socket>::type& operator=(
|
||||
basic_seq_packet_socket<Protocol1, SeqPacketSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, SeqPacketSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_seq_packet_socket<
|
||||
Protocol1, SeqPacketSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block until the data has been sent successfully, or an
|
||||
* until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(boost::asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the sequenced packet socket. The
|
||||
* function call will block the data has been sent successfully, or an until
|
||||
* error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the sequenced packet
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(boost::asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(boost::asio::buffer(data, size), out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, out_flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(boost::asio::buffer(data, size), 0, out_flags);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the sequenced packet socket. The
|
||||
* function call will block until data has been received successfully, or
|
||||
* until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags After the receive call completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(this->get_implementation(),
|
||||
buffers, in_flags, out_flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* packet socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(boost::asio::buffer(data, size), out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags& out_flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, 0, out_flags,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the sequenced
|
||||
* data socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param in_flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param out_flags Once the asynchronous operation completes, contains flags
|
||||
* associated with the received data. For example, if the
|
||||
* socket_base::message_end_of_record bit is set then the received data marks
|
||||
* the end of a record. The caller must guarantee that the referenced
|
||||
* variable remains valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(
|
||||
* boost::asio::buffer(data, size),
|
||||
* 0, out_flags, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags in_flags,
|
||||
socket_base::message_flags& out_flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(
|
||||
this->get_implementation(), buffers, in_flags, out_flags,
|
||||
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_SEQ_PACKET_SOCKET_HPP
|
||||
-697
@@ -1,697 +0,0 @@
|
||||
//
|
||||
// basic_serial_port.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_SERIAL_PORT_HPP
|
||||
#define BOOST_ASIO_BASIC_SERIAL_PORT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include <string>
|
||||
#include <boost/asio/basic_io_object.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/serial_port_base.hpp>
|
||||
#include <boost/asio/serial_port_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides serial port functionality.
|
||||
/**
|
||||
* The basic_serial_port class template provides functionality that is common
|
||||
* to all serial ports.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*/
|
||||
template <typename SerialPortService = serial_port_service>
|
||||
class basic_serial_port
|
||||
: public basic_io_object<SerialPortService>,
|
||||
public serial_port_base
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// serial port.
|
||||
typedef typename SerialPortService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a serial port.
|
||||
typedef typename SerialPortService::native_handle_type native_handle_type;
|
||||
|
||||
/// A basic_serial_port is always the lowest layer.
|
||||
typedef basic_serial_port<SerialPortService> lowest_layer_type;
|
||||
|
||||
/// Construct a basic_serial_port without opening it.
|
||||
/**
|
||||
* This constructor creates a serial port without opening it.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*/
|
||||
explicit basic_serial_port(boost::asio::io_service& io_service)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(boost::asio::io_service& io_service,
|
||||
const char* device)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
boost::asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct and open a basic_serial_port.
|
||||
/**
|
||||
* This constructor creates and opens a serial port for the specified device
|
||||
* name.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param device The platform-specific device name for this serial
|
||||
* port.
|
||||
*/
|
||||
explicit basic_serial_port(boost::asio::io_service& io_service,
|
||||
const std::string& device)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
boost::asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Construct a basic_serial_port on an existing native serial port.
|
||||
/**
|
||||
* This constructor creates a serial port object to hold an existing native
|
||||
* serial port.
|
||||
*
|
||||
* @param io_service The io_service object that the serial port will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_serial_port(boost::asio::io_service& io_service,
|
||||
const native_handle_type& native_serial_port)
|
||||
: basic_io_object<SerialPortService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
boost::asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_serial_port from another.
|
||||
/**
|
||||
* This constructor moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_service&) constructor.
|
||||
*/
|
||||
basic_serial_port(basic_serial_port&& other)
|
||||
: basic_io_object<SerialPortService>(
|
||||
BOOST_ASIO_MOVE_CAST(basic_serial_port)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_serial_port from another.
|
||||
/**
|
||||
* This assignment operator moves a serial port from one object to another.
|
||||
*
|
||||
* @param other The other basic_serial_port object from which the move will
|
||||
* occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_serial_port(io_service&) constructor.
|
||||
*/
|
||||
basic_serial_port& operator=(basic_serial_port&& other)
|
||||
{
|
||||
basic_io_object<SerialPortService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST(basic_serial_port)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a reference to the lowest layer in a stack of
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A reference to the lowest layer in the stack of layers. Ownership
|
||||
* is not transferred to the caller.
|
||||
*/
|
||||
lowest_layer_type& lowest_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Get a const reference to the lowest layer.
|
||||
/**
|
||||
* This function returns a const reference to the lowest layer in a stack of
|
||||
* layers. Since a basic_serial_port cannot contain any further layers, it
|
||||
* simply returns a reference to itself.
|
||||
*
|
||||
* @return A const reference to the lowest layer in the stack of layers.
|
||||
* Ownership is not transferred to the caller.
|
||||
*/
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port for the specified device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void open(const std::string& device)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().open(this->get_implementation(), device, ec);
|
||||
boost::asio::detail::throw_error(ec, "open");
|
||||
}
|
||||
|
||||
/// Open the serial port using the specified device name.
|
||||
/**
|
||||
* This function opens the serial port using the given platform-specific
|
||||
* device name.
|
||||
*
|
||||
* @param device The platform-specific device name.
|
||||
*
|
||||
* @param ec Set the indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code open(const std::string& device,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().open(this->get_implementation(), device, ec);
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void assign(const native_handle_type& native_serial_port)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
boost::asio::detail::throw_error(ec, "assign");
|
||||
}
|
||||
|
||||
/// Assign an existing native serial port to the serial port.
|
||||
/*
|
||||
* This function opens the serial port to hold an existing native serial port.
|
||||
*
|
||||
* @param native_serial_port A native serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code assign(const native_handle_type& native_serial_port,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().assign(this->get_implementation(),
|
||||
native_serial_port, ec);
|
||||
}
|
||||
|
||||
/// Determine whether the serial port is open.
|
||||
bool is_open() const
|
||||
{
|
||||
return this->get_service().is_open(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* boost::asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().close(this->get_implementation(), ec);
|
||||
boost::asio::detail::throw_error(ec, "close");
|
||||
}
|
||||
|
||||
/// Close the serial port.
|
||||
/**
|
||||
* This function is used to close the serial port. Any asynchronous read or
|
||||
* write operations will be cancelled immediately, and will complete with the
|
||||
* boost::asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code close(boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().close(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// (Deprecated: Use native_handle().) Get the native serial port
|
||||
/// representation.
|
||||
/**
|
||||
* This function may be used to obtain the underlying representation of the
|
||||
* serial port. This is intended to allow access to native serial port
|
||||
* functionality that is not otherwise provided.
|
||||
*/
|
||||
native_type native()
|
||||
{
|
||||
return this->get_service().native_handle(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Get the native serial port representation.
|
||||
/**
|
||||
* This function may be used to obtain the underlying representation of the
|
||||
* serial port. This is intended to allow access to native serial port
|
||||
* functionality that is not otherwise provided.
|
||||
*/
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return this->get_service().native_handle(this->get_implementation());
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the boost::asio::error::operation_aborted error.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().cancel(this->get_implementation(), ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all asynchronous operations associated with the serial port.
|
||||
/**
|
||||
* This function causes all outstanding asynchronous read or write operations
|
||||
* to finish immediately, and the handlers for cancelled operations will be
|
||||
* passed the boost::asio::error::operation_aborted error.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code cancel(boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().cancel(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void send_break()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().send_break(this->get_implementation(), ec);
|
||||
boost::asio::detail::throw_error(ec, "send_break");
|
||||
}
|
||||
|
||||
/// Send a break sequence to the serial port.
|
||||
/**
|
||||
* This function causes a break sequence of platform-specific duration to be
|
||||
* sent out the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code send_break(boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send_break(this->get_implementation(), ec);
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* boost::asio::serial_port_base::baud_rate @n
|
||||
* boost::asio::serial_port_base::flow_control @n
|
||||
* boost::asio::serial_port_base::parity @n
|
||||
* boost::asio::serial_port_base::stop_bits @n
|
||||
* boost::asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
void set_option(const SettableSerialPortOption& option)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().set_option(this->get_implementation(), option, ec);
|
||||
boost::asio::detail::throw_error(ec, "set_option");
|
||||
}
|
||||
|
||||
/// Set an option on the serial port.
|
||||
/**
|
||||
* This function is used to set an option on the serial port.
|
||||
*
|
||||
* @param option The option value to be set on the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @sa SettableSerialPortOption @n
|
||||
* boost::asio::serial_port_base::baud_rate @n
|
||||
* boost::asio::serial_port_base::flow_control @n
|
||||
* boost::asio::serial_port_base::parity @n
|
||||
* boost::asio::serial_port_base::stop_bits @n
|
||||
* boost::asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename SettableSerialPortOption>
|
||||
boost::system::error_code set_option(const SettableSerialPortOption& option,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().set_option(
|
||||
this->get_implementation(), option, ec);
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* boost::asio::serial_port_base::baud_rate @n
|
||||
* boost::asio::serial_port_base::flow_control @n
|
||||
* boost::asio::serial_port_base::parity @n
|
||||
* boost::asio::serial_port_base::stop_bits @n
|
||||
* boost::asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
void get_option(GettableSerialPortOption& option)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->get_service().get_option(this->get_implementation(), option, ec);
|
||||
boost::asio::detail::throw_error(ec, "get_option");
|
||||
}
|
||||
|
||||
/// Get an option from the serial port.
|
||||
/**
|
||||
* This function is used to get the current value of an option on the serial
|
||||
* port.
|
||||
*
|
||||
* @param option The option value to be obtained from the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @sa GettableSerialPortOption @n
|
||||
* boost::asio::serial_port_base::baud_rate @n
|
||||
* boost::asio::serial_port_base::flow_control @n
|
||||
* boost::asio::serial_port_base::parity @n
|
||||
* boost::asio::serial_port_base::stop_bits @n
|
||||
* boost::asio::serial_port_base::character_size
|
||||
*/
|
||||
template <typename GettableSerialPortOption>
|
||||
boost::system::error_code get_option(GettableSerialPortOption& option,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().get_option(
|
||||
this->get_implementation(), option, ec);
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @returns The number of bytes written.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.write_some(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
boost::asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Write some data to the serial port.
|
||||
/**
|
||||
* This function is used to write data to the serial port. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes written. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().write_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
/**
|
||||
* This function is used to asynchronously write data to the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the serial port.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the write operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_write_some(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_write_some(this->get_implementation(),
|
||||
buffers, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.read_some(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
boost::asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Read some data from the serial port.
|
||||
/**
|
||||
* This function is used to read data from the serial port. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes read. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().read_some(
|
||||
this->get_implementation(), buffers, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
/**
|
||||
* This function is used to asynchronously read data from the serial port.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the read operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
* requested amount of data is read before the asynchronous operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* serial_port.async_read_some(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_read_some(this->get_implementation(),
|
||||
buffers, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
|
||||
// || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_SERIAL_PORT_HPP
|
||||
Vendored
-386
@@ -1,386 +0,0 @@
|
||||
//
|
||||
// basic_signal_set.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_SIGNAL_SET_HPP
|
||||
#define BOOST_ASIO_BASIC_SIGNAL_SET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#include <boost/asio/basic_io_object.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/signal_set_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides signal functionality.
|
||||
/**
|
||||
* The basic_signal_set class template provides the ability to perform an
|
||||
* asynchronous wait for one or more signals to occur.
|
||||
*
|
||||
* Most applications will use the boost::asio::signal_set typedef.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Example
|
||||
* Performing an asynchronous wait:
|
||||
* @code
|
||||
* void handler(
|
||||
* const boost::system::error_code& error,
|
||||
* int signal_number)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // A signal occurred.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a signal set registered for process termination.
|
||||
* boost::asio::signal_set signals(io_service, SIGINT, SIGTERM);
|
||||
*
|
||||
* // Start an asynchronous wait for one of the signals to occur.
|
||||
* signals.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Queueing of signal notifications
|
||||
*
|
||||
* If a signal is registered with a signal_set, and the signal occurs when
|
||||
* there are no waiting handlers, then the signal notification is queued. The
|
||||
* next async_wait operation on that signal_set will dequeue the notification.
|
||||
* If multiple notifications are queued, subsequent async_wait operations
|
||||
* dequeue them one at a time. Signal notifications are dequeued in order of
|
||||
* ascending signal number.
|
||||
*
|
||||
* If a signal number is removed from a signal_set (using the @c remove or @c
|
||||
* erase member functions) then any queued notifications for that signal are
|
||||
* discarded.
|
||||
*
|
||||
* @par Multiple registration of signals
|
||||
*
|
||||
* The same signal number may be registered with different signal_set objects.
|
||||
* When the signal occurs, one handler is called for each signal_set object.
|
||||
*
|
||||
* Note that multiple registration only works for signals that are registered
|
||||
* using Asio. The application must not also register a signal handler using
|
||||
* functions such as @c signal() or @c sigaction().
|
||||
*
|
||||
* @par Signal masking on POSIX platforms
|
||||
*
|
||||
* POSIX allows signals to be blocked using functions such as @c sigprocmask()
|
||||
* and @c pthread_sigmask(). For signals to be delivered, programs must ensure
|
||||
* that any signals registered using signal_set objects are unblocked in at
|
||||
* least one thread.
|
||||
*/
|
||||
template <typename SignalSetService = signal_set_service>
|
||||
class basic_signal_set
|
||||
: public basic_io_object<SignalSetService>
|
||||
{
|
||||
public:
|
||||
/// Construct a signal set without adding any signals.
|
||||
/**
|
||||
* This constructor creates a signal set without registering for any signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*/
|
||||
explicit basic_signal_set(boost::asio::io_service& io_service)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a signal set and add one signal.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for one signal.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code boost::asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1); @endcode
|
||||
*/
|
||||
basic_signal_set(boost::asio::io_service& io_service, int signal_number_1)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add two signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for two signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code boost::asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2); @endcode
|
||||
*/
|
||||
basic_signal_set(boost::asio::io_service& io_service, int signal_number_1,
|
||||
int signal_number_2)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_2, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Construct a signal set and add three signals.
|
||||
/**
|
||||
* This constructor creates a signal set and registers for three signals.
|
||||
*
|
||||
* @param io_service The io_service object that the signal set will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the set.
|
||||
*
|
||||
* @param signal_number_1 The first signal number to be added.
|
||||
*
|
||||
* @param signal_number_2 The second signal number to be added.
|
||||
*
|
||||
* @param signal_number_3 The third signal number to be added.
|
||||
*
|
||||
* @note This constructor is equivalent to performing:
|
||||
* @code boost::asio::signal_set signals(io_service);
|
||||
* signals.add(signal_number_1);
|
||||
* signals.add(signal_number_2);
|
||||
* signals.add(signal_number_3); @endcode
|
||||
*/
|
||||
basic_signal_set(boost::asio::io_service& io_service, int signal_number_1,
|
||||
int signal_number_2, int signal_number_3)
|
||||
: basic_io_object<SignalSetService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.add(this->implementation, signal_number_1, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_2, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
this->service.add(this->implementation, signal_number_3, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void add(int signal_number)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.add(this->implementation, signal_number, ec);
|
||||
boost::asio::detail::throw_error(ec, "add");
|
||||
}
|
||||
|
||||
/// Add a signal to a signal_set.
|
||||
/**
|
||||
* This function adds the specified signal to the set. It has no effect if the
|
||||
* signal is already in the set.
|
||||
*
|
||||
* @param signal_number The signal to be added to the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
boost::system::error_code add(int signal_number,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.add(this->implementation, signal_number, ec);
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
void remove(int signal_number)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.remove(this->implementation, signal_number, ec);
|
||||
boost::asio::detail::throw_error(ec, "remove");
|
||||
}
|
||||
|
||||
/// Remove a signal from a signal_set.
|
||||
/**
|
||||
* This function removes the specified signal from the set. It has no effect
|
||||
* if the signal is not in the set.
|
||||
*
|
||||
* @param signal_number The signal to be removed from the set.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes any notifications that have been queued for the specified
|
||||
* signal number.
|
||||
*/
|
||||
boost::system::error_code remove(int signal_number,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.remove(this->implementation, signal_number, ec);
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.clear(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "clear");
|
||||
}
|
||||
|
||||
/// Remove all signals from a signal_set.
|
||||
/**
|
||||
* This function removes all signals from the set. It has no effect if the set
|
||||
* is already empty.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note Removes all queued notifications.
|
||||
*/
|
||||
boost::system::error_code clear(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.clear(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the boost::asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
void cancel()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.cancel(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel");
|
||||
}
|
||||
|
||||
/// Cancel all operations associated with the signal set.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the signal set. The handler for each cancelled
|
||||
* operation will be invoked with the boost::asio::error::operation_aborted
|
||||
* error code.
|
||||
*
|
||||
* Cancellation does not alter the set of registered signals.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @note If a registered signal occurred before cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
boost::system::error_code cancel(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous operation to wait for a signal to be delivered.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* signal set. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li One of the registered signals in the signal set occurs; or
|
||||
*
|
||||
* @li The signal set was cancelled, in which case the handler is passed the
|
||||
* error code boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the signal occurs. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* int signal_number // Indicates which signal occurred.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename SignalHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
|
||||
void (boost::system::error_code, int))
|
||||
async_wait(BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a SignalHandler.
|
||||
BOOST_ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
BOOST_ASIO_MOVE_CAST(SignalHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_SIGNAL_SET_HPP
|
||||
Vendored
-1520
File diff suppressed because it is too large.
Load diff
-1138
File diff suppressed because it is too large.
Load diff
-288
@@ -1,288 +0,0 @@
|
||||
//
|
||||
// basic_socket_iostream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
||||
#define BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <boost/asio/basic_socket_streambuf.hpp>
|
||||
#include <boost/asio/stream_socket_service.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include <boost/asio/detail/variadic_templates.hpp>
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// explicit basic_socket_iostream(T1 x1, ..., Tn xn)
|
||||
// : std::basic_iostream<char>(
|
||||
// &this->detail::socket_iostream_base<
|
||||
// Protocol, StreamSocketService, Time,
|
||||
// TimeTraits, TimerService>::streambuf_)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define BOOST_ASIO_PRIVATE_CTR_DEF(n) \
|
||||
template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
|
||||
explicit basic_socket_iostream(BOOST_ASIO_VARIADIC_PARAMS(n)) \
|
||||
: std::basic_iostream<char>( \
|
||||
&this->detail::socket_iostream_base< \
|
||||
Protocol, StreamSocketService, Time, \
|
||||
TimeTraits, TimerService>::streambuf_) \
|
||||
{ \
|
||||
this->setf(std::ios_base::unitbuf); \
|
||||
if (rdbuf()->connect(BOOST_ASIO_VARIADIC_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// void connect(T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// if (rdbuf()->connect(x1, ..., xn) == 0)
|
||||
// this->setstate(std::ios_base::failbit);
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define BOOST_ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void connect(BOOST_ASIO_VARIADIC_PARAMS(n)) \
|
||||
{ \
|
||||
if (rdbuf()->connect(BOOST_ASIO_VARIADIC_ARGS(n)) == 0) \
|
||||
this->setstate(std::ios_base::failbit); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the streambuf is initialised
|
||||
// prior to the basic_socket_iostream's basic_iostream base class.
|
||||
template <typename Protocol, typename StreamSocketService,
|
||||
typename Time, typename TimeTraits, typename TimerService>
|
||||
class socket_iostream_base
|
||||
{
|
||||
protected:
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService> streambuf_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/// Iostream interface for a socket.
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol>,
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
typename Time = boost::posix_time::ptime,
|
||||
typename TimeTraits = boost::asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
#else
|
||||
typename Time = steady_timer::clock_type,
|
||||
typename TimeTraits = steady_timer::traits_type,
|
||||
typename TimerService = steady_timer::service_type>
|
||||
#endif
|
||||
class basic_socket_iostream
|
||||
: private detail::socket_iostream_base<Protocol,
|
||||
StreamSocketService, Time, TimeTraits, TimerService>,
|
||||
public std::basic_iostream<char>
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateTime, Boost.Chrono or std::chrono.
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef TimeTraits traits_helper;
|
||||
#else
|
||||
typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The time type.
|
||||
typedef typename TimeTraits::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename TimeTraits::duration_type duration_type;
|
||||
#else
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_iostream without establishing a connection.
|
||||
basic_socket_iostream()
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This constructor automatically establishes a connection based on the
|
||||
* supplied resolver query parameters. The arguments are used to construct
|
||||
* a resolver query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
explicit basic_socket_iostream(T1 t1, ..., TN tn);
|
||||
#elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
explicit basic_socket_iostream(T... x)
|
||||
: std::basic_iostream<char>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_)
|
||||
{
|
||||
this->setf(std::ios_base::unitbuf);
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_CTR_DEF)
|
||||
#endif
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection to an endpoint corresponding to a resolver query.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
void connect(T1 t1, ..., TN tn);
|
||||
#elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
void connect(T... x)
|
||||
{
|
||||
if (rdbuf()->connect(x...) == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
#else
|
||||
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
void close()
|
||||
{
|
||||
if (rdbuf()->close() == 0)
|
||||
this->setstate(std::ios_base::failbit);
|
||||
}
|
||||
|
||||
/// Return a pointer to the underlying streambuf.
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* rdbuf() const
|
||||
{
|
||||
return const_cast<basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>*>(
|
||||
&this->detail::socket_iostream_base<
|
||||
Protocol, StreamSocketService, Time,
|
||||
TimeTraits, TimerService>::streambuf_);
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream.
|
||||
*
|
||||
* @par Example
|
||||
* To print the error associated with a failure to establish a connection:
|
||||
* @code tcp::iostream s("www.boost.org", "http");
|
||||
* if (!s)
|
||||
* {
|
||||
* std::cout << "Error: " << s.error().message() << std::endl;
|
||||
* } @endcode
|
||||
*/
|
||||
const boost::system::error_code& error() const
|
||||
{
|
||||
return rdbuf()->puberror();
|
||||
}
|
||||
|
||||
/// Get the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream's expiry time.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return rdbuf()->expires_at();
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_type& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_at(expiry_time);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream's expiry time.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return rdbuf()->expires_from_now();
|
||||
}
|
||||
|
||||
/// Set the stream's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
rdbuf()->expires_from_now(expiry_time);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef BOOST_ASIO_PRIVATE_CTR_DEF
|
||||
# undef BOOST_ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
|
||||
-569
@@ -1,569 +0,0 @@
|
||||
//
|
||||
// basic_socket_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
||||
#define BOOST_ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <streambuf>
|
||||
#include <boost/asio/basic_socket.hpp>
|
||||
#include <boost/asio/deadline_timer_service.hpp>
|
||||
#include <boost/asio/detail/array.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/stream_socket_service.hpp>
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
|
||||
# include <boost/asio/deadline_timer.hpp>
|
||||
#else
|
||||
# include <boost/asio/steady_timer.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
# include <boost/asio/detail/variadic_templates.hpp>
|
||||
|
||||
// A macro that should expand to:
|
||||
// template <typename T1, ..., typename Tn>
|
||||
// basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
// Time, TimeTraits, TimerService>* connect(
|
||||
// T1 x1, ..., Tn xn)
|
||||
// {
|
||||
// init_buffers();
|
||||
// this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
// typedef typename Protocol::resolver resolver_type;
|
||||
// typedef typename resolver_type::query resolver_query;
|
||||
// resolver_query query(x1, ..., xn);
|
||||
// resolve_and_connect(query);
|
||||
// return !ec_ ? this : 0;
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
|
||||
# define BOOST_ASIO_PRIVATE_CONNECT_DEF(n) \
|
||||
template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
|
||||
basic_socket_streambuf<Protocol, StreamSocketService, \
|
||||
Time, TimeTraits, TimerService>* connect(BOOST_ASIO_VARIADIC_PARAMS(n)) \
|
||||
{ \
|
||||
init_buffers(); \
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_); \
|
||||
typedef typename Protocol::resolver resolver_type; \
|
||||
typedef typename resolver_type::query resolver_query; \
|
||||
resolver_query query(BOOST_ASIO_VARIADIC_ARGS(n)); \
|
||||
resolve_and_connect(query); \
|
||||
return !ec_ ? this : 0; \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#endif // !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// A separate base class is used to ensure that the io_service is initialised
|
||||
// prior to the basic_socket_streambuf's basic_socket base class.
|
||||
class socket_streambuf_base
|
||||
{
|
||||
protected:
|
||||
io_service io_service_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// Iostream streambuf for a socket.
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol>,
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
|
||||
|| defined(GENERATING_DOCUMENTATION)
|
||||
typename Time = boost::posix_time::ptime,
|
||||
typename TimeTraits = boost::asio::time_traits<Time>,
|
||||
typename TimerService = deadline_timer_service<Time, TimeTraits> >
|
||||
#else
|
||||
typename Time = steady_timer::clock_type,
|
||||
typename TimeTraits = steady_timer::traits_type,
|
||||
typename TimerService = steady_timer::service_type>
|
||||
#endif
|
||||
class basic_socket_streambuf
|
||||
: public std::streambuf,
|
||||
private detail::socket_streambuf_base,
|
||||
public basic_socket<Protocol, StreamSocketService>
|
||||
{
|
||||
private:
|
||||
// These typedefs are intended keep this class's implementation independent
|
||||
// of whether it's using Boost.DateTime, Boost.Chrono or std::chrono.
|
||||
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
|
||||
typedef TimeTraits traits_helper;
|
||||
#else
|
||||
typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The time type.
|
||||
typedef typename TimeTraits::time_type time_type;
|
||||
|
||||
/// The duration type.
|
||||
typedef typename TimeTraits::duration_type duration_type;
|
||||
#else
|
||||
typedef typename traits_helper::time_type time_type;
|
||||
typedef typename traits_helper::duration_type duration_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_socket_streambuf without establishing a connection.
|
||||
basic_socket_streambuf()
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
this->detail::socket_streambuf_base::io_service_),
|
||||
unbuffered_(false),
|
||||
timer_service_(0),
|
||||
timer_state_(no_timer)
|
||||
{
|
||||
init_buffers();
|
||||
}
|
||||
|
||||
/// Destructor flushes buffered data.
|
||||
virtual ~basic_socket_streambuf()
|
||||
{
|
||||
if (pptr() != pbase())
|
||||
overflow(traits_type::eof());
|
||||
|
||||
destroy_timer();
|
||||
}
|
||||
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function establishes a connection to the specified endpoint.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* connect(
|
||||
const endpoint_type& endpoint)
|
||||
{
|
||||
init_buffers();
|
||||
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = boost::asio::error::operation_aborted;
|
||||
return 0;
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->basic_socket<Protocol, StreamSocketService>::async_connect(
|
||||
endpoint, handler);
|
||||
|
||||
ec_ = boost::asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == boost::asio::error::would_block);
|
||||
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// Establish a connection.
|
||||
/**
|
||||
* This function automatically establishes a connection based on the supplied
|
||||
* resolver query parameters. The arguments are used to construct a resolver
|
||||
* query object.
|
||||
*
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
template <typename T1, ..., typename TN>
|
||||
basic_socket_streambuf<Protocol, StreamSocketService>* connect(
|
||||
T1 t1, ..., TN tn);
|
||||
#elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename... T>
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* connect(T... x)
|
||||
{
|
||||
init_buffers();
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
typedef typename resolver_type::query resolver_query;
|
||||
resolver_query query(x...);
|
||||
resolve_and_connect(query);
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
#else
|
||||
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_CONNECT_DEF)
|
||||
#endif
|
||||
|
||||
/// Close the connection.
|
||||
/**
|
||||
* @return \c this if a connection was successfully established, a null
|
||||
* pointer otherwise.
|
||||
*/
|
||||
basic_socket_streambuf<Protocol, StreamSocketService,
|
||||
Time, TimeTraits, TimerService>* close()
|
||||
{
|
||||
sync();
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
if (!ec_)
|
||||
init_buffers();
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
const boost::system::error_code& puberror() const
|
||||
{
|
||||
return error();
|
||||
}
|
||||
|
||||
/// Get the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* @return An absolute time value representing the stream buffer's expiry
|
||||
* time.
|
||||
*/
|
||||
time_type expires_at() const
|
||||
{
|
||||
return timer_service_
|
||||
? timer_service_->expires_at(timer_implementation_)
|
||||
: time_type();
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the stream.
|
||||
*/
|
||||
void expires_at(const time_type& expiry_time)
|
||||
{
|
||||
construct_timer();
|
||||
|
||||
boost::system::error_code ec;
|
||||
timer_service_->expires_at(timer_implementation_, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_at");
|
||||
|
||||
start_timer();
|
||||
}
|
||||
|
||||
/// Get the stream buffer's expiry time relative to now.
|
||||
/**
|
||||
* @return A relative time value representing the stream buffer's expiry time.
|
||||
*/
|
||||
duration_type expires_from_now() const
|
||||
{
|
||||
return traits_helper::subtract(expires_at(), traits_helper::now());
|
||||
}
|
||||
|
||||
/// Set the stream buffer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time associated with the stream. Stream
|
||||
* operations performed after this time (where the operations cannot be
|
||||
* completed using the internal buffers) will fail with the error
|
||||
* boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*/
|
||||
void expires_from_now(const duration_type& expiry_time)
|
||||
{
|
||||
construct_timer();
|
||||
|
||||
boost::system::error_code ec;
|
||||
timer_service_->expires_from_now(timer_implementation_, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_from_now");
|
||||
|
||||
start_timer();
|
||||
}
|
||||
|
||||
protected:
|
||||
int_type underflow()
|
||||
{
|
||||
if (gptr() == egptr())
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = boost::asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_receive(this->get_implementation(),
|
||||
boost::asio::buffer(boost::asio::buffer(get_buffer_) + putback_max),
|
||||
0, handler);
|
||||
|
||||
ec_ = boost::asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == boost::asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
setg(&get_buffer_[0], &get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max + bytes_transferred_);
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
return traits_type::eof();
|
||||
}
|
||||
}
|
||||
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if (unbuffered_)
|
||||
{
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
{
|
||||
// Nothing to do.
|
||||
return traits_type::not_eof(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = boost::asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Send the single character immediately.
|
||||
char_type ch = traits_type::to_char_type(c);
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
boost::asio::buffer(&ch, sizeof(char_type)), 0, handler);
|
||||
|
||||
ec_ = boost::asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == boost::asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send all data in the output buffer.
|
||||
boost::asio::const_buffer buffer =
|
||||
boost::asio::buffer(pbase(), pptr() - pbase());
|
||||
while (boost::asio::buffer_size(buffer) > 0)
|
||||
{
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = boost::asio::error::operation_aborted;
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->get_service().async_send(this->get_implementation(),
|
||||
boost::asio::buffer(buffer), 0, handler);
|
||||
|
||||
ec_ = boost::asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == boost::asio::error::would_block);
|
||||
if (ec_)
|
||||
return traits_type::eof();
|
||||
|
||||
buffer = buffer + bytes_transferred_;
|
||||
}
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
|
||||
// If the new character is eof then our work here is done.
|
||||
if (traits_type::eq_int_type(c, traits_type::eof()))
|
||||
return traits_type::not_eof(c);
|
||||
|
||||
// Add the new character to the output buffer.
|
||||
*pptr() = traits_type::to_char_type(c);
|
||||
pbump(1);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int sync()
|
||||
{
|
||||
return overflow(traits_type::eof());
|
||||
}
|
||||
|
||||
std::streambuf* setbuf(char_type* s, std::streamsize n)
|
||||
{
|
||||
if (pptr() == pbase() && s == 0 && n == 0)
|
||||
{
|
||||
unbuffered_ = true;
|
||||
setp(0, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Get the last error associated with the stream buffer.
|
||||
/**
|
||||
* @return An \c error_code corresponding to the last error from the stream
|
||||
* buffer.
|
||||
*/
|
||||
virtual const boost::system::error_code& error() const
|
||||
{
|
||||
return ec_;
|
||||
}
|
||||
|
||||
private:
|
||||
void init_buffers()
|
||||
{
|
||||
setg(&get_buffer_[0],
|
||||
&get_buffer_[0] + putback_max,
|
||||
&get_buffer_[0] + putback_max);
|
||||
if (unbuffered_)
|
||||
setp(0, 0);
|
||||
else
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
}
|
||||
|
||||
template <typename ResolverQuery>
|
||||
void resolve_and_connect(const ResolverQuery& query)
|
||||
{
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
typedef typename resolver_type::iterator iterator_type;
|
||||
resolver_type resolver(detail::socket_streambuf_base::io_service_);
|
||||
iterator_type i = resolver.resolve(query, ec_);
|
||||
if (!ec_)
|
||||
{
|
||||
iterator_type end;
|
||||
ec_ = boost::asio::error::host_not_found;
|
||||
while (ec_ && i != end)
|
||||
{
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
|
||||
if (timer_state_ == timer_has_expired)
|
||||
{
|
||||
ec_ = boost::asio::error::operation_aborted;
|
||||
return;
|
||||
}
|
||||
|
||||
io_handler handler = { this };
|
||||
this->basic_socket<Protocol, StreamSocketService>::async_connect(
|
||||
*i, handler);
|
||||
|
||||
ec_ = boost::asio::error::would_block;
|
||||
this->get_service().get_io_service().reset();
|
||||
do this->get_service().get_io_service().run_one();
|
||||
while (ec_ == boost::asio::error::would_block);
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct io_handler;
|
||||
friend struct io_handler;
|
||||
struct io_handler
|
||||
{
|
||||
basic_socket_streambuf* this_;
|
||||
|
||||
void operator()(const boost::system::error_code& ec,
|
||||
std::size_t bytes_transferred = 0)
|
||||
{
|
||||
this_->ec_ = ec;
|
||||
this_->bytes_transferred_ = bytes_transferred;
|
||||
}
|
||||
};
|
||||
|
||||
struct timer_handler;
|
||||
friend struct timer_handler;
|
||||
struct timer_handler
|
||||
{
|
||||
basic_socket_streambuf* this_;
|
||||
|
||||
void operator()(const boost::system::error_code&)
|
||||
{
|
||||
time_type now = traits_helper::now();
|
||||
|
||||
time_type expiry_time = this_->timer_service_->expires_at(
|
||||
this_->timer_implementation_);
|
||||
|
||||
if (traits_helper::less_than(now, expiry_time))
|
||||
{
|
||||
this_->timer_state_ = timer_is_pending;
|
||||
this_->timer_service_->async_wait(this_->timer_implementation_, *this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this_->timer_state_ = timer_has_expired;
|
||||
boost::system::error_code ec;
|
||||
this_->basic_socket<Protocol, StreamSocketService>::close(ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void construct_timer()
|
||||
{
|
||||
if (timer_service_ == 0)
|
||||
{
|
||||
TimerService& timer_service = use_service<TimerService>(
|
||||
detail::socket_streambuf_base::io_service_);
|
||||
timer_service.construct(timer_implementation_);
|
||||
timer_service_ = &timer_service;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_timer()
|
||||
{
|
||||
if (timer_service_)
|
||||
timer_service_->destroy(timer_implementation_);
|
||||
}
|
||||
|
||||
void start_timer()
|
||||
{
|
||||
if (timer_state_ != timer_is_pending)
|
||||
{
|
||||
timer_handler handler = { this };
|
||||
handler(boost::system::error_code());
|
||||
}
|
||||
}
|
||||
|
||||
enum { putback_max = 8 };
|
||||
enum { buffer_size = 512 };
|
||||
boost::asio::detail::array<char, buffer_size> get_buffer_;
|
||||
boost::asio::detail::array<char, buffer_size> put_buffer_;
|
||||
bool unbuffered_;
|
||||
boost::system::error_code ec_;
|
||||
std::size_t bytes_transferred_;
|
||||
TimerService* timer_service_;
|
||||
typename TimerService::implementation_type timer_implementation_;
|
||||
enum state { no_timer, timer_is_pending, timer_has_expired } timer_state_;
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
# undef BOOST_ASIO_PRIVATE_CONNECT_DEF
|
||||
#endif // !defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_SOCKET_STREAMBUF_HPP
|
||||
-854
@@ -1,854 +0,0 @@
|
||||
//
|
||||
// basic_stream_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_STREAM_SOCKET_HPP
|
||||
#define BOOST_ASIO_BASIC_STREAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/asio/async_result.hpp>
|
||||
#include <boost/asio/basic_socket.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/stream_socket_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides stream-oriented socket functionality.
|
||||
/**
|
||||
* The basic_stream_socket class template provides asynchronous and blocking
|
||||
* stream-oriented socket functionality.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Concepts:
|
||||
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
|
||||
*/
|
||||
template <typename Protocol,
|
||||
typename StreamSocketService = stream_socket_service<Protocol> >
|
||||
class basic_stream_socket
|
||||
: public basic_socket<Protocol, StreamSocketService>
|
||||
{
|
||||
public:
|
||||
/// (Deprecated: Use native_handle_type.) The native representation of a
|
||||
/// socket.
|
||||
typedef typename StreamSocketService::native_handle_type native_type;
|
||||
|
||||
/// The native representation of a socket.
|
||||
typedef typename StreamSocketService::native_handle_type native_handle_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// Construct a basic_stream_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a stream socket without opening it. The socket
|
||||
* needs to be opened and then connected or accepted before data can be sent
|
||||
* or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_stream_socket(boost::asio::io_service& io_service)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_stream_socket.
|
||||
/**
|
||||
* This constructor creates and opens a stream socket. The socket needs to be
|
||||
* connected or accepted before data can be sent or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service, protocol)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a stream socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the stream
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(boost::asio::io_service& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: basic_socket<Protocol, StreamSocketService>(io_service, endpoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket on an existing native socket.
|
||||
/**
|
||||
* This constructor creates a stream socket object to hold an existing native
|
||||
* socket.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @param native_socket The new underlying socket implementation.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(boost::asio::io_service& io_service,
|
||||
const protocol_type& protocol, const native_handle_type& native_socket)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
io_service, protocol, native_socket)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
/// Move-construct a basic_stream_socket from another.
|
||||
/**
|
||||
* This constructor moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_stream_socket(basic_stream_socket&& other)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST(basic_stream_socket)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_stream_socket from another.
|
||||
/**
|
||||
* This assignment operator moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
basic_stream_socket& operator=(basic_stream_socket&& other)
|
||||
{
|
||||
basic_socket<Protocol, StreamSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST(basic_stream_socket)(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Move-construct a basic_stream_socket from a socket of another protocol
|
||||
/// type.
|
||||
/**
|
||||
* This constructor moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename StreamSocketService1>
|
||||
basic_stream_socket(
|
||||
basic_stream_socket<Protocol1, StreamSocketService1>&& other,
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value>::type* = 0)
|
||||
: basic_socket<Protocol, StreamSocketService>(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_stream_socket<
|
||||
Protocol1, StreamSocketService1>)(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assign a basic_stream_socket from a socket of another protocol type.
|
||||
/**
|
||||
* This assignment operator moves a stream socket from one object to another.
|
||||
*
|
||||
* @param other The other basic_stream_socket object from which the move
|
||||
* will occur.
|
||||
*
|
||||
* @note Following the move, the moved-from object is in the same state as if
|
||||
* constructed using the @c basic_stream_socket(io_service&) constructor.
|
||||
*/
|
||||
template <typename Protocol1, typename StreamSocketService1>
|
||||
typename enable_if<is_convertible<Protocol1, Protocol>::value,
|
||||
basic_stream_socket>::type& operator=(
|
||||
basic_stream_socket<Protocol1, StreamSocketService1>&& other)
|
||||
{
|
||||
basic_socket<Protocol, StreamSocketService>::operator=(
|
||||
BOOST_ASIO_MOVE_CAST2(basic_stream_socket<
|
||||
Protocol1, StreamSocketService1>)(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.send(boost::asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "send");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
/**
|
||||
* This function is used to send data on the stream socket. The function
|
||||
* call will block until one or more bytes of the data has been sent
|
||||
* successfully, or an until error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes sent. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref write function if you need to ensure that all data
|
||||
* is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, 0,
|
||||
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
/**
|
||||
* This function is used to asynchronously send data on the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be sent on the socket. Although
|
||||
* the buffers object may be copied as necessary, ownership of the underlying
|
||||
* memory blocks is retained by the caller, which must guarantee that they
|
||||
* remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the send call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the send operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes sent.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The send operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To send a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_send(boost::asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on sending multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_send(const ConstBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(
|
||||
this->get_implementation(), buffers, flags,
|
||||
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.receive(boost::asio::buffer(data, size), 0);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
boost::asio::detail::throw_error(ec, "receive");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
/**
|
||||
* This function is used to receive data on the stream socket. The function
|
||||
* call will block until one or more bytes of data has been received
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes received. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that the
|
||||
* requested amount of data is read before the blocking operation completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags, boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, flags, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the stream
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
* that the requested amount of data is received before the asynchronous
|
||||
* operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
/**
|
||||
* This function is used to asynchronously receive data from the stream
|
||||
* socket. The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be received.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param flags Flags specifying how the receive call is to be made.
|
||||
*
|
||||
* @param handler The handler to be called when the receive operation
|
||||
* completes. Copies will be made of the handler as required. The function
|
||||
* signature of the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes received.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The receive operation may not receive all of the requested number of
|
||||
* bytes. Consider using the @ref async_read function if you need to ensure
|
||||
* that the requested amount of data is received before the asynchronous
|
||||
* operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To receive into a single data buffer use the @ref buffer function as
|
||||
* follows:
|
||||
* @code
|
||||
* socket.async_receive(boost::asio::buffer(data, size), 0, handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on receiving into
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_receive(const MutableBufferSequence& buffers,
|
||||
socket_base::message_flags flags,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, flags, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
/**
|
||||
* This function is used to write data to the stream socket. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
*
|
||||
* @returns The number of bytes written.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.write_some(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().send(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "write_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
/**
|
||||
* This function is used to write data to the stream socket. The function call
|
||||
* will block until one or more bytes of the data has been written
|
||||
* successfully, or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes written. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The write_some operation may not transmit all of the data to the
|
||||
* peer. Consider using the @ref write function if you need to ensure that
|
||||
* all data is written before the blocking operation completes.
|
||||
*/
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some(const ConstBufferSequence& buffers,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().send(this->get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
/**
|
||||
* This function is used to asynchronously write data to the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more data buffers to be written to the socket.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the write operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes written.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The write operation may not transmit all of the data to the peer.
|
||||
* Consider using the @ref async_write function if you need to ensure that all
|
||||
* data is written before the asynchronous operation completes.
|
||||
*
|
||||
* @par Example
|
||||
* To write a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_write_some(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on writing multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_write_some(const ConstBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WriteHandler.
|
||||
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_send(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
/**
|
||||
* This function is used to read data from the stream socket. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure. An error code of
|
||||
* boost::asio::error::eof indicates that the connection was closed by the
|
||||
* peer.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.read_some(boost::asio::buffer(data, size));
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
boost::asio::detail::throw_error(ec, "read_some");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
/**
|
||||
* This function is used to read data from the stream socket. The function
|
||||
* call will block until one or more bytes of data has been read successfully,
|
||||
* or until an error occurs.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @returns The number of bytes read. Returns 0 if an error occurred.
|
||||
*
|
||||
* @note The read_some operation may not read all of the requested number of
|
||||
* bytes. Consider using the @ref read function if you need to ensure that
|
||||
* the requested amount of data is read before the blocking operation
|
||||
* completes.
|
||||
*/
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some(const MutableBufferSequence& buffers,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->get_service().receive(
|
||||
this->get_implementation(), buffers, 0, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
/**
|
||||
* This function is used to asynchronously read data from the stream socket.
|
||||
* The function call always returns immediately.
|
||||
*
|
||||
* @param buffers One or more buffers into which the data will be read.
|
||||
* Although the buffers object may be copied as necessary, ownership of the
|
||||
* underlying memory blocks is retained by the caller, which must guarantee
|
||||
* that they remain valid until the handler is called.
|
||||
*
|
||||
* @param handler The handler to be called when the read operation completes.
|
||||
* Copies will be made of the handler as required. The function signature of
|
||||
* the handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error, // Result of operation.
|
||||
* std::size_t bytes_transferred // Number of bytes read.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*
|
||||
* @note The read operation may not read all of the requested number of bytes.
|
||||
* Consider using the @ref async_read function if you need to ensure that the
|
||||
* requested amount of data is read before the asynchronous operation
|
||||
* completes.
|
||||
*
|
||||
* @par Example
|
||||
* To read into a single data buffer use the @ref buffer function as follows:
|
||||
* @code
|
||||
* socket.async_read_some(boost::asio::buffer(data, size), handler);
|
||||
* @endcode
|
||||
* See the @ref buffer documentation for information on reading into multiple
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
void (boost::system::error_code, std::size_t))
|
||||
async_read_some(const MutableBufferSequence& buffers,
|
||||
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a ReadHandler.
|
||||
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
return this->get_service().async_receive(this->get_implementation(),
|
||||
buffers, 0, BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_STREAM_SOCKET_HPP
|
||||
Vendored
-371
@@ -1,371 +0,0 @@
|
||||
//
|
||||
// basic_streambuf.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_STREAMBUF_HPP
|
||||
#define BOOST_ASIO_BASIC_STREAMBUF_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include <boost/asio/basic_streambuf_fwd.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/detail/limits.hpp>
|
||||
#include <boost/asio/detail/noncopyable.hpp>
|
||||
#include <boost/asio/detail/throw_exception.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Automatically resizable buffer class based on std::streambuf.
|
||||
/**
|
||||
* The @c basic_streambuf class is derived from @c std::streambuf to associate
|
||||
* the streambuf's input and output sequences with one or more character
|
||||
* arrays. These character arrays are internal to the @c basic_streambuf
|
||||
* object, but direct access to the array elements is provided to permit them
|
||||
* to be used efficiently with I/O operations. Characters written to the output
|
||||
* sequence of a @c basic_streambuf object are appended to the input sequence
|
||||
* of the same object.
|
||||
*
|
||||
* The @c basic_streambuf class's public interface is intended to permit the
|
||||
* following implementation strategies:
|
||||
*
|
||||
* @li A single contiguous character array, which is reallocated as necessary
|
||||
* to accommodate changes in the size of the character sequence. This is the
|
||||
* implementation approach currently used in Asio.
|
||||
*
|
||||
* @li A sequence of one or more character arrays, where each array is of the
|
||||
* same size. Additional character array objects are appended to the sequence
|
||||
* to accommodate changes in the size of the character sequence.
|
||||
*
|
||||
* @li A sequence of one or more character arrays of varying sizes. Additional
|
||||
* character array objects are appended to the sequence to accommodate changes
|
||||
* in the size of the character sequence.
|
||||
*
|
||||
* The constructor for basic_streambuf accepts a @c size_t argument specifying
|
||||
* the maximum of the sum of the sizes of the input sequence and output
|
||||
* sequence. During the lifetime of the @c basic_streambuf object, the following
|
||||
* invariant holds:
|
||||
* @code size() <= max_size()@endcode
|
||||
* Any member function that would, if successful, cause the invariant to be
|
||||
* violated shall throw an exception of class @c std::length_error.
|
||||
*
|
||||
* The constructor for @c basic_streambuf takes an Allocator argument. A copy
|
||||
* of this argument is used for any memory allocation performed, by the
|
||||
* constructor and by all member functions, during the lifetime of each @c
|
||||
* basic_streambuf object.
|
||||
*
|
||||
* @par Examples
|
||||
* Writing directly from an streambuf to a socket:
|
||||
* @code
|
||||
* boost::asio::streambuf b;
|
||||
* std::ostream os(&b);
|
||||
* os << "Hello, World!\n";
|
||||
*
|
||||
* // try sending some data in input sequence
|
||||
* size_t n = sock.send(b.data());
|
||||
*
|
||||
* b.consume(n); // sent data is removed from input sequence
|
||||
* @endcode
|
||||
*
|
||||
* Reading from a socket directly into a streambuf:
|
||||
* @code
|
||||
* boost::asio::streambuf b;
|
||||
*
|
||||
* // reserve 512 bytes in output sequence
|
||||
* boost::asio::streambuf::mutable_buffers_type bufs = b.prepare(512);
|
||||
*
|
||||
* size_t n = sock.receive(bufs);
|
||||
*
|
||||
* // received data is "committed" from output sequence to input sequence
|
||||
* b.commit(n);
|
||||
*
|
||||
* std::istream is(&b);
|
||||
* std::string s;
|
||||
* is >> s;
|
||||
* @endcode
|
||||
*/
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
#else
|
||||
template <typename Allocator>
|
||||
#endif
|
||||
class basic_streambuf
|
||||
: public std::streambuf,
|
||||
private noncopyable
|
||||
{
|
||||
public:
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
typedef implementation_defined const_buffers_type;
|
||||
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
typedef implementation_defined mutable_buffers_type;
|
||||
#else
|
||||
typedef boost::asio::const_buffers_1 const_buffers_type;
|
||||
typedef boost::asio::mutable_buffers_1 mutable_buffers_type;
|
||||
#endif
|
||||
|
||||
/// Construct a basic_streambuf object.
|
||||
/**
|
||||
* Constructs a streambuf with the specified maximum size. The initial size
|
||||
* of the streambuf's input sequence is 0.
|
||||
*/
|
||||
explicit basic_streambuf(
|
||||
std::size_t maximum_size = (std::numeric_limits<std::size_t>::max)(),
|
||||
const Allocator& allocator = Allocator())
|
||||
: max_size_(maximum_size),
|
||||
buffer_(allocator)
|
||||
{
|
||||
std::size_t pend = (std::min<std::size_t>)(max_size_, buffer_delta);
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0]);
|
||||
setp(&buffer_[0], &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
/// Get the size of the input sequence.
|
||||
/**
|
||||
* @returns The size of the input sequence. The value is equal to that
|
||||
* calculated for @c s in the following code:
|
||||
* @code
|
||||
* size_t s = 0;
|
||||
* const_buffers_type bufs = data();
|
||||
* const_buffers_type::const_iterator i = bufs.begin();
|
||||
* while (i != bufs.end())
|
||||
* {
|
||||
* const_buffer buf(*i++);
|
||||
* s += buffer_size(buf);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
std::size_t size() const
|
||||
{
|
||||
return pptr() - gptr();
|
||||
}
|
||||
|
||||
/// Get the maximum size of the basic_streambuf.
|
||||
/**
|
||||
* @returns The allowed maximum of the sum of the sizes of the input sequence
|
||||
* and output sequence.
|
||||
*/
|
||||
std::size_t max_size() const
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the input sequence.
|
||||
/**
|
||||
* @returns An object of type @c const_buffers_type that satisfies
|
||||
* ConstBufferSequence requirements, representing all character arrays in the
|
||||
* input sequence.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
const_buffers_type data() const
|
||||
{
|
||||
return boost::asio::buffer(boost::asio::const_buffer(gptr(),
|
||||
(pptr() - gptr()) * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Get a list of buffers that represents the output sequence, with the given
|
||||
/// size.
|
||||
/**
|
||||
* Ensures that the output sequence can accommodate @c n characters,
|
||||
* reallocating character array objects as necessary.
|
||||
*
|
||||
* @returns An object of type @c mutable_buffers_type that satisfies
|
||||
* MutableBufferSequence requirements, representing character array objects
|
||||
* at the start of the output sequence such that the sum of the buffer sizes
|
||||
* is @c n.
|
||||
*
|
||||
* @throws std::length_error If <tt>size() + n > max_size()</tt>.
|
||||
*
|
||||
* @note The returned object is invalidated by any @c basic_streambuf member
|
||||
* function that modifies the input sequence or output sequence.
|
||||
*/
|
||||
mutable_buffers_type prepare(std::size_t n)
|
||||
{
|
||||
reserve(n);
|
||||
return boost::asio::buffer(boost::asio::mutable_buffer(
|
||||
pptr(), n * sizeof(char_type)));
|
||||
}
|
||||
|
||||
/// Move characters from the output sequence to the input sequence.
|
||||
/**
|
||||
* Appends @c n characters from the start of the output sequence to the input
|
||||
* sequence. The beginning of the output sequence is advanced by @c n
|
||||
* characters.
|
||||
*
|
||||
* Requires a preceding call <tt>prepare(x)</tt> where <tt>x >= n</tt>, and
|
||||
* no intervening operations that modify the input or output sequence.
|
||||
*
|
||||
* @note If @c n is greater than the size of the output sequence, the entire
|
||||
* output sequence is moved to the input sequence and no error is issued.
|
||||
*/
|
||||
void commit(std::size_t n)
|
||||
{
|
||||
if (pptr() + n > epptr())
|
||||
n = epptr() - pptr();
|
||||
pbump(static_cast<int>(n));
|
||||
setg(eback(), gptr(), pptr());
|
||||
}
|
||||
|
||||
/// Remove characters from the input sequence.
|
||||
/**
|
||||
* Removes @c n characters from the beginning of the input sequence.
|
||||
*
|
||||
* @note If @c n is greater than the size of the input sequence, the entire
|
||||
* input sequence is consumed and no error is issued.
|
||||
*/
|
||||
void consume(std::size_t n)
|
||||
{
|
||||
if (egptr() < pptr())
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
if (gptr() + n > pptr())
|
||||
n = pptr() - gptr();
|
||||
gbump(static_cast<int>(n));
|
||||
}
|
||||
|
||||
protected:
|
||||
enum { buffer_delta = 128 };
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::underflow().
|
||||
*/
|
||||
int_type underflow()
|
||||
{
|
||||
if (gptr() < pptr())
|
||||
{
|
||||
setg(&buffer_[0], gptr(), pptr());
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
return traits_type::eof();
|
||||
}
|
||||
}
|
||||
|
||||
/// Override std::streambuf behaviour.
|
||||
/**
|
||||
* Behaves according to the specification of @c std::streambuf::overflow(),
|
||||
* with the specialisation that @c std::length_error is thrown if appending
|
||||
* the character to the input sequence would require the condition
|
||||
* <tt>size() > max_size()</tt> to be true.
|
||||
*/
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if (!traits_type::eq_int_type(c, traits_type::eof()))
|
||||
{
|
||||
if (pptr() == epptr())
|
||||
{
|
||||
std::size_t buffer_size = pptr() - gptr();
|
||||
if (buffer_size < max_size_ && max_size_ - buffer_size < buffer_delta)
|
||||
{
|
||||
reserve(max_size_ - buffer_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
reserve(buffer_delta);
|
||||
}
|
||||
}
|
||||
|
||||
*pptr() = traits_type::to_char_type(c);
|
||||
pbump(1);
|
||||
return c;
|
||||
}
|
||||
|
||||
return traits_type::not_eof(c);
|
||||
}
|
||||
|
||||
void reserve(std::size_t n)
|
||||
{
|
||||
// Get current stream positions as offsets.
|
||||
std::size_t gnext = gptr() - &buffer_[0];
|
||||
std::size_t pnext = pptr() - &buffer_[0];
|
||||
std::size_t pend = epptr() - &buffer_[0];
|
||||
|
||||
// Check if there is already enough space in the put area.
|
||||
if (n <= pend - pnext)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift existing contents of get area to start of buffer.
|
||||
if (gnext > 0)
|
||||
{
|
||||
pnext -= gnext;
|
||||
std::memmove(&buffer_[0], &buffer_[0] + gnext, pnext);
|
||||
}
|
||||
|
||||
// Ensure buffer is large enough to hold at least the specified size.
|
||||
if (n > pend - pnext)
|
||||
{
|
||||
if (n <= max_size_ && pnext <= max_size_ - n)
|
||||
{
|
||||
pend = pnext + n;
|
||||
buffer_.resize((std::max<std::size_t>)(pend, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::length_error ex("boost::asio::streambuf too long");
|
||||
boost::asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Update stream positions.
|
||||
setg(&buffer_[0], &buffer_[0], &buffer_[0] + pnext);
|
||||
setp(&buffer_[0] + pnext, &buffer_[0] + pend);
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t max_size_;
|
||||
std::vector<char_type, Allocator> buffer_;
|
||||
|
||||
// Helper function to get the preferred size for reading data.
|
||||
friend std::size_t read_size_helper(
|
||||
basic_streambuf& sb, std::size_t max_size)
|
||||
{
|
||||
return std::min<std::size_t>(
|
||||
std::max<std::size_t>(512, sb.buffer_.capacity() - sb.size()),
|
||||
std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to get the preferred size for reading data. Used for any
|
||||
// user-provided specialisations of basic_streambuf.
|
||||
template <typename Allocator>
|
||||
inline std::size_t read_size_helper(
|
||||
basic_streambuf<Allocator>& sb, std::size_t max_size)
|
||||
{
|
||||
return std::min<std::size_t>(512,
|
||||
std::min<std::size_t>(max_size, sb.max_size() - sb.size()));
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_STREAMBUF_HPP
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// basic_streambuf_fwd.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_STREAMBUF_FWD_HPP
|
||||
#define BOOST_ASIO_BASIC_STREAMBUF_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
|
||||
#if !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
template <typename Allocator = std::allocator<char> >
|
||||
class basic_streambuf;
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_STREAMBUF_FWD_HPP
|
||||
-521
@@ -1,521 +0,0 @@
|
||||
//
|
||||
// basic_waitable_timer.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// 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 BOOST_ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
#define BOOST_ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <boost/asio/detail/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/asio/basic_io_object.hpp>
|
||||
#include <boost/asio/detail/handler_type_requirements.hpp>
|
||||
#include <boost/asio/detail/throw_error.hpp>
|
||||
#include <boost/asio/error.hpp>
|
||||
#include <boost/asio/wait_traits.hpp>
|
||||
#include <boost/asio/waitable_timer_service.hpp>
|
||||
|
||||
#include <boost/asio/detail/push_options.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
|
||||
/// Provides waitable timer functionality.
|
||||
/**
|
||||
* The basic_waitable_timer class template provides the ability to perform a
|
||||
* blocking or asynchronous wait for a timer to expire.
|
||||
*
|
||||
* A waitable timer is always in one of two states: "expired" or "not expired".
|
||||
* If the wait() or async_wait() function is called on an expired timer, the
|
||||
* wait operation will complete immediately.
|
||||
*
|
||||
* Most applications will use one of the boost::asio::steady_timer,
|
||||
* boost::asio::system_timer or boost::asio::high_resolution_timer typedefs.
|
||||
*
|
||||
* @note This waitable timer functionality is for use with the C++11 standard
|
||||
* library's @c <chrono> facility, or with the Boost.Chrono library.
|
||||
*
|
||||
* @par Thread Safety
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
*
|
||||
* @par Examples
|
||||
* Performing a blocking wait (C++11):
|
||||
* @code
|
||||
* // Construct a timer without setting an expiry time.
|
||||
* boost::asio::steady_timer timer(io_service);
|
||||
*
|
||||
* // Set an expiry time relative to now.
|
||||
* timer.expires_from_now(std::chrono::seconds(5));
|
||||
*
|
||||
* // Wait for the timer to expire.
|
||||
* timer.wait();
|
||||
* @endcode
|
||||
*
|
||||
* @par
|
||||
* Performing an asynchronous wait (C++11):
|
||||
* @code
|
||||
* void handler(const boost::system::error_code& error)
|
||||
* {
|
||||
* if (!error)
|
||||
* {
|
||||
* // Timer expired.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* // Construct a timer with an absolute expiry time.
|
||||
* boost::asio::steady_timer timer(io_service,
|
||||
* std::chrono::steady_clock::now() + std::chrono::seconds(60));
|
||||
*
|
||||
* // Start an asynchronous wait.
|
||||
* timer.async_wait(handler);
|
||||
* @endcode
|
||||
*
|
||||
* @par Changing an active waitable timer's expiry time
|
||||
*
|
||||
* Changing the expiry time of a timer while there are pending asynchronous
|
||||
* waits causes those wait operations to be cancelled. To ensure that the action
|
||||
* associated with the timer is performed only once, use something like this:
|
||||
* used:
|
||||
*
|
||||
* @code
|
||||
* void on_some_event()
|
||||
* {
|
||||
* if (my_timer.expires_from_now(seconds(5)) > 0)
|
||||
* {
|
||||
* // We managed to cancel the timer. Start new asynchronous wait.
|
||||
* my_timer.async_wait(on_timeout);
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Too late, timer has already expired!
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void on_timeout(const boost::system::error_code& e)
|
||||
* {
|
||||
* if (e != boost::asio::error::operation_aborted)
|
||||
* {
|
||||
* // Timer was not cancelled, take necessary action.
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @li The boost::asio::basic_waitable_timer::expires_from_now() function
|
||||
* cancels any pending asynchronous waits, and returns the number of
|
||||
* asynchronous waits that were cancelled. If it returns 0 then you were too
|
||||
* late and the wait handler has already been executed, or will soon be
|
||||
* executed. If it returns 1 then the wait handler was successfully cancelled.
|
||||
*
|
||||
* @li If a wait handler is cancelled, the boost::system::error_code passed to
|
||||
* it contains the value boost::asio::error::operation_aborted.
|
||||
*/
|
||||
template <typename Clock,
|
||||
typename WaitTraits = boost::asio::wait_traits<Clock>,
|
||||
typename WaitableTimerService = waitable_timer_service<Clock, WaitTraits> >
|
||||
class basic_waitable_timer
|
||||
: public basic_io_object<WaitableTimerService>
|
||||
{
|
||||
public:
|
||||
/// The clock type.
|
||||
typedef Clock clock_type;
|
||||
|
||||
/// The duration type of the clock.
|
||||
typedef typename clock_type::duration duration;
|
||||
|
||||
/// The time point type of the clock.
|
||||
typedef typename clock_type::time_point time_point;
|
||||
|
||||
/// The wait traits type.
|
||||
typedef WaitTraits traits_type;
|
||||
|
||||
/// Constructor.
|
||||
/**
|
||||
* This constructor creates a timer without setting an expiry time. The
|
||||
* expires_at() or expires_from_now() functions must be called to set an
|
||||
* expiry time before the timer can be waited on.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*/
|
||||
explicit basic_waitable_timer(boost::asio::io_service& io_service)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time as an absolute time.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, expressed
|
||||
* as an absolute time.
|
||||
*/
|
||||
basic_waitable_timer(boost::asio::io_service& io_service,
|
||||
const time_point& expiry_time)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_at");
|
||||
}
|
||||
|
||||
/// Constructor to set a particular expiry time relative to now.
|
||||
/**
|
||||
* This constructor creates a timer and sets the expiry time.
|
||||
*
|
||||
* @param io_service The io_service object that the timer will use to dispatch
|
||||
* handlers for any asynchronous operations performed on the timer.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer, relative to
|
||||
* now.
|
||||
*/
|
||||
basic_waitable_timer(boost::asio::io_service& io_service,
|
||||
const duration& expiry_time)
|
||||
: basic_io_object<WaitableTimerService>(io_service)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.expires_from_now(this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_from_now");
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.cancel(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancel any asynchronous operations that are waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of any pending asynchronous wait
|
||||
* operations against the timer. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when cancel() is called, then the
|
||||
* handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.cancel(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.cancel_one(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "cancel_one");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Cancels one asynchronous operation that is waiting on the timer.
|
||||
/**
|
||||
* This function forces the completion of one pending asynchronous wait
|
||||
* operation against the timer. Handlers are cancelled in FIFO order. The
|
||||
* handler for the cancelled operation will be invoked with the
|
||||
* boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* Cancelling the timer does not change the expiry time.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled. That is,
|
||||
* either 0 or 1.
|
||||
*
|
||||
* @note If the timer has already expired when cancel_one() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t cancel_one(boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.cancel_one(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
time_point expires_at() const
|
||||
{
|
||||
return this->service.expires_at(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.expires_at(
|
||||
this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_at");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time as an absolute time.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_at() is called, then
|
||||
* the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_at(const time_point& expiry_time,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.expires_at(this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Get the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function may be used to obtain the timer's current expiry time.
|
||||
* Whether the timer has expired or not does not affect this value.
|
||||
*/
|
||||
duration expires_from_now() const
|
||||
{
|
||||
return this->service.expires_from_now(this->implementation);
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
std::size_t s = this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
boost::asio::detail::throw_error(ec, "expires_from_now");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Set the timer's expiry time relative to now.
|
||||
/**
|
||||
* This function sets the expiry time. Any pending asynchronous wait
|
||||
* operations will be cancelled. The handler for each cancelled operation will
|
||||
* be invoked with the boost::asio::error::operation_aborted error code.
|
||||
*
|
||||
* @param expiry_time The expiry time to be used for the timer.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*
|
||||
* @return The number of asynchronous operations that were cancelled.
|
||||
*
|
||||
* @note If the timer has already expired when expires_from_now() is called,
|
||||
* then the handlers for asynchronous wait operations will:
|
||||
*
|
||||
* @li have already been invoked; or
|
||||
*
|
||||
* @li have been queued for invocation in the near future.
|
||||
*
|
||||
* These handlers can no longer be cancelled, and therefore are passed an
|
||||
* error code that indicates the successful completion of the wait operation.
|
||||
*/
|
||||
std::size_t expires_from_now(const duration& expiry_time,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
return this->service.expires_from_now(
|
||||
this->implementation, expiry_time, ec);
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @throws boost::system::system_error Thrown on failure.
|
||||
*/
|
||||
void wait()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
this->service.wait(this->implementation, ec);
|
||||
boost::asio::detail::throw_error(ec, "wait");
|
||||
}
|
||||
|
||||
/// Perform a blocking wait on the timer.
|
||||
/**
|
||||
* This function is used to wait for the timer to expire. This function
|
||||
* blocks and does not return until the timer has expired.
|
||||
*
|
||||
* @param ec Set to indicate what error occurred, if any.
|
||||
*/
|
||||
void wait(boost::system::error_code& ec)
|
||||
{
|
||||
this->service.wait(this->implementation, ec);
|
||||
}
|
||||
|
||||
/// Start an asynchronous wait on the timer.
|
||||
/**
|
||||
* This function may be used to initiate an asynchronous wait against the
|
||||
* timer. It always returns immediately.
|
||||
*
|
||||
* For each call to async_wait(), the supplied handler will be called exactly
|
||||
* once. The handler will be called when:
|
||||
*
|
||||
* @li The timer has expired.
|
||||
*
|
||||
* @li The timer was cancelled, in which case the handler is passed the error
|
||||
* code boost::asio::error::operation_aborted.
|
||||
*
|
||||
* @param handler The handler to be called when the timer expires. Copies
|
||||
* will be made of the handler as required. The function signature of the
|
||||
* handler must be:
|
||||
* @code void handler(
|
||||
* const boost::system::error_code& error // Result of operation.
|
||||
* ); @endcode
|
||||
* Regardless of whether the asynchronous operation completes immediately or
|
||||
* not, the handler will not be invoked from within this function. Invocation
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* boost::asio::io_service::post().
|
||||
*/
|
||||
template <typename WaitHandler>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
||||
void (boost::system::error_code))
|
||||
async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
|
||||
{
|
||||
// If you get an error on the following line it means that your handler does
|
||||
// not meet the documented type requirements for a WaitHandler.
|
||||
BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
|
||||
|
||||
return this->service.async_wait(this->implementation,
|
||||
BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace asio
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/asio/detail/pop_options.hpp>
|
||||
|
||||
#endif // BOOST_ASIO_BASIC_WAITABLE_TIMER_HPP
|
||||
Vendored
-2241
File diff suppressed because it is too large.
Load diff
Loaded 100 of 2867 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user