[Assorted-commits] SF.net SVN: assorted:[1289] cpp-commons/trunk/src/commons
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-03-12 19:54:40
|
Revision: 1289 http://assorted.svn.sourceforge.net/assorted/?rev=1289&view=rev Author: yangzhang Date: 2009-03-12 19:54:31 +0000 (Thu, 12 Mar 2009) Log Message: ----------- using ASSERT instead of assert Modified Paths: -------------- cpp-commons/trunk/src/commons/fast_map.h cpp-commons/trunk/src/commons/rand.h cpp-commons/trunk/src/commons/st/st.h cpp-commons/trunk/src/commons/streamreader.h cpp-commons/trunk/src/commons/streamwriter.h Modified: cpp-commons/trunk/src/commons/fast_map.h =================================================================== --- cpp-commons/trunk/src/commons/fast_map.h 2009-03-12 19:53:53 UTC (rev 1288) +++ cpp-commons/trunk/src/commons/fast_map.h 2009-03-12 19:54:31 UTC (rev 1289) @@ -2,8 +2,8 @@ #define COMMONS_DENSE_HASH_MAP_H #include <boost/functional/hash.hpp> -#include <cassert> #include <commons/array.h> +#include <commons/assert.h> #include <commons/exceptions.h> #include <utility> @@ -167,7 +167,7 @@ for (size_t probe = 0; newtab[pos].first != empty_key; pos = (pos + ++probe) & mask) { - assert(probe < newtab.size()); + ASSERT(probe < newtab.size()); } newtab[pos] = table[i]; } @@ -177,7 +177,7 @@ void grow() { resize(table.size() << 1); } void shrink() { resize(table.size() >> 1); } - void assert_init() const { assert(has_empty_key && has_deleted_key); } + void assert_init() const { ASSERT(has_empty_key && has_deleted_key); } public: fast_map() : @@ -229,7 +229,7 @@ if (table[pos].first == empty_key) return end(); if (table[pos].first == k) return const_iterator(*this, &table[pos]); pos = (pos + ++probe) & mask; - assert(probe < table.size()); + ASSERT(probe < table.size()); } } @@ -240,13 +240,13 @@ if (table[pos].first == empty_key) return end(); if (table[pos].first == k) return iterator(*this, &table[pos]); pos = (pos + ++probe) & mask; - assert(probe < table.size()); + ASSERT(probe < table.size()); } #if 0 for (; table[pos].first != empty_key && table[pos].first != k; pos = (pos + ++probe) & mask) { - assert(probe < table.size()); + ASSERT(probe < table.size()); } if (table[pos].first == empty_key) return end(); else return &table[pos]; @@ -265,14 +265,14 @@ table[pos].first != empty_key && table[pos].first != k; pos = (pos + ++probe) & mask) { - assert(probe < table.size()); + ASSERT(probe < table.size()); } if (table[pos].first == deleted_key) { size_t first_deleted = pos; for (; table[pos].first != empty_key && table[pos].first != k; pos = (pos + ++probe) & mask) { - assert(probe < table.size()); + ASSERT(probe < table.size()); } if (table[pos].first == empty_key) { // Inserting new value_type. Grow table if necessary. Modified: cpp-commons/trunk/src/commons/rand.h =================================================================== --- cpp-commons/trunk/src/commons/rand.h 2009-03-12 19:53:53 UTC (rev 1288) +++ cpp-commons/trunk/src/commons/rand.h 2009-03-12 19:54:31 UTC (rev 1289) @@ -1,7 +1,6 @@ #ifndef COMMONS_RAND_H #define COMMONS_RAND_H -#include <cassert> #include <cstdlib> // random, RAND_MAX namespace commons Modified: cpp-commons/trunk/src/commons/st/st.h =================================================================== --- cpp-commons/trunk/src/commons/st/st.h 2009-03-12 19:53:53 UTC (rev 1288) +++ cpp-commons/trunk/src/commons/st/st.h 2009-03-12 19:54:31 UTC (rev 1289) @@ -6,6 +6,7 @@ #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <commons/array.h> +#include <commons/assert.h> #include <commons/delegates.h> #include <commons/nullptr.h> #include <commons/streamreader.h> @@ -297,7 +298,7 @@ void reset() { // If b is true, then any threads that join are immediately // interrupted, so the set must be empty. - assert(!b || threads.empty()); + ASSERT(!b || threads.empty()); b = false; } operator bool() const { return b; } @@ -350,7 +351,7 @@ NONCOPYABLE(st_joining) public: st_joining(st_thread_t t) : t_(t) {} - ~st_joining() { st_join(t_); } + ~st_joining() { if (t_ != nullptr) st_join(t_); } private: st_thread_t t_; }; @@ -375,6 +376,11 @@ std::set<st_thread_t> ts; }; +#if 0 +/// XXX + int count = 0; + size_t glen = 0; + class st_read_fn { private: @@ -384,9 +390,28 @@ st_read_fn(st_netfd_t fd, st_utime_t to = ST_UTIME_NO_TIMEOUT) : fd_(fd), to_(to) {} size_t operator()(char *buf, size_t len) { + size_t x = size_t(checknnegerr(st_read(fd_, buf, len, to_))); + glen += x; + if ((++count & 0xf) == 0xf) + cout << "count " << count << " len " << len << " read " << x << " glen " << glen << endl; + return x; + // return size_t(checknnegerr(st_read(fd_, buf, len, to_))); + } + }; +#else + class st_read_fn + { + private: + st_netfd_t fd_; + st_utime_t to_; + public: + st_read_fn(st_netfd_t fd, st_utime_t to = ST_UTIME_NO_TIMEOUT) + : fd_(fd), to_(to) {} + size_t operator()(char *buf, size_t len) { return size_t(checknnegerr(st_read(fd_, buf, len, to_))); } }; +#endif class st_read_fully_fn { Modified: cpp-commons/trunk/src/commons/streamreader.h =================================================================== --- cpp-commons/trunk/src/commons/streamreader.h 2009-03-12 19:53:53 UTC (rev 1288) +++ cpp-commons/trunk/src/commons/streamreader.h 2009-03-12 19:54:31 UTC (rev 1289) @@ -3,6 +3,7 @@ #include <boost/function.hpp> #include <commons/array.h> +#include <commons/assert.h> #include <cstring> namespace commons { @@ -31,7 +32,7 @@ res += reader_(buf + res, len - res); if (res == 0) throw eof_exception(); } - assert(res == len); + ASSERT(res == len); } }; @@ -205,7 +206,7 @@ return x; } - assert(req <= buf_.size()); + ASSERT(req <= buf_.size()); // Shift things down if necessary. if (req > static_cast<size_t>(buf_.end() - end_)) Modified: cpp-commons/trunk/src/commons/streamwriter.h =================================================================== --- cpp-commons/trunk/src/commons/streamwriter.h 2009-03-12 19:53:53 UTC (rev 1288) +++ cpp-commons/trunk/src/commons/streamwriter.h 2009-03-12 19:54:31 UTC (rev 1289) @@ -3,6 +3,7 @@ #include <boost/function.hpp> #include <commons/array.h> +#include <commons/assert.h> #include <cstring> #include <iostream> #include <iomanip> @@ -25,7 +26,7 @@ char *reserve(int n, char *p) { if (p + n > a_.end()) { // check that the reserved space will fit - assert(size_t(p - mark_ + n + sizeof(uint32_t)) <= a_.size()); + ASSERT(size_t(p - mark_ + n + sizeof(uint32_t)) <= a_.size()); // get rid of what we have flush(); size_t diff = mark_ - (a_.get() + sizeof(uint32_t)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |