zmqpp 4.1.2
C++ bindings for 0mq (libzmq)
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * This file is part of zmqpp.
7 * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file.
8 */
9
17#ifndef ZMQPP_CONTEXT_HPP_
18#define ZMQPP_CONTEXT_HPP_
19
20#include <cassert>
21
22#include <zmq.h>
23
24#include "compatibility.hpp"
25#include "exception.hpp"
26#if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2))
27#include "context_options.hpp"
28#endif
29
30namespace zmqpp
31{
32
47{
48public:
49
50#if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2))
63 context(int const& threads = 1)
64#else
73#endif
74 : _context(nullptr)
75 {
76#if (ZMQ_VERSION_MAJOR < 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR < 2))
77 _context = zmq_init(threads);
78#else
79 _context = zmq_ctx_new();
80#endif
81
82 if (nullptr == _context)
83 {
85 }
86 }
87
97 {
98 if (nullptr != _context)
99 {
100 terminate();
101 }
102 }
103
112 : _context(source._context)
113 {
114 source._context = nullptr;
115 }
116
125 {
126 std::swap( _context, source._context );
127 return *this;
128 }
129
138 void terminate();
139
140#if (ZMQ_VERSION_MAJOR > 3) || ((ZMQ_VERSION_MAJOR == 3) && (ZMQ_VERSION_MINOR >= 2))
147 void set(context_option const option, int const value);
148
155 int get(context_option const option);
156#endif
157
168 operator bool() const NOEXCEPT
169 {
170 return nullptr != _context;
171 }
172
178 operator void*() const NOEXCEPT
179 {
180 return _context;
181 }
182
183private:
184 void* _context;
185
186 // No copy - private and not implemented
189};
190
191}
192
193#endif /* ZMQPP_CONTEXT_HPP_ */
The context class represents internal zmq context and io threads.
Definition context.hpp:47
context(context const &) ZMQPP_EXPLICITLY_DELETED
context & operator=(context &&source) NOEXCEPT
Move supporting operator.
Definition context.hpp:124
context()
Initialise the 0mq context.
Definition context.hpp:72
context & operator=(context const &) NOEXCEPT ZMQPP_EXPLICITLY_DELETED
~context() NOEXCEPT
Closes the 0mq context.
Definition context.hpp:96
context(context &&source) NOEXCEPT
Move supporting constructor.
Definition context.hpp:111
void * _context
Definition context.hpp:184
Represents internal zmq errors.
Definition exception.hpp:103
#define NOEXCEPT
Definition compatibility.hpp:122
#define ZMQPP_EXPORT
Definition compatibility.hpp:39
#define ZMQPP_EXPLICITLY_DELETED
Definition compatibility.hpp:107
C++ wrapper around zmq.
Definition actor.cpp:30