Commit 3aca691e authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Mark chan<T> IO methods as const

chan<T> is a pointer type and e.g. send does not change the pointer - it
only "modifies" channel buffer. Marking appropriate methods as const is
needed so that `const chan<T>` could be used to send/receive the same
way as `chan <T>` is used.
parent 176a3feb
...@@ -70,28 +70,28 @@ cdef extern from "golang/libgolang.h" namespace "golang" nogil: ...@@ -70,28 +70,28 @@ cdef extern from "golang/libgolang.h" namespace "golang" nogil:
chan(); chan();
# send/recv/close # send/recv/close
void send(const T&) void send(const T&) const
T recv() T recv() const
pair[T, cbool] recv_() pair[T, cbool] recv_() const
void close() void close() const
# send/recv in select # send/recv in select
_selcase sends(const T *ptx) _selcase sends(const T *ptx) const
_selcase recvs() _selcase recvs() const
_selcase recvs(T* prx) _selcase recvs(T* prx) const
_selcase recvs(T* prx, cbool *pok) _selcase recvs(T* prx, cbool *pok) const
# length/capacity # length/capacity
unsigned len() unsigned len() const
unsigned cap() unsigned cap() const
# compare wrt nil; =nil # compare wrt nil; =nil
cbool operator==(nullptr_t) cbool operator==(nullptr_t) const
cbool operator!=(nullptr_t) cbool operator!=(nullptr_t) const
void operator=(nullptr_t) void operator=(nullptr_t)
# for tests # for tests
_chan *_rawchan() _chan *_rawchan() const
chan[T] makechan[T]() chan[T] makechan[T]()
chan[T] makechan[T](unsigned size) chan[T] makechan[T](unsigned size)
......
...@@ -316,39 +316,39 @@ public: ...@@ -316,39 +316,39 @@ public:
static_assert(std::is_trivially_copyable<T>::value, "TODO chan<T>: T copy is not trivial"); static_assert(std::is_trivially_copyable<T>::value, "TODO chan<T>: T copy is not trivial");
// send/recv/close // send/recv/close
inline void send(const T &ptx) { _chansend(_ch, &ptx); } inline void send(const T &ptx) const { _chansend(_ch, &ptx); }
inline T recv() { T rx; _chanrecv(_ch, &rx); return rx; } inline T recv() const { T rx; _chanrecv(_ch, &rx); return rx; }
inline std::pair<T,bool> recv_() { T rx; bool ok = _chanrecv_(_ch, &rx); inline std::pair<T,bool> recv_() const { T rx; bool ok = _chanrecv_(_ch, &rx);
return std::make_pair(rx, ok); } return std::make_pair(rx, ok); }
inline void close() { _chanclose(_ch); } inline void close() const { _chanclose(_ch); }
// send/recv in select // send/recv in select
// ch.sends creates `ch.send(*ptx)` case for select. // ch.sends creates `ch.send(*ptx)` case for select.
[[nodiscard]] inline _selcase sends(const T *ptx) { return _selsend(_ch, ptx); } [[nodiscard]] inline _selcase sends(const T *ptx) const { return _selsend(_ch, ptx); }
// ch.recvs creates `*prx = ch.recv()` case for select. // ch.recvs creates `*prx = ch.recv()` case for select.
// //
// if pok is provided the case is extended to `[*prx, *pok] = ch.recv_()` // if pok is provided the case is extended to `[*prx, *pok] = ch.recv_()`
// if both prx and pok are omitted the case is reduced to `ch.recv()`. // if both prx and pok are omitted the case is reduced to `ch.recv()`.
[[nodiscard]] inline _selcase recvs(T *prx=NULL, bool *pok=NULL) { [[nodiscard]] inline _selcase recvs(T *prx=NULL, bool *pok=NULL) const {
return _selrecv_(_ch, prx, pok); return _selrecv_(_ch, prx, pok);
} }
// length/capacity // length/capacity
inline unsigned len() { return _chanlen(_ch); } inline unsigned len() const { return _chanlen(_ch); }
inline unsigned cap() { return _chancap(_ch); } inline unsigned cap() const { return _chancap(_ch); }
// compare wrt nil // compare wrt nil
inline bool operator==(nullptr_t) { return (_ch == NULL); } inline bool operator==(nullptr_t) const { return (_ch == NULL); }
inline bool operator!=(nullptr_t) { return (_ch != NULL); } inline bool operator!=(nullptr_t) const { return (_ch != NULL); }
// compare wrt chan // compare wrt chan
inline bool operator==(const chan<T>& ch2) { return (_ch == ch2._ch); } inline bool operator==(const chan<T>& ch2) const { return (_ch == ch2._ch); }
inline bool operator!=(const chan<T>& ch2) { return (_ch != ch2._ch); } inline bool operator!=(const chan<T>& ch2) const { return (_ch != ch2._ch); }
// for testing // for testing
inline _chan *_rawchan() { return _ch; } inline _chan *_rawchan() const { return _ch; }
}; };
// makechan<T> makes new chan<T> with capacity=size. // makechan<T> makes new chan<T> with capacity=size.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment