[Assorted-commits] SF.net SVN: assorted:[1309] cpp-commons/trunk/src/commons
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-03-19 10:18:20
|
Revision: 1309 http://assorted.svn.sourceforge.net/assorted/?rev=1309&view=rev Author: yangzhang Date: 2009-03-19 10:18:05 +0000 (Thu, 19 Mar 2009) Log Message: ----------- - added friendlier versions of st_read, st_write - added array ctor - made stream_writer::reserve return the current pointer Modified Paths: -------------- cpp-commons/trunk/src/commons/array.h cpp-commons/trunk/src/commons/st/st.h cpp-commons/trunk/src/commons/streamwriter.h Modified: cpp-commons/trunk/src/commons/array.h =================================================================== --- cpp-commons/trunk/src/commons/array.h 2009-03-19 10:16:33 UTC (rev 1308) +++ cpp-commons/trunk/src/commons/array.h 2009-03-19 10:18:05 UTC (rev 1309) @@ -52,6 +52,7 @@ friend void swap<>(array<T> &a, array<T> &b); public: explicit array(size_t n) : p_(new T[n]), n_(n) {} + explicit array(T *p, size_t n) : p_(p), n_(n) {} array() : p_(), n_(0) {} array(array<T> &&src) : p_(src.release()), n_(src.n_) {} #if 0 Modified: cpp-commons/trunk/src/commons/st/st.h =================================================================== --- cpp-commons/trunk/src/commons/st/st.h 2009-03-19 10:16:33 UTC (rev 1308) +++ cpp-commons/trunk/src/commons/st/st.h 2009-03-19 10:18:05 UTC (rev 1309) @@ -50,6 +50,33 @@ st_mutex_t mx_; }; + void + st_read(st_netfd_t fd, void *buf, size_t len) + { + checkeqnneg(st_read_fully(fd, buf, len, ST_UTIME_NO_TIMEOUT), ssize_t(len)); + } + + template<typename T> + void + st_read(st_netfd_t fd, T &x) + { + st_read(fd, &x, sizeof x); + } + + void + st_write(st_netfd_t fd, const void *buf, size_t len) + { + checkeqnneg(st_write(fd, buf, len, ST_UTIME_NO_TIMEOUT), ssize_t(len)); + } + + template<typename T> + void + st_write(st_netfd_t fd, const T &x) + { + st_write(fd, &x, sizeof x); + } + + /** * Run a function in pthread. * \return The new pthread_t on success, 0 on failure. Modified: cpp-commons/trunk/src/commons/streamwriter.h =================================================================== --- cpp-commons/trunk/src/commons/streamwriter.h 2009-03-19 10:16:33 UTC (rev 1308) +++ cpp-commons/trunk/src/commons/streamwriter.h 2009-03-19 10:18:05 UTC (rev 1309) @@ -60,7 +60,7 @@ } } void reset() { p_ = mark_; } - void reserve(size_t n) { reserve(n, p_); } + char *reserve(size_t n) { reserve(n, p_); return p_; } void mark_and_flush() { mark(); flush(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |