assorted-commits Mailing List for Assorted projects (Page 17)
Brought to you by:
yangzhang
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(9) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(86) |
Feb
(265) |
Mar
(96) |
Apr
(47) |
May
(136) |
Jun
(28) |
Jul
(57) |
Aug
(42) |
Sep
(20) |
Oct
(67) |
Nov
(37) |
Dec
(34) |
2009 |
Jan
(39) |
Feb
(85) |
Mar
(96) |
Apr
(24) |
May
(82) |
Jun
(13) |
Jul
(10) |
Aug
(8) |
Sep
(2) |
Oct
(20) |
Nov
(31) |
Dec
(17) |
2010 |
Jan
(16) |
Feb
(11) |
Mar
(17) |
Apr
(53) |
May
(31) |
Jun
(13) |
Jul
(3) |
Aug
(6) |
Sep
(11) |
Oct
(4) |
Nov
(17) |
Dec
(17) |
2011 |
Jan
(3) |
Feb
(19) |
Mar
(5) |
Apr
(17) |
May
(3) |
Jun
(4) |
Jul
(14) |
Aug
(3) |
Sep
(2) |
Oct
(1) |
Nov
(3) |
Dec
(2) |
2012 |
Jan
(3) |
Feb
(7) |
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
(4) |
Aug
(5) |
Sep
(2) |
Oct
(3) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(9) |
Apr
(5) |
May
|
Jun
(2) |
Jul
(1) |
Aug
(10) |
Sep
(1) |
Oct
(2) |
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
(3) |
Mar
(3) |
Apr
(1) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2016 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <yan...@us...> - 2009-11-06 01:34:12
|
Revision: 1502 http://assorted.svn.sourceforge.net/assorted/?rev=1502&view=rev Author: yangzhang Date: 2009-11-06 01:33:54 +0000 (Fri, 06 Nov 2009) Log Message: ----------- adopt boost's typedefs Modified Paths: -------------- cpp-commons/trunk/src/commons/win.h Modified: cpp-commons/trunk/src/commons/win.h =================================================================== --- cpp-commons/trunk/src/commons/win.h 2009-11-05 23:38:18 UTC (rev 1501) +++ cpp-commons/trunk/src/commons/win.h 2009-11-06 01:33:54 UTC (rev 1502) @@ -4,10 +4,17 @@ #ifdef WIN32 # define NONWIN(x) # define __attribute__(x) +#include <boost/cstdint.hpp> +using boost::int8_t; +using boost::int16_t; +using boost::int32_t; +using boost::int64_t; +using boost::uint8_t; +using boost::uint16_t; +using boost::uint32_t; +using boost::uint64_t; typedef HANDLE fd_t; int close(fd_t fd) { return CloseHandle(fd) ? 0 : -1; } -typedef UINT16 uint16_t; -typedef UINT32 uint32_t; void bzero(void *s, size_t n) { memset(s, 0, n); } #else # define NONWIN(x) x This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-05 23:38:28
|
Revision: 1501 http://assorted.svn.sourceforge.net/assorted/?rev=1501&view=rev Author: yangzhang Date: 2009-11-05 23:38:18 +0000 (Thu, 05 Nov 2009) Log Message: ----------- fixed win32 macros Modified Paths: -------------- cpp-commons/trunk/src/commons/die.h Modified: cpp-commons/trunk/src/commons/die.h =================================================================== --- cpp-commons/trunk/src/commons/die.h 2009-11-04 22:12:54 UTC (rev 1500) +++ cpp-commons/trunk/src/commons/die.h 2009-11-05 23:38:18 UTC (rev 1501) @@ -16,8 +16,10 @@ * * TODO: move into C Commons. */ +#ifdef WIN32 //#pragma warning(push) TODO why doesn't this work? #pragma warning(disable: 4505) +#endif __attribute__((format(printf, 1, 2),unused)) static void die(const char *format, ...) { @@ -30,7 +32,9 @@ fprintf(stderr, ": %s\n", errstr); exit(1); } +#ifdef WIN32 //#pragma warning(pop) +#endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-04 22:13:02
|
Revision: 1500 http://assorted.svn.sourceforge.net/assorted/?rev=1500&view=rev Author: yangzhang Date: 2009-11-04 22:12:54 +0000 (Wed, 04 Nov 2009) Log Message: ----------- updated for latest c++ commons Modified Paths: -------------- numa-bench/trunk/src/chew.cc Modified: numa-bench/trunk/src/chew.cc =================================================================== --- numa-bench/trunk/src/chew.cc 2009-11-04 22:11:38 UTC (rev 1499) +++ numa-bench/trunk/src/chew.cc 2009-11-04 22:12:54 UTC (rev 1500) @@ -15,7 +15,7 @@ #include <commons/rand.h> #include <commons/threads.h> #include <commons/time.h> -#include <commons/boost/threads.h> +#include <commons/threads.h> #ifdef TILE64 #include <commons/pthread/barrier.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-04 22:11:53
|
Revision: 1499 http://assorted.svn.sourceforge.net/assorted/?rev=1499&view=rev Author: yangzhang Date: 2009-11-04 22:11:38 +0000 (Wed, 04 Nov 2009) Log Message: ----------- updated for new libnuma Modified Paths: -------------- numa-bench/trunk/src/avail.cc Modified: numa-bench/trunk/src/avail.cc =================================================================== --- numa-bench/trunk/src/avail.cc 2009-11-04 22:11:16 UTC (rev 1498) +++ numa-bench/trunk/src/avail.cc 2009-11-04 22:11:38 UTC (rev 1499) @@ -26,7 +26,7 @@ // Print node CPUs. const int buflen = 512; unsigned long buffer[buflen]; - check(0 == numa_node_to_cpus(node, buffer, buflen)); + check(0 == numa_node_to_cpus_compat(node, buffer, buflen)); // TODO # cpus? for (int i = 0; i < 1; i++) { cout << hex << setfill('0') << setw(4) << buffer[i] << dec << ' '; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-04 22:11:34
|
Revision: 1498 http://assorted.svn.sourceforge.net/assorted/?rev=1498&view=rev Author: yangzhang Date: 2009-11-04 22:11:16 +0000 (Wed, 04 Nov 2009) Log Message: ----------- added back a makefile Added Paths: ----------- numa-bench/trunk/src/Makefile Added: numa-bench/trunk/src/Makefile =================================================================== --- numa-bench/trunk/src/Makefile (rev 0) +++ numa-bench/trunk/src/Makefile 2009-11-04 22:11:16 UTC (rev 1498) @@ -0,0 +1,5 @@ +LDLIBS = -lnuma +CXXFLAGS = -pthread -Wall +all: avail chew +clean: + rm -f avail chew This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-03 21:32:38
|
Revision: 1497 http://assorted.svn.sourceforge.net/assorted/?rev=1497&view=rev Author: yangzhang Date: 2009-11-03 21:32:27 +0000 (Tue, 03 Nov 2009) Log Message: ----------- tweak Modified Paths: -------------- sandbox/trunk/src/cc/c++0x.cc Modified: sandbox/trunk/src/cc/c++0x.cc =================================================================== --- sandbox/trunk/src/cc/c++0x.cc 2009-11-03 21:29:38 UTC (rev 1496) +++ sandbox/trunk/src/cc/c++0x.cc 2009-11-03 21:32:27 UTC (rev 1497) @@ -22,7 +22,7 @@ // new function class // could also use `auto` here // here's a lambda that captures x by value - function<void()> f = [x]{ + function<void()> f = [=]{ // new chrono class std::this_thread::sleep_for( chrono::seconds(x->first)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-03 21:29:54
|
Revision: 1496 http://assorted.svn.sourceforge.net/assorted/?rev=1496&view=rev Author: yangzhang Date: 2009-11-03 21:29:38 +0000 (Tue, 03 Nov 2009) Log Message: ----------- added c++0x demo Added Paths: ----------- sandbox/trunk/src/cc/c++0x.cc Added: sandbox/trunk/src/cc/c++0x.cc =================================================================== --- sandbox/trunk/src/cc/c++0x.cc (rev 0) +++ sandbox/trunk/src/cc/c++0x.cc 2009-11-03 21:29:38 UTC (rev 1496) @@ -0,0 +1,40 @@ +#define _GLIBCXX_USE_NANOSLEEP +#include <functional> +#include <iostream> +#include <string> +#include <thread> +#include <vector> + +using namespace std; +int main() { + // strongly typed enums + // can specify underlying type + enum class msg_type : uint8_t { hello, world }; + // initializer lists for easy init + // no more `>>` misparsing + const vector<pair<int, string>> xs = + {{1, "hello"}, {3, "world"}}; + // standard classes for concurrency + vector<thread> ts; + // type inference with repurposed `auto` + // no need for `vector<string>::const_iterator` + for (auto x = xs.begin(); x != xs.end(); ++x) { + // new function class + // could also use `auto` here + // here's a lambda that captures x by value + function<void()> f = [x]{ + // new chrono class + std::this_thread::sleep_for( + chrono::seconds(x->first)); + cout << x->second << endl; + }; + // thread is moveable + // no worry about copying/destroying here + // enabled by rvalue references (&&) + ts.push_back(thread(f)); + } + for (auto t = ts.begin(); t != ts.end(); ++t) { + t->join(); + } + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-11-03 17:16:27
|
Revision: 1495 http://assorted.svn.sourceforge.net/assorted/?rev=1495&view=rev Author: yangzhang Date: 2009-11-03 17:16:07 +0000 (Tue, 03 Nov 2009) Log Message: ----------- added gcc 4.4 c++0x demos Added Paths: ----------- sandbox/trunk/src/cc/inference.cc sandbox/trunk/src/cc/init_lists.cc Added: sandbox/trunk/src/cc/inference.cc =================================================================== --- sandbox/trunk/src/cc/inference.cc (rev 0) +++ sandbox/trunk/src/cc/inference.cc 2009-11-03 17:16:07 UTC (rev 1495) @@ -0,0 +1,21 @@ +#include <iostream> +#include <map> +#include <vector> +using namespace std; + +int main() { + auto x = 2; + cout << x << endl; + + auto xs = vector<int>({0,1,2,3}); + cout << xs[2] << endl; + + const auto ys = xs; + // No need for: + // for (vector<int>::const_iterator y = xs.begin(); y != xs.end(); ++y) { + for (auto y = ys.begin(); y != ys.end(); ++y) { + cout << *y << endl; + } + + return 0; +} Added: sandbox/trunk/src/cc/init_lists.cc =================================================================== --- sandbox/trunk/src/cc/init_lists.cc (rev 0) +++ sandbox/trunk/src/cc/init_lists.cc 2009-11-03 17:16:07 UTC (rev 1495) @@ -0,0 +1,41 @@ +#include <iostream> +#include <map> +#include <vector> +using namespace std; + +void f(const vector<int> &xs) { cout << xs[2] << endl; } + +struct point { + point(int x, int y) : x(x), y(y) {} + int x, y; +}; + +struct point2 { + point2(initializer_list<int> xs) { + for (const int *p = xs.begin(); p != xs.end(); ++p) { + ys.push_back(*p); + } + } + vector<int> ys; +}; + +int main() { + vector<int> xs = {0, 1, 2, 3}; + cout << xs[2] << endl; + cout << (vector<int>({0, 1, 2, 3}))[2] << endl; + f({0, 1, 2, 3}); + + point p = {2, 3}; + + point2 q = {0, 1, 2, 3}; + cout << q.ys[2] << endl; + + // causes a segfault in gcc 4.4.1 + map<int, pair<int, int>> m = {{0, {0, 0}}, + {1, {1, 1}}, + {2, {2, 2}}, + {3, {3, 3}}}; + cout << m[2].first << endl; + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-26 05:32:29
|
Revision: 1494 http://assorted.svn.sourceforge.net/assorted/?rev=1494&view=rev Author: yangzhang Date: 2009-10-26 05:32:08 +0000 (Mon, 26 Oct 2009) Log Message: ----------- tweak for windows Modified Paths: -------------- configs/trunk/src/vim/plugin/_yang.vim Modified: configs/trunk/src/vim/plugin/_yang.vim =================================================================== --- configs/trunk/src/vim/plugin/_yang.vim 2009-10-15 08:26:09 UTC (rev 1493) +++ configs/trunk/src/vim/plugin/_yang.vim 2009-10-26 05:32:08 UTC (rev 1494) @@ -1,4 +1,6 @@ -" crawl http://eigenstate.org/vim/vimrc +" TODO crawl http://eigenstate.org/vim/vimrc +" TODO crawl default windows vimrc's +" TODO merge with cream mainline " UNSORTED " command! DiffOff :call CleanDiffOptions() @@ -11,11 +13,12 @@ " \ 'CmpJavaImports', 1) " " TODO fix +set nocompatible + nnoremap <silent> <C-Space> :call ShiftWordInSpace(1)<CR> nnoremap <silent> <C-BS> :call ShiftWordInSpace(-1)<CR> nnoremap <silent> \cw :call CenterWordInSpace()<CR> - " From " http://concisionandconcinnity.blogspot.com/2009/07/vim-part-ii-matching-pairs.html vnoremap ( <ESC>`>a)<ESC>`<i(<ESC> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-15 08:26:20
|
Revision: 1493 http://assorted.svn.sourceforge.net/assorted/?rev=1493&view=rev Author: yangzhang Date: 2009-10-15 08:26:09 +0000 (Thu, 15 Oct 2009) Log Message: ----------- added windows support; added addr2name, name2addr, checkptr Modified Paths: -------------- cpp-commons/trunk/src/commons/check.h cpp-commons/trunk/src/commons/closing.h cpp-commons/trunk/src/commons/die.h cpp-commons/trunk/src/commons/sockets.h Added Paths: ----------- cpp-commons/trunk/src/commons/win.h Modified: cpp-commons/trunk/src/commons/check.h =================================================================== --- cpp-commons/trunk/src/commons/check.h 2009-10-14 18:10:19 UTC (rev 1492) +++ cpp-commons/trunk/src/commons/check.h 2009-10-15 08:26:09 UTC (rev 1493) @@ -5,6 +5,10 @@ #include <sstream> #include <string> #include <commons/die.h> +#include <commons/utility.h> +#include <commons/win.h> +#include <commons/nullptr.h> +#include <boost/noncopyable.hpp> #include <boost/lexical_cast.hpp> // TODO: rename: @@ -28,6 +32,13 @@ namespace commons { +#ifdef WIN32 +#define wvsnprintf(buf, len, fmt, args) \ + { USE(buf); USE(len); USE(fmt); USE(args); } +// TODO get this to build! +// #define vsnprintf(buf, len, fmt, args) vsnprintf_s(buf, len, _TRUNCATE, fmt, args) +#endif + enum { buflen = 4096 }; // TODO: deal with va args @@ -44,7 +55,7 @@ virtual ~check_exception() throw() {} virtual const char *what() const throw() { return name.c_str(); } private: - const string name; + string name; }; __attribute__((format(printf, 4, 0))) inline static void @@ -85,6 +96,13 @@ } template<typename T> inline T + _checkptr(T x, const char *file, int line) + { + _check(x != nullptr, file, line); + return x; + } + + template<typename T> inline T _checknneg(T x, const char *file, int line) { if (x < 0) { @@ -177,8 +195,10 @@ * use as a guard against expected failures (such as checking return codes). * This is a macro for two reasons: (1) the file and line, and (2) the lazy * evaluation of msg. + * + * check(result, "bad result %d", result) */ -#define check(cond, msg...) _check(cond, __FILE__, __LINE__, ## msg) +#define check(cond, ...) commons::_check(cond, __FILE__, __LINE__, ## __VA_ARGS__) /** * Same as check(), but additionally returns the value that was passed in. The @@ -187,53 +207,58 @@ * return value is non-zero or not false). This is suitable for small, * copyable pieces of data, such as integers, file descriptors, pointers, etc. */ -#define checkpass(expr, msg...) _checkpass(expr, __FILE__, __LINE__, ## msg) +#define checkpass(expr, ...) commons::_checkpass(expr, __FILE__, __LINE__, ## __VA_ARGS__) /** + * Check that a pointer is not NULL. + */ +#define checkptr(expr, ...) commons::_checkptr(expr, __FILE__, __LINE__, ## __VA_ARGS__) + +/** * Same as checkpass(), but includes the strerror message in the exception. */ -#define checkerr(expr) _checkerr(expr, __FILE__, __LINE__) +#define checkerr(expr) commons::_checkerr(expr, __FILE__, __LINE__) /** * Checks that the value is non-negative. */ -#define checknneg(expr, msg...) _checknneg(expr, __FILE__, __LINE__, ## msg) +#define checknneg(expr, ...) commons::_checknneg(expr, __FILE__, __LINE__, ## __VA_ARGS__) /** * Same as checknneg, but include the strerror in the exception. */ -#define checknnegerr(expr) _checknnegerr(expr, __FILE__, __LINE__) +#define checknnegerr(expr) commons::_checknnegerr(expr, __FILE__, __LINE__) /** * Checks that the value is 0. Same as check0(), but throws an error rather * than return. Also clears the errno on error. The resulting exception * includes the strerror(). */ -#define check0x(expr, msg...) _check0(expr, __FILE__, __LINE__, ## msg) +#define check0x(expr, ...) commons::_check0(expr, __FILE__, __LINE__, ## __VA_ARGS__) /** * Checks that the values are not equal. The exception will include both * values, as formatted by ostream <<. */ -#define checkneq(l, r, msg...) _checkneq(l, r, __FILE__, __LINE__, ## msg) +#define checkneq(l, r, ...) commons::_checkneq(l, r, __FILE__, __LINE__, ## __VA_ARGS__) /** * Checks that the values are equal. The exception will include both values, * as formatted by ostream <<. */ -#define checkeq(l, r, msg...) _checkeq(l, r, __FILE__, __LINE__, ## msg) +#define checkeq(l, r, ...) commons::_checkeq(l, r, __FILE__, __LINE__, ## __VA_ARGS__) /** * Like checkeq, but if the left value is negative, then interpret that as a * sign of error, and include the errorstr in the exception message. */ -#define checkeqnneg(l, r, msg...) \ - _checkeqnneg(l, r, __FILE__, __LINE__, ## msg) +#define checkeqnneg(l, r, ...) \ + commons::_checkeqnneg(l, r, __FILE__, __LINE__, ## __VA_ARGS__) #if 0 #define checkmsg(cond, msg) \ bool b__ = cond; \ - if (!b__) _check(b__, (msg), __FILE__, __LINE__) + if (!b__) commons::_check(b__, (msg), __FILE__, __LINE__) #define checkmsgf(cond, msg...) \ do { \ @@ -241,7 +266,7 @@ if (!b__) { \ char s__[4096]; \ snprintf(s, msg); \ - _check(b__, s__, __FILE__, __LINE__); \ + commons::_check(b__, s__, __FILE__, __LINE__); \ } \ } while (0) #endif @@ -261,10 +286,10 @@ /** * Checks that the value is true or non-zero, otherwise dies (calls die()). */ -#define checkdie(expr, msg...) \ +#define checkdie(expr, ...) \ do { \ if (!expr) { \ - die(msg); \ + die(__VA_ARGS__); \ } \ } while (0) Modified: cpp-commons/trunk/src/commons/closing.h =================================================================== --- cpp-commons/trunk/src/commons/closing.h 2009-10-14 18:10:19 UTC (rev 1492) +++ cpp-commons/trunk/src/commons/closing.h 2009-10-15 08:26:09 UTC (rev 1493) @@ -4,15 +4,18 @@ #include <boost/utility.hpp> #include <commons/check.h> #include <commons/utility.h> +#include <commons/win.h> +#include <cstdio> namespace commons { using namespace boost; + using namespace std; // void checked_close(int &fd) { check0x(close(fd)); } - struct fd_closer { static void apply(int fd) { check0x(close(fd)); } }; + struct fd_closer { static void apply(fd_t fd) { check0x(close(fd)); } }; template<typename T, typename Closer> class closing @@ -29,7 +32,7 @@ bool scoped; }; - typedef closing<int, fd_closer> closingfd; + typedef closing<fd_t, fd_closer> closingfd; } Modified: cpp-commons/trunk/src/commons/die.h =================================================================== --- cpp-commons/trunk/src/commons/die.h 2009-10-14 18:10:19 UTC (rev 1492) +++ cpp-commons/trunk/src/commons/die.h 2009-10-15 08:26:09 UTC (rev 1493) @@ -1,6 +1,7 @@ #ifndef COMMONS_DIE_H #define COMMONS_DIE_H +#include <commons/win.h> #include <cerrno> #include <cstdio> #include <cstdarg> @@ -15,6 +16,8 @@ * * TODO: move into C Commons. */ +//#pragma warning(push) TODO why doesn't this work? +#pragma warning(disable: 4505) __attribute__((format(printf, 1, 2),unused)) static void die(const char *format, ...) { @@ -27,6 +30,7 @@ fprintf(stderr, ": %s\n", errstr); exit(1); } +//#pragma warning(pop) } Modified: cpp-commons/trunk/src/commons/sockets.h =================================================================== --- cpp-commons/trunk/src/commons/sockets.h 2009-10-14 18:10:19 UTC (rev 1492) +++ cpp-commons/trunk/src/commons/sockets.h 2009-10-15 08:26:09 UTC (rev 1493) @@ -1,6 +1,9 @@ #ifndef COMMONS_SOCKETS_H #define COMMONS_SOCKETS_H +#ifdef WIN32 +#include <winsock2.h> +#else #include <arpa/inet.h> #include <netdb.h> #include <netinet/in.h> @@ -9,6 +12,7 @@ #include <sys/types.h> #include <fcntl.h> #include <unistd.h> +#endif #include <commons/check.h> #include <commons/closing.h> @@ -17,6 +21,19 @@ namespace commons { +#ifdef WIN32 + typedef SOCKET socket_t; + + int inet_aton(const char *cp, struct in_addr *inp) { + uint32_t a = inet_addr(cp); + if (a == INADDR_NONE) return 0; + inp->S_un.S_addr = a; + return 1; + } +#else + typedef fd_t socket_t; +#endif + /** * Work-around for the -Wold-style-cast-unsafe FD_* macros (see select(2)). */ @@ -26,26 +43,35 @@ /** * Work-around for the -Wold-style-cast-unsafe INADDR_ANY */ +#ifndef WIN32 const in_addr_t inaddr_any = in_addr_t(0); +#else +#define inaddr_any INADDR_ANY +#endif /** * Make a TCP socket non-blocking. */ - inline int - set_non_blocking(int fd) + inline socket_t + set_non_blocking(socket_t fd) { +#ifndef WIN32 checknnegerr(fcntl(fd, F_SETFL, O_NONBLOCK | checknnegerr(fcntl(fd, F_GETFL, 0)))); +#else + unsigned long one = 1; + checknnegerr(ioctlsocket(fd, FIONBIO, &one)); +#endif return fd; } /** * Create a TCP socket. */ - inline int + inline socket_t tcp_socket(bool nb) { - int fd = checknnegerr(socket(PF_INET, SOCK_STREAM, 0)); + socket_t fd = checknnegerr(socket(PF_INET, SOCK_STREAM, 0)); // Make our socket non-blocking if desired. if (nb) set_non_blocking(fd); return fd; @@ -84,7 +110,7 @@ // First try to interpret host as a dot-notation string. if (!inet_aton(host, reinterpret_cast<in_addr*>(&a.sin_addr.s_addr))) { // Now try to resolve the hostname. - hostent *res = checkpass(gethostbyname(host)); + hostent *res = checkptr(gethostbyname(host)); memcpy(&a.sin_addr, res->h_addr_list[0], res->h_length); } } @@ -101,6 +127,16 @@ } /** + * Initialize an inet addres. + */ + inline void + sockaddr_init(sockaddr_in &a, uint32_t host, uint16_t port) + { + sockaddr_init(a, port); + a.sin_addr.s_addr = host; + } + + /** * Construct an inet address. */ template <typename T> @@ -112,18 +148,28 @@ return a; } + void close_socket(socket_t s) { +#ifdef WIN32 + closesocket(s); +#else + close(s); +#endif + } + struct socket_closer { static void apply(socket_t s) { close_socket(s); } }; + typedef closing<socket_t, socket_closer> closing_socket; + /** * Create a server socket bound to localhost, with SO_REUSEADDR enabled. * \param[in] port The port to listen on. * \param[in] nb Whether the socket should be non-blocking. * \return The server socket. */ - UNUSED static int + UNUSED static socket_t server_socket(uint16_t port, bool nb = false) { // Create the socket. - closingfd c(tcp_socket(nb)); - int fd = c.get(); + closing_socket c(tcp_socket(nb)); + socket_t fd = c.get(); // Configure the socket. int n = 1; @@ -145,17 +191,17 @@ * \param[in] nb Whether the socket should be non-blocking. * \return The listener socket. */ - UNUSED static int + UNUSED static socket_t tcp_listen(uint16_t port, bool nb = false) { - int fd = server_socket(port, nb); + socket_t fd = server_socket(port, nb); try { // SOMAXCONN is the kernel's limit on the maximum number of socket // connections. check0x(listen(fd, SOMAXCONN)); return fd; } catch (...) { - close(fd); + close_socket(fd); throw; } } @@ -163,15 +209,61 @@ /** * Connect to a TCP socket. */ - UNUSED static int - tcp_connect(const char *host, uint16_t port) + template<typename T> + UNUSED static socket_t + tcp_connect(T host, uint16_t port) { - closingfd c(tcp_socket(false)); + closing_socket c(tcp_socket(false)); sockaddr_in a = make_sockaddr(host, port); check0x(connect(c.get(), reinterpret_cast<sockaddr*>(&a), sizeof a)); return c.release(); } +#if defined(WIN32) && defined(UNICODE) +#define getnameinfo GetNameInfoW +#define getaddrinfo GetAddrInfoW +#define addrinfo ADDRINFOW +#define freeaddrinfo FreeAddrInfoW +#endif + + /** + * T is a string or wstring. + */ + template<typename T> + sockaddr_in + addr2name(const sockaddr_in sa) + { + enum { sz = 1024 }; + wchar_t buf[sz]; + check0x(getnameinfo(reinterpret_cast<const sockaddr*>(&sa), sizeof sa, + buf, sz, // output hostname + nullptr, 0, // service + 0)); // flags + return sa; + } + + /** + * Get IPv4 address for hostname. T is a string or wstring. + */ + template<typename T> + in_addr + name2addr(const T *name) + { + addrinfo *ai, hints = {0}; + in_addr addr; + hints.ai_family = AF_INET; // use AF_UNSPEC for "any" + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + check0x(getaddrinfo(name, // hostname + L"1", // service + &hints, // flags + &ai)); // output addrinfo + // just take the first one; ignore everything but in_addr + addr = reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_addr; + freeaddrinfo(ai); + return addr; + } + } #endif Added: cpp-commons/trunk/src/commons/win.h =================================================================== --- cpp-commons/trunk/src/commons/win.h (rev 0) +++ cpp-commons/trunk/src/commons/win.h 2009-10-15 08:26:09 UTC (rev 1493) @@ -0,0 +1,17 @@ +#ifndef COMMONS_WIN_H +#define COMMONS_WIN_H + +#ifdef WIN32 +# define NONWIN(x) +# define __attribute__(x) +typedef HANDLE fd_t; +int close(fd_t fd) { return CloseHandle(fd) ? 0 : -1; } +typedef UINT16 uint16_t; +typedef UINT32 uint32_t; +void bzero(void *s, size_t n) { memset(s, 0, n); } +#else +# define NONWIN(x) x +typedef int fd_t; +#endif + +#endif Property changes on: cpp-commons/trunk/src/commons/win.h ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:10:34
|
Revision: 1492 http://assorted.svn.sourceforge.net/assorted/?rev=1492&view=rev Author: yangzhang Date: 2009-10-14 18:10:19 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added version of boost::dynamic_bitset from boost 1.37 that additionally features a find_in method to find in specific range of bits Added Paths: ----------- cpp-commons/trunk/src/commons/dynamic_bitset.h Added: cpp-commons/trunk/src/commons/dynamic_bitset.h =================================================================== --- cpp-commons/trunk/src/commons/dynamic_bitset.h (rev 0) +++ cpp-commons/trunk/src/commons/dynamic_bitset.h 2009-10-14 18:10:19 UTC (rev 1492) @@ -0,0 +1,1780 @@ +// ----------------------------------------------------------- +// +// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek +// Copyright (c) 2003-2006, 2008 Gennaro Prota +// +// 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 COMMONS_DYNAMIC_BITSET_H +#define COMMONS_DYNAMIC_BITSET_H + +#include <assert.h> +#include <string> +#include <stdexcept> +#include <algorithm> +#include <vector> +#include <climits> // for CHAR_BIT + +#include <boost/dynamic_bitset/config.hpp> + +#ifndef BOOST_NO_STD_LOCALE +# include <locale> +#endif + +#if defined(BOOST_OLD_IOSTREAMS) +# include <iostream.h> +# include <ctype.h> // for isspace +#else +# include <istream> +# include <ostream> +#endif + +#include <boost/dynamic_bitset_fwd.hpp> +#include <boost/detail/dynamic_bitset.hpp> +#include <boost/detail/iterator.hpp> // used to implement append(Iter, Iter) +#include <boost/static_assert.hpp> +#include <boost/limits.hpp> +#include <boost/pending/lowest_bit.hpp> + + +namespace boost { + +template <typename Block, typename Allocator> +class dynamic_bitset +{ + // Portability note: member function templates are defined inside + // this class definition to avoid problems with VC++. Similarly, + // with the member functions of nested classes. + // + // [October 2008: the note above is mostly historical; new versions + // of VC++ are likely able to digest a more drinking form of the + // code; but changing it now is probably not worth the risks...] + + BOOST_STATIC_ASSERT(detail::dynamic_bitset_impl::allowed_block_type<Block>::value); + +public: + typedef Block block_type; + typedef Allocator allocator_type; + typedef std::size_t size_type; + typedef block_type block_width_type; + + BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits)); + BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1)); + + +public: + + // A proxy class to simulate lvalues of bit type. + // + class reference + { + friend class dynamic_bitset<Block, Allocator>; + + + // the one and only non-copy ctor + reference(block_type & b, block_type pos) + :m_block(b), + m_mask( (assert(pos < bits_per_block), + block_type(1) << pos ) + ) + { } + + void operator&(); // left undefined + + public: + + // copy constructor: compiler generated + + operator bool() const { return (m_block & m_mask) != 0; } + bool operator~() const { return (m_block & m_mask) == 0; } + + reference& flip() { do_flip(); return *this; } + + reference& operator=(bool x) { do_assign(x); return *this; } // for b[i] = x + reference& operator=(const reference& rhs) { do_assign(rhs); return *this; } // for b[i] = b[j] + + reference& operator|=(bool x) { if (x) do_set(); return *this; } + reference& operator&=(bool x) { if (!x) do_reset(); return *this; } + reference& operator^=(bool x) { if (x) do_flip(); return *this; } + reference& operator-=(bool x) { if (x) do_reset(); return *this; } + + private: + block_type & m_block; + const block_type m_mask; + + void do_set() { m_block |= m_mask; } + void do_reset() { m_block &= ~m_mask; } + void do_flip() { m_block ^= m_mask; } + void do_assign(bool x) { x? do_set() : do_reset(); } + }; + + typedef bool const_reference; + + // constructors, etc. + explicit + dynamic_bitset(const Allocator& alloc = Allocator()); + + explicit + dynamic_bitset(size_type num_bits, unsigned long value = 0, + const Allocator& alloc = Allocator()); + + + // WARNING: you should avoid using this constructor. + // + // A conversion from string is, in most cases, formatting, + // and should be performed by using operator>>. + // + // NOTE: + // Leave the parentheses around std::basic_string<CharT, Traits, Alloc>::npos. + // g++ 3.2 requires them and probably the standard will - see core issue 325 + // NOTE 2: + // split into two constructors because of bugs in MSVC 6.0sp5 with STLport + + template <typename CharT, typename Traits, typename Alloc> + dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s, + typename std::basic_string<CharT, Traits, Alloc>::size_type pos, + typename std::basic_string<CharT, Traits, Alloc>::size_type n, + size_type num_bits = npos, + const Allocator& alloc = Allocator()) + + :m_bits(alloc), + m_num_bits(0) + { + init_from_string(s, pos, n, num_bits); + } + + template <typename CharT, typename Traits, typename Alloc> + explicit + dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s, + typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0) + + :m_bits(Allocator()), + m_num_bits(0) + { + init_from_string(s, pos, (std::basic_string<CharT, Traits, Alloc>::npos), + npos); + } + + // The first bit in *first is the least significant bit, and the + // last bit in the block just before *last is the most significant bit. + template <typename BlockInputIterator> + dynamic_bitset(BlockInputIterator first, BlockInputIterator last, + const Allocator& alloc = Allocator()) + + :m_bits(alloc), + m_num_bits(0) + { + using boost::detail::dynamic_bitset_impl::value_to_type; + using boost::detail::dynamic_bitset_impl::is_numeric; + + const value_to_type< + is_numeric<BlockInputIterator>::value> selector; + + dispatch_init(first, last, selector); + } + + template <typename T> + void dispatch_init(T num_bits, unsigned long value, + detail::dynamic_bitset_impl::value_to_type<true>) + { + init_from_unsigned_long(static_cast<size_type>(num_bits), value); + } + + template <typename T> + void dispatch_init(T first, T last, + detail::dynamic_bitset_impl::value_to_type<false>) + { + init_from_block_range(first, last); + } + + template <typename BlockIter> + void init_from_block_range(BlockIter first, BlockIter last) + { + assert(m_bits.size() == 0); + m_bits.insert(m_bits.end(), first, last); + m_num_bits = m_bits.size() * bits_per_block; + } + + // copy constructor + dynamic_bitset(const dynamic_bitset& b); + + ~dynamic_bitset(); + + void swap(dynamic_bitset& b); + dynamic_bitset& operator=(const dynamic_bitset& b); + + allocator_type get_allocator() const; + + // size changing operations + void resize(size_type num_bits, bool value = false); + void clear(); + void push_back(bool bit); + void append(Block block); + + template <typename BlockInputIterator> + void m_append(BlockInputIterator first, BlockInputIterator last, std::input_iterator_tag) + { + std::vector<Block, Allocator> v(first, last); + m_append(v.begin(), v.end(), std::random_access_iterator_tag()); + } + template <typename BlockInputIterator> + void m_append(BlockInputIterator first, BlockInputIterator last, std::forward_iterator_tag) + { + assert(first != last); + block_width_type r = count_extra_bits(); + std::size_t d = boost::detail::distance(first, last); + m_bits.reserve(num_blocks() + d); + if (r == 0) { + for( ; first != last; ++first) + m_bits.push_back(*first); // could use vector<>::insert() + } + else { + m_highest_block() |= (*first << r); + do { + Block b = *first >> (bits_per_block - r); + ++first; + m_bits.push_back(b | (first==last? 0 : *first << r)); + } while (first != last); + } + m_num_bits += bits_per_block * d; + } + template <typename BlockInputIterator> + void append(BlockInputIterator first, BlockInputIterator last) // strong guarantee + { + if (first != last) { + typename detail::iterator_traits<BlockInputIterator>::iterator_category cat; + m_append(first, last, cat); + } + } + + + // bitset operations + dynamic_bitset& operator&=(const dynamic_bitset& b); + dynamic_bitset& operator|=(const dynamic_bitset& b); + dynamic_bitset& operator^=(const dynamic_bitset& b); + dynamic_bitset& operator-=(const dynamic_bitset& b); + dynamic_bitset& operator<<=(size_type n); + dynamic_bitset& operator>>=(size_type n); + dynamic_bitset operator<<(size_type n) const; + dynamic_bitset operator>>(size_type n) const; + + // basic bit operations + dynamic_bitset& set(size_type n, bool val = true); + dynamic_bitset& set(); + dynamic_bitset& reset(size_type n); + dynamic_bitset& reset(); + dynamic_bitset& flip(size_type n); + dynamic_bitset& flip(); + bool test(size_type n) const; + bool any() const; + bool none() const; + dynamic_bitset operator~() const; + size_type count() const; + + // subscript + reference operator[](size_type pos) { + return reference(m_bits[block_index(pos)], bit_index(pos)); + } + bool operator[](size_type pos) const { return test(pos); } + + unsigned long to_ulong() const; + + size_type size() const; + size_type num_blocks() const; + size_type max_size() const; + bool empty() const; + + bool is_subset_of(const dynamic_bitset& a) const; + bool is_proper_subset_of(const dynamic_bitset& a) const; + bool intersects(const dynamic_bitset & a) const; + + // lookup + size_type find_first() const; + size_type find_next(size_type pos) const; + /** Look up in specific range. */ + size_type find_in(size_type start, size_type end) const + { + assert(start <= end && start < size() && end <= size()); + const size_type bstart = block_index(start), bend = block_index(end); + const block_width_type ind_start = bit_index(start), + ind_end = bit_index(end); + + // mask out bits before start and after end + Block fore = m_bits[bstart] & ( ~Block(0) << ind_start ), + aft = bend == num_blocks() ? 0 : m_bits[bend] & ( ~Block(0) >> (bits_per_block - ind_end) ); + if (bstart == bend) fore &= ( ~Block(0) >> (bits_per_block - ind_end) ); + + return fore? + bstart * bits_per_block + lowest_bit(fore) + : + m_do_find_from(bstart + 1); + + } + + +#if !defined BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS + // lexicographical comparison + template <typename B, typename A> + friend bool operator==(const dynamic_bitset<B, A>& a, + const dynamic_bitset<B, A>& b); + + template <typename B, typename A> + friend bool operator<(const dynamic_bitset<B, A>& a, + const dynamic_bitset<B, A>& b); + + + template <typename B, typename A, typename BlockOutputIterator> + friend void to_block_range(const dynamic_bitset<B, A>& b, + BlockOutputIterator result); + + template <typename BlockIterator, typename B, typename A> + friend void from_block_range(BlockIterator first, BlockIterator last, + dynamic_bitset<B, A>& result); + + + template <typename CharT, typename Traits, typename B, typename A> + friend std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, + dynamic_bitset<B, A>& b); + + template <typename B, typename A, typename stringT> + friend void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s, bool dump_all); + + +#endif + + +private: + BOOST_STATIC_CONSTANT(block_width_type, ulong_width = std::numeric_limits<unsigned long>::digits); + typedef std::vector<block_type, allocator_type> buffer_type; + + void m_zero_unused_bits(); + bool m_check_invariants() const; + + size_type m_do_find_from(size_type first_block) const; + + block_width_type count_extra_bits() const { return bit_index(size()); } + static size_type block_index(size_type pos) { return pos / bits_per_block; } + static block_width_type bit_index(size_type pos) { return static_cast<block_width_type>(pos % bits_per_block); } + static Block bit_mask(size_type pos) { return Block(1) << bit_index(pos); } + + template <typename CharT, typename Traits, typename Alloc> + void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s, + typename std::basic_string<CharT, Traits, Alloc>::size_type pos, + typename std::basic_string<CharT, Traits, Alloc>::size_type n, + size_type num_bits) + { + assert(pos <= s.size()); + + typedef typename std::basic_string<CharT, Traits, Alloc> StrT; + typedef typename StrT::traits_type Tr; + + const typename StrT::size_type rlen = (std::min)(n, s.size() - pos); + const size_type sz = ( num_bits != npos? num_bits : rlen); + m_bits.resize(calc_num_blocks(sz)); + m_num_bits = sz; + + + BOOST_DYNAMIC_BITSET_CTYPE_FACET(CharT, fac, std::locale()); + const CharT one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1'); + + const size_type m = num_bits < rlen ? num_bits : rlen; + typename StrT::size_type i = 0; + for( ; i < m; ++i) { + + const CharT c = s[(pos + m - 1) - i]; + + assert( Tr::eq(c, one) + || Tr::eq(c, BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0')) ); + + if (Tr::eq(c, one)) + set(i); + + } + + } + + void init_from_unsigned_long(size_type num_bits, + unsigned long value/*, + const Allocator& alloc*/) + { + + assert(m_bits.size() == 0); + + m_bits.resize(calc_num_blocks(num_bits)); + m_num_bits = num_bits; + + typedef unsigned long num_type; + typedef boost::detail::dynamic_bitset_impl + ::shifter<num_type, bits_per_block, ulong_width> shifter; + + //if (num_bits == 0) + // return; + + // zero out all bits at pos >= num_bits, if any; + // note that: num_bits == 0 implies value == 0 + if (num_bits < static_cast<size_type>(ulong_width)) { + const num_type mask = (num_type(1) << num_bits) - 1; + value &= mask; + } + + typename buffer_type::iterator it = m_bits.begin(); + for( ; value; shifter::left_shift(value), ++it) { + *it = static_cast<block_type>(value); + } + + } + + + +BOOST_DYNAMIC_BITSET_PRIVATE: + + bool m_unchecked_test(size_type pos) const; + static size_type calc_num_blocks(size_type num_bits); + + Block& m_highest_block(); + const Block& m_highest_block() const; + + buffer_type m_bits; + size_type m_num_bits; + + + class bit_appender; + friend class bit_appender; + class bit_appender { + // helper for stream >> + // Supplies to the lack of an efficient append at the less + // significant end: bits are actually appended "at left" but + // rearranged in the destructor. From the perspective of + // client code everything works *as if* dynamic_bitset<> had + // an append_at_right() function (eventually throwing the same + // exceptions as push_back) except that the function is in fact + // called bit_appender::do_append(). + // + dynamic_bitset & bs; + size_type n; + Block mask; + Block * current; + + // not implemented + bit_appender(const bit_appender &); + bit_appender & operator=(const bit_appender &); + + public: + bit_appender(dynamic_bitset & r) : bs(r), n(0), mask(0), current(0) {} + ~bit_appender() { + // reverse the order of blocks, shift + // if needed, and then resize + // + std::reverse(bs.m_bits.begin(), bs.m_bits.end()); + const block_width_type offs = bit_index(n); + if (offs) + bs >>= (bits_per_block - offs); + bs.resize(n); // doesn't enlarge, so can't throw + assert(bs.m_check_invariants()); + } + inline void do_append(bool value) { + + if (mask == 0) { + bs.append(Block(0)); + current = &bs.m_highest_block(); + mask = Block(1) << (bits_per_block - 1); + } + + if(value) + *current |= mask; + + mask /= 2; + ++n; + } + size_type get_count() const { return n; } + }; + +}; + +#if defined(__IBMCPP__) && BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) + +// Workaround for IBM's AIX platform. +// See http://comments.gmane.org/gmane.comp.lib.boost.user/15331 +// +// NOTE: +// The compiler is actually right, until core issue 454 will be settled: +// <http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#454> +// +// It's arguable whether we want to mark this with BOOST_WORKAROUND or not. + + +template<typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>::block_width_type const +dynamic_bitset<Block, Allocator>::bits_per_block; + +template<typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>::block_width_type const +dynamic_bitset<Block, Allocator>::ulong_width; + +#endif + +// Global Functions: + +// comparison +template <typename Block, typename Allocator> +bool operator!=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b); + +template <typename Block, typename Allocator> +bool operator<=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b); + +template <typename Block, typename Allocator> +bool operator>(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b); + +template <typename Block, typename Allocator> +bool operator>=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b); + +// stream operators +#ifdef BOOST_OLD_IOSTREAMS +template <typename Block, typename Allocator> +std::ostream& operator<<(std::ostream& os, + const dynamic_bitset<Block, Allocator>& b); + +template <typename Block, typename Allocator> +std::istream& operator>>(std::istream& is, dynamic_bitset<Block,Allocator>& b); +#else +template <typename CharT, typename Traits, typename Block, typename Allocator> +std::basic_ostream<CharT, Traits>& +operator<<(std::basic_ostream<CharT, Traits>& os, + const dynamic_bitset<Block, Allocator>& b); + +template <typename CharT, typename Traits, typename Block, typename Allocator> +std::basic_istream<CharT, Traits>& +operator>>(std::basic_istream<CharT, Traits>& is, + dynamic_bitset<Block, Allocator>& b); +#endif + +// bitset operations +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator&(const dynamic_bitset<Block, Allocator>& b1, + const dynamic_bitset<Block, Allocator>& b2); + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator|(const dynamic_bitset<Block, Allocator>& b1, + const dynamic_bitset<Block, Allocator>& b2); + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator^(const dynamic_bitset<Block, Allocator>& b1, + const dynamic_bitset<Block, Allocator>& b2); + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator-(const dynamic_bitset<Block, Allocator>& b1, + const dynamic_bitset<Block, Allocator>& b2); + +// namespace scope swap +template<typename Block, typename Allocator> +void swap(dynamic_bitset<Block, Allocator>& b1, + dynamic_bitset<Block, Allocator>& b2); + + +template <typename Block, typename Allocator, typename stringT> +void +to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s); + +template <typename Block, typename Allocator, typename BlockOutputIterator> +void +to_block_range(const dynamic_bitset<Block, Allocator>& b, + BlockOutputIterator result); + + +template <typename BlockIterator, typename B, typename A> +inline void +from_block_range(BlockIterator first, BlockIterator last, + dynamic_bitset<B, A>& result) +{ + // PRE: distance(first, last) <= numblocks() + std::copy (first, last, result.m_bits.begin()); +} + +//============================================================================= +// dynamic_bitset implementation + + +//----------------------------------------------------------------------------- +// constructors, etc. + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>::dynamic_bitset(const Allocator& alloc) + : m_bits(alloc), m_num_bits(0) +{ + +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>:: +dynamic_bitset(size_type num_bits, unsigned long value, const Allocator& alloc) + : m_bits(alloc), + m_num_bits(0) +{ + init_from_unsigned_long(num_bits, value); +} + +// copy constructor +template <typename Block, typename Allocator> +inline dynamic_bitset<Block, Allocator>:: +dynamic_bitset(const dynamic_bitset& b) + : m_bits(b.m_bits), m_num_bits(b.m_num_bits) +{ + +} + +template <typename Block, typename Allocator> +inline dynamic_bitset<Block, Allocator>:: +~dynamic_bitset() +{ + assert(m_check_invariants()); +} + +template <typename Block, typename Allocator> +inline void dynamic_bitset<Block, Allocator>:: +swap(dynamic_bitset<Block, Allocator>& b) // no throw +{ + std::swap(m_bits, b.m_bits); + std::swap(m_num_bits, b.m_num_bits); +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>:: +operator=(const dynamic_bitset<Block, Allocator>& b) +{ + m_bits = b.m_bits; + m_num_bits = b.m_num_bits; + return *this; +} + +template <typename Block, typename Allocator> +inline typename dynamic_bitset<Block, Allocator>::allocator_type +dynamic_bitset<Block, Allocator>::get_allocator() const +{ + return m_bits.get_allocator(); +} + +//----------------------------------------------------------------------------- +// size changing operations + +template <typename Block, typename Allocator> +void dynamic_bitset<Block, Allocator>:: +resize(size_type num_bits, bool value) // strong guarantee +{ + + const size_type old_num_blocks = num_blocks(); + const size_type required_blocks = calc_num_blocks(num_bits); + + const block_type v = value? ~Block(0) : Block(0); + + if (required_blocks != old_num_blocks) { + m_bits.resize(required_blocks, v); // s.g. (copy) + } + + + // At this point: + // + // - if the buffer was shrunk, we have nothing more to do, + // except a call to m_zero_unused_bits() + // + // - if it was enlarged, all the (used) bits in the new blocks have + // the correct value, but we have not yet touched those bits, if + // any, that were 'unused bits' before enlarging: if value == true, + // they must be set. + + if (value && (num_bits > m_num_bits)) { + + const size_type extra_bits = count_extra_bits(); + if (extra_bits) { + assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size()); + + // Set them. + m_bits[old_num_blocks - 1] |= (v << extra_bits); + } + + } + + m_num_bits = num_bits; + m_zero_unused_bits(); + +} + +template <typename Block, typename Allocator> +void dynamic_bitset<Block, Allocator>:: +clear() // no throw +{ + m_bits.clear(); + m_num_bits = 0; +} + + +template <typename Block, typename Allocator> +void dynamic_bitset<Block, Allocator>:: +push_back(bool bit) +{ + const size_type sz = size(); + resize(sz + 1); + set(sz, bit); +} + +template <typename Block, typename Allocator> +void dynamic_bitset<Block, Allocator>:: +append(Block value) // strong guarantee +{ + const block_width_type r = count_extra_bits(); + + if (r == 0) { + // the buffer is empty, or all blocks are filled + m_bits.push_back(value); + } + else { + m_bits.push_back(value >> (bits_per_block - r)); + m_bits[m_bits.size() - 2] |= (value << r); // m_bits.size() >= 2 + } + + m_num_bits += bits_per_block; + assert(m_check_invariants()); + +} + + +//----------------------------------------------------------------------------- +// bitset operations +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::operator&=(const dynamic_bitset& rhs) +{ + assert(size() == rhs.size()); + for (size_type i = 0; i < num_blocks(); ++i) + m_bits[i] &= rhs.m_bits[i]; + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::operator|=(const dynamic_bitset& rhs) +{ + assert(size() == rhs.size()); + for (size_type i = 0; i < num_blocks(); ++i) + m_bits[i] |= rhs.m_bits[i]; + //m_zero_unused_bits(); + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::operator^=(const dynamic_bitset& rhs) +{ + assert(size() == rhs.size()); + for (size_type i = 0; i < this->num_blocks(); ++i) + m_bits[i] ^= rhs.m_bits[i]; + //m_zero_unused_bits(); + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::operator-=(const dynamic_bitset& rhs) +{ + assert(size() == rhs.size()); + for (size_type i = 0; i < num_blocks(); ++i) + m_bits[i] &= ~rhs.m_bits[i]; + //m_zero_unused_bits(); + return *this; +} + +// +// NOTE: +// Note that the 'if (r != 0)' is crucial to avoid undefined +// behavior when the left hand operand of >> isn't promoted to a +// wider type (because rs would be too large). +// +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::operator<<=(size_type n) +{ + if (n >= m_num_bits) + return reset(); + //else + if (n > 0) { + + size_type const last = num_blocks() - 1; // num_blocks() is >= 1 + size_type const div = n / bits_per_block; // div is <= last + block_width_type const r = bit_index(n); + block_type * const b = &m_bits[0]; + + if (r != 0) { + + block_width_type const rs = bits_per_block - r; + + for (size_type i = last-div; i>0; --i) { + b[i+div] = (b[i] << r) | (b[i-1] >> rs); + } + b[div] = b[0] << r; + + } + else { + for (size_type i = last-div; i>0; --i) { + b[i+div] = b[i]; + } + b[div] = b[0]; + } + + // zero out div blocks at the less significant end + std::fill_n(b, div, static_cast<block_type>(0)); + + // zero out any 1 bit that flowed into the unused part + m_zero_unused_bits(); // thanks to Lester Gong + + } + + return *this; + + +} + + +// +// NOTE: +// see the comments to operator <<= +// +template <typename B, typename A> +dynamic_bitset<B, A> & dynamic_bitset<B, A>::operator>>=(size_type n) { + if (n >= m_num_bits) { + return reset(); + } + //else + if (n>0) { + + size_type const last = num_blocks() - 1; // num_blocks() is >= 1 + size_type const div = n / bits_per_block; // div is <= last + block_width_type const r = bit_index(n); + block_type * const b = &m_bits[0]; + + + if (r != 0) { + + block_width_type const ls = bits_per_block - r; + + for (size_type i = div; i < last; ++i) { + b[i-div] = (b[i] >> r) | (b[i+1] << ls); + } + // r bits go to zero + b[last-div] = b[last] >> r; + } + + else { + for (size_type i = div; i <= last; ++i) { + b[i-div] = b[i]; + } + // note the '<=': the last iteration 'absorbs' + // b[last-div] = b[last] >> 0; + } + + + + // div blocks are zero filled at the most significant end + std::fill_n(b + (num_blocks()-div), div, static_cast<block_type>(0)); + } + + return *this; +} + + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +dynamic_bitset<Block, Allocator>::operator<<(size_type n) const +{ + dynamic_bitset r(*this); + return r <<= n; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +dynamic_bitset<Block, Allocator>::operator>>(size_type n) const +{ + dynamic_bitset r(*this); + return r >>= n; +} + + +//----------------------------------------------------------------------------- +// basic bit operations + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::set(size_type pos, bool val) +{ + assert(pos < m_num_bits); + + if (val) + m_bits[block_index(pos)] |= bit_mask(pos); + else + reset(pos); + + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::set() +{ + std::fill(m_bits.begin(), m_bits.end(), ~Block(0)); + m_zero_unused_bits(); + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::reset(size_type pos) +{ + assert(pos < m_num_bits); +#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x + // CodeWarrior 8 generates incorrect code when the &=~ is compiled, + // use the |^ variation instead.. <grafik> + m_bits[block_index(pos)] |= bit_mask(pos); + m_bits[block_index(pos)] ^= bit_mask(pos); +#else + m_bits[block_index(pos)] &= ~bit_mask(pos); +#endif + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::reset() +{ + std::fill(m_bits.begin(), m_bits.end(), Block(0)); + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::flip(size_type pos) +{ + assert(pos < m_num_bits); + m_bits[block_index(pos)] ^= bit_mask(pos); + return *this; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator>& +dynamic_bitset<Block, Allocator>::flip() +{ + for (size_type i = 0; i < num_blocks(); ++i) + m_bits[i] = ~m_bits[i]; + m_zero_unused_bits(); + return *this; +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>::m_unchecked_test(size_type pos) const +{ + return (m_bits[block_index(pos)] & bit_mask(pos)) != 0; +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>::test(size_type pos) const +{ + assert(pos < m_num_bits); + return m_unchecked_test(pos); +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>::any() const +{ + for (size_type i = 0; i < num_blocks(); ++i) + if (m_bits[i]) + return true; + return false; +} + +template <typename Block, typename Allocator> +inline bool dynamic_bitset<Block, Allocator>::none() const +{ + return !any(); +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +dynamic_bitset<Block, Allocator>::operator~() const +{ + dynamic_bitset b(*this); + b.flip(); + return b; +} + +template <typename Block, typename Allocator> +typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::count() const +{ + using detail::dynamic_bitset_impl::table_width; + using detail::dynamic_bitset_impl::access_by_bytes; + using detail::dynamic_bitset_impl::access_by_blocks; + using detail::dynamic_bitset_impl::value_to_type; + + // NOTE: Explicitly qualifying "bits_per_block" to workaround + // regressions of gcc 3.4.x + const bool no_padding = + dynamic_bitset<Block, Allocator>::bits_per_block + == CHAR_BIT * sizeof(Block); + + const bool enough_table_width = table_width >= CHAR_BIT; + + const bool mode = (no_padding && enough_table_width) + ? access_by_bytes + : access_by_blocks; + + return do_count(m_bits.begin(), num_blocks(), Block(0), + static_cast<value_to_type<mode> *>(0)); +} + + +//----------------------------------------------------------------------------- +// conversions + + +template <typename B, typename A, typename stringT> +void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s, + bool dump_all) +{ + typedef typename stringT::traits_type Tr; + typedef typename stringT::value_type Ch; + + BOOST_DYNAMIC_BITSET_CTYPE_FACET(Ch, fac, std::locale()); + const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0'); + const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1'); + + // Note that this function may access (when + // dump_all == true) bits beyond position size() - 1 + + typedef typename dynamic_bitset<B, A>::size_type size_type; + + const size_type len = dump_all? + dynamic_bitset<B, A>::bits_per_block * b.num_blocks(): + b.size(); + s.assign (len, zero); + + for (size_type i = 0; i < len; ++i) { + if (b.m_unchecked_test(i)) + Tr::assign(s[len - 1 - i], one); + + } + +} + + +// A comment similar to the one about the constructor from +// basic_string can be done here. Thanks to James Kanze for +// making me (Gennaro) realize this important separation of +// concerns issue, as well as many things about i18n. +// +template <typename Block, typename Allocator, typename stringT> +inline void +to_string(const dynamic_bitset<Block, Allocator>& b, stringT& s) +{ + to_string_helper(b, s, false); +} + + +// Differently from to_string this function dumps out +// every bit of the internal representation (may be +// useful for debugging purposes) +// +template <typename B, typename A, typename stringT> +inline void +dump_to_string(const dynamic_bitset<B, A>& b, stringT& s) +{ + to_string_helper(b, s, true /* =dump_all*/); +} + +template <typename Block, typename Allocator, typename BlockOutputIterator> +inline void +to_block_range(const dynamic_bitset<Block, Allocator>& b, + BlockOutputIterator result) +{ + // note how this copies *all* bits, including the + // unused ones in the last block (which are zero) + std::copy(b.m_bits.begin(), b.m_bits.end(), result); +} + +template <typename Block, typename Allocator> +unsigned long dynamic_bitset<Block, Allocator>:: +to_ulong() const +{ + + if (m_num_bits == 0) + return 0; // convention + + // Check for overflows. This may be a performance burden on very + // large bitsets but is required by the specification, sorry + if (find_next(ulong_width - 1) != npos) + throw std::overflow_error("boost::dynamic_bitset::to_ulong overflow"); + + + // Ok, from now on we can be sure there's no "on" bit + // beyond the "allowed" positions + typedef unsigned long result_type; + + const size_type max_size = + (std::min)(m_num_bits, static_cast<size_type>(ulong_width)); + + const size_type last_block = block_index( max_size - 1 ); + + assert((last_block * bits_per_block) < static_cast<size_type>(ulong_width)); + + result_type result = 0; + for (size_type i = 0; i <= last_block; ++i) { + const size_type offset = i * bits_per_block; + result |= (static_cast<result_type>(m_bits[i]) << offset); + } + + return result; +} + +template <typename Block, typename Allocator> +inline typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::size() const +{ + return m_num_bits; +} + +template <typename Block, typename Allocator> +inline typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::num_blocks() const +{ + return m_bits.size(); +} + +template <typename Block, typename Allocator> +inline typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::max_size() const +{ + // Semantics of vector<>::max_size() aren't very clear + // (see lib issue 197) and many library implementations + // simply return dummy values, _unrelated_ to the underlying + // allocator. + // + // Given these problems, I was tempted to not provide this + // function at all but the user could need it if he provides + // his own allocator. + // + + const size_type m = detail::dynamic_bitset_impl:: + vector_max_size_workaround(m_bits); + + return m <= (size_type(-1)/bits_per_block) ? + m * bits_per_block : + size_type(-1); +} + +template <typename Block, typename Allocator> +inline bool dynamic_bitset<Block, Allocator>::empty() const +{ + return size() == 0; +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>:: +is_subset_of(const dynamic_bitset<Block, Allocator>& a) const +{ + assert(size() == a.size()); + for (size_type i = 0; i < num_blocks(); ++i) + if (m_bits[i] & ~a.m_bits[i]) + return false; + return true; +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>:: +is_proper_subset_of(const dynamic_bitset<Block, Allocator>& a) const +{ + assert(size() == a.size()); + assert(num_blocks() == a.num_blocks()); + + bool proper = false; + for (size_type i = 0; i < num_blocks(); ++i) { + const Block & bt = m_bits[i]; + const Block & ba = a.m_bits[i]; + + if (bt & ~ba) + return false; // not a subset at all + if (ba & ~bt) + proper = true; + } + return proper; +} + +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>::intersects(const dynamic_bitset & b) const +{ + size_type common_blocks = num_blocks() < b.num_blocks() + ? num_blocks() : b.num_blocks(); + + for(size_type i = 0; i < common_blocks; ++i) { + if(m_bits[i] & b.m_bits[i]) + return true; + } + return false; +} + +// -------------------------------- +// lookup + + +// look for the first bit "on", starting +// from the block with index first_block +// +template <typename Block, typename Allocator> +typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::m_do_find_from(size_type first_block) const +{ + size_type i = first_block; + + // skip null blocks + while (i < num_blocks() && m_bits[i] == 0) + ++i; + + if (i >= num_blocks()) + return npos; // not found + + return i * bits_per_block + boost::lowest_bit(m_bits[i]); + +} + + +template <typename Block, typename Allocator> +typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::find_first() const +{ + return m_do_find_from(0); +} + + +template <typename Block, typename Allocator> +typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::find_next(size_type pos) const +{ + + const size_type sz = size(); + if (pos >= (sz-1) || sz == 0) + return npos; + + ++pos; + + const size_type blk = block_index(pos); + const block_width_type ind = bit_index(pos); + + // mask out bits before pos + const Block fore = m_bits[blk] & ( ~Block(0) << ind ); + + return fore? + blk * bits_per_block + lowest_bit(fore) + : + m_do_find_from(blk + 1); + +} + + + +//----------------------------------------------------------------------------- +// comparison + +template <typename Block, typename Allocator> +bool operator==(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + return (a.m_num_bits == b.m_num_bits) + && (a.m_bits == b.m_bits); +} + +template <typename Block, typename Allocator> +inline bool operator!=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + return !(a == b); +} + +template <typename Block, typename Allocator> +bool operator<(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + assert(a.size() == b.size()); + typedef typename dynamic_bitset<Block, Allocator>::size_type size_type; + + //if (a.size() == 0) + // return false; + + // Since we are storing the most significant bit + // at pos == size() - 1, we need to do the comparisons in reverse. + // + for (size_type ii = a.num_blocks(); ii > 0; --ii) { + size_type i = ii-1; + if (a.m_bits[i] < b.m_bits[i]) + return true; + else if (a.m_bits[i] > b.m_bits[i]) + return false; + } + return false; +} + +template <typename Block, typename Allocator> +inline bool operator<=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + return !(a > b); +} + +template <typename Block, typename Allocator> +inline bool operator>(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + return b < a; +} + +template <typename Block, typename Allocator> +inline bool operator>=(const dynamic_bitset<Block, Allocator>& a, + const dynamic_bitset<Block, Allocator>& b) +{ + return !(a < b); +} + +//----------------------------------------------------------------------------- +// stream operations + +#ifdef BOOST_OLD_IOSTREAMS +template < typename Block, typename Alloc> +std::ostream& +operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b) +{ + // NOTE: since this is aimed at "classic" iostreams, exception + // masks on the stream are not supported. The library that + // ships with gcc 2.95 has an exceptions() member function but + // nothing is actually implemented; not even the class ios::failure. + + using namespace std; + + const ios::iostate ok = ios::goodbit; + ios::iostate err = ok; + + if (os.opfx()) { + + //try + typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type; + + const bitsetsize_type sz = b.size(); + std::streambuf * buf = os.rdbuf(); + size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0) + || (bitsetsize_type) os.width() <= sz? 0 : os.width() - sz; + + const char fill_char = os.fill(); + const ios::fmtflags adjustfield = os.flags() & ios::adjustfield; + + // if needed fill at left; pad is decresed along the way + if (adjustfield != ios::left) { + for (; 0 < npad; --npad) + if (fill_char != buf->sputc(fill_char)) { + err |= ios::failbit; + break; + } + } + + if (err == ok) { + // output the bitset + for (bitsetsize_type i = b.size(); 0 < i; --i) { + const char dig = b.test(i-1)? '1' : '0'; + if (EOF == buf->sputc(dig)) { + err |= ios::failbit; + break; + } + } + } + + if (err == ok) { + // if needed fill at right + for (; 0 < npad; --npad) { + if (fill_char != buf->sputc(fill_char)) { + err |= ios::failbit; + break; + } + } + } + + os.osfx(); + os.width(0); + + } // if opfx + + if(err != ok) + os.setstate(err); // assume this does NOT throw + return os; + +} +#else + +template <typename Ch, typename Tr, typename Block, typename Alloc> +std::basic_ostream<Ch, Tr>& +operator<<(std::basic_ostream<Ch, Tr>& os, + const dynamic_bitset<Block, Alloc>& b) +{ + + using namespace std; + + const ios_base::iostate ok = ios_base::goodbit; + ios_base::iostate err = ok; + + typename basic_ostream<Ch, Tr>::sentry cerberos(os); + if (cerberos) { + + BOOST_DYNAMIC_BITSET_CTYPE_FACET(Ch, fac, os.getloc()); + const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0'); + const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1'); + + try { + + typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type; + typedef basic_streambuf<Ch, Tr> buffer_type; + + buffer_type * buf = os.rdbuf(); + size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0) + || (bitsetsize_type) os.width() <= b.size()? 0 : os.width() - b.size(); + + const Ch fill_char = os.fill(); + const ios_base::fmtflags adjustfield = os.flags() & ios_base::adjustfield; + + // if needed fill at left; pad is decresed along the way + if (adjustfield != ios_base::left) { + for (; 0 < npad; --npad) + if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) { + err |= ios_base::failbit; + break; + } + } + + if (err == ok) { + // output the bitset + for (bitsetsize_type i = b.size(); 0 < i; --i) { + typename buffer_type::int_type + ret = buf->sputc(b.test(i-1)? one : zero); + if (Tr::eq_int_type(Tr::eof(), ret)) { + err |= ios_base::failbit; + break; + } + } + } + + if (err == ok) { + // if needed fill at right + for (; 0 < npad; --npad) { + if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) { + err |= ios_base::failbit; + break; + } + } + } + + + os.width(0); + + } catch (...) { // see std 27.6.1.1/4 + bool rethrow = false; + try { os.setstate(ios_base::failbit); } catch (...) { rethrow = true; } + + if (rethrow) + throw; + } + } + + if(err != ok) + os.setstate(err); // may throw exception + return os; + +} +#endif + + +#ifdef BOOST_OLD_IOSTREAMS + + // A sentry-like class that calls isfx in its destructor. + // "Necessary" because bit_appender::do_append may throw. + class pseudo_sentry { + std::istream & m_r; + const bool m_ok; + public: + explicit pseudo_sentry(std::istream & r) : m_r(r), m_ok(r.ipfx(0)) { } + ~pseudo_sentry() { m_r.isfx(); } + operator bool() const { return m_ok; } + }; + +template <typename Block, typename Alloc> +std::istream& +operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b) +{ + +// Extractor for classic IO streams (libstdc++ < 3.0) +// ----------------------------------------------------// +// It's assumed that the stream buffer functions, and +// the stream's setstate() _cannot_ throw. + + + typedef dynamic_bitset<Block, Alloc> bitset_type; + typedef typename bitset_type::size_type size_type; + + std::ios::iostate err = std::ios::goodbit; + pseudo_sentry cerberos(is); // skips whitespaces + if(cerberos) { + + b.clear(); + + const std::streamsize w = is.width(); + const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size() + ? w : b.max_size(); + typename bitset_type::bit_appender appender(b); + std::streambuf * buf = is.rdbuf(); + for(int c = buf->sgetc(); appender.get_count() < limit; c = buf->snextc() ) { + + if (c == EOF) { + err |= std::ios::eofbit; + break; + } + else if (char(c) != '0' && char(c) != '1') + break; // non digit character + + else { + try { + appender.do_append(char(c) == '1'); + } + catch(...) { + is.setstate(std::ios::failbit); // assume this can't throw + throw; + } + } + + } // for + } + + is.width(0); + if (b.size() == 0) + err |= std::ios::failbit; + if (err != std::ios::goodbit) + is.setstate (err); // may throw + + return is; +} + +#else // BOOST_OLD_IOSTREAMS + +template <typename Ch, typename Tr, typename Block, typename Alloc> +std::basic_istream<Ch, Tr>& +operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b) +{ + + using namespace std; + + typedef dynamic_bitset<Block, Alloc> bitset_type; + typedef typename bitset_type::size_type size_type; + + const streamsize w = is.width(); + const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()? + w : b.max_size(); + + ios_base::iostate err = ios_base::goodbit; + typename basic_istream<Ch, Tr>::sentry cerberos(is); // skips whitespaces + if(cerberos) { + + // in accordance with prop. resol. of lib DR 303 [last checked 4 Feb 2004] + BOOST_DYNAMIC_BITSET_CTYPE_FACET(Ch, fac, is.getloc()); + const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0'); + const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1'); + + b.clear(); + try { + typename bitset_type::bit_appender appender(b); + basic_streambuf <Ch, Tr> * buf = is.rdbuf(); + typename Tr::int_type c = buf->sgetc(); + for( ; appender.get_count() < limit; c = buf->snextc() ) { + + if (Tr::eq_int_type(Tr::eof(), c)) { + err |= ios_base::eofbit; + break; + } + else { + const Ch to_c = Tr::to_char_type(c); + const bool is_one = Tr::eq(to_c, one); + + if (!is_one && !Tr::eq(to_c, zero)) + break; // non digit character + + appender.do_append(is_one); + + } + + } // for + } + catch (...) { + // catches from stream buf, or from vector: + // + // bits_stored bits have been extracted and stored, and + // either no further character is extractable or we can't + // append to the underlying vector (out of memory) + + bool rethrow = false; // see std 27.6.1.1/4 + try { is.setstate(ios_base::badbit); } + catch(...) { rethrow = true; } + + if (rethrow) + throw; + + } + } + + is.width(0); + if (b.size() == 0 /*|| !cerberos*/) + err |= ios_base::failbit; + if (err != ios_base::goodbit) + is.setstate (err); // may throw + + return is; + +} + + +#endif + + +//----------------------------------------------------------------------------- +// bitset operations + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator&(const dynamic_bitset<Block, Allocator>& x, + const dynamic_bitset<Block, Allocator>& y) +{ + dynamic_bitset<Block, Allocator> b(x); + return b &= y; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator|(const dynamic_bitset<Block, Allocator>& x, + const dynamic_bitset<Block, Allocator>& y) +{ + dynamic_bitset<Block, Allocator> b(x); + return b |= y; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator^(const dynamic_bitset<Block, Allocator>& x, + const dynamic_bitset<Block, Allocator>& y) +{ + dynamic_bitset<Block, Allocator> b(x); + return b ^= y; +} + +template <typename Block, typename Allocator> +dynamic_bitset<Block, Allocator> +operator-(const dynamic_bitset<Block, Allocator>& x, + const dynamic_bitset<Block, Allocator>& y) +{ + dynamic_bitset<Block, Allocator> b(x); + return b -= y; +} + +//----------------------------------------------------------------------------- +// namespace scope swap + +template<typename Block, typename Allocator> +inline void +swap(dynamic_bitset<Block, Allocator>& left, + dynamic_bitset<Block, Allocator>& right) // no throw +{ + left.swap(right); +} + + +//----------------------------------------------------------------------------- +// private (on conforming compilers) member functions + + +template <typename Block, typename Allocator> +inline typename dynamic_bitset<Block, Allocator>::size_type +dynamic_bitset<Block, Allocator>::calc_num_blocks(size_type num_bits) +{ + return num_bits / bits_per_block + + static_cast<int>( num_bits % bits_per_block != 0 ); +} + +// gives a reference to the highest block +// +template <typename Block, typename Allocator> +inline Block& dynamic_bitset<Block, Allocator>::m_highest_block() +{ + return const_cast<Block &> + (static_cast<const dynamic_bitset *>(this)->m_highest_block()); +} + +// gives a const-reference to the highest block +// +template <typename Block, typename Allocator> +inline const Block& dynamic_bitset<Block, Allocator>::m_highest_block() const +{ + assert(size() > 0 && num_blocks() > 0); + return m_bits.back(); +} + + +// If size() is not a multiple of bits_per_block +// then not all the bits in the last block are used. +// This function resets the unused bits (convenient +// for the implementation of many member functions) +// +template <typename Block, typename Allocator> +inline void dynamic_bitset<Block, Allocator>::m_zero_unused_bits() +{ + assert (num_blocks() == calc_num_blocks(m_num_bits)); + + // if != 0 this is the number of bits used in the last block + const block_width_type extra_bits = count_extra_bits(); + + if (extra_bits != 0) + m_highest_block() &= ~(~static_cast<Block>(0) << extra_bits); + +} + +// check class invariants +template <typename Block, typename Allocator> +bool dynamic_bitset<Block, Allocator>::m_check_invariants() const +{ + const block_width_type extra_bits = count_extra_bits(); + if (extra_bits > 0) { + block_type const mask = (~static_cast<Block>(0) << extra_bits); + if ((m_highest_block() & mask) != 0) + return false; + } + if (m_bits.size() > m_bits.capacity() || num_blocks() != calc_num_blocks(size())) + return false; + + return true; + +} + + +} // namespace boost + + +#undef BOOST_BITSET_CHAR + +#endif // include guard + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:06:41
|
Revision: 1491 http://assorted.svn.sourceforge.net/assorted/?rev=1491&view=rev Author: yangzhang Date: 2009-10-14 18:06:33 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added partial serialization/deserialization to versioned_heap Modified Paths: -------------- cpp-commons/trunk/src/commons/versioned_heap.h Modified: cpp-commons/trunk/src/commons/versioned_heap.h =================================================================== --- cpp-commons/trunk/src/commons/versioned_heap.h 2009-10-14 18:05:48 UTC (rev 1490) +++ cpp-commons/trunk/src/commons/versioned_heap.h 2009-10-14 18:06:33 UTC (rev 1491) @@ -349,6 +349,14 @@ } /** + * Deserialize a heap partially in place. + */ + void deser_partial(void *meta, void *data, size_t page_count) { + desermeta_partial(meta); + deserdata_partial(data, page_count); + } + + /** * Iterator. */ iterator begin() { return iterator(*this); } @@ -389,6 +397,24 @@ return r.read<size_t>(); } + void desermeta_partial(void *meta) { + raw_reader r(meta); + + // Deserialize metadata. + size_t first_free, last_free; + r.read(first_free); + r.read(last_free); + first_free_ = reinterpret_cast<hdr*>(first_free); + last_free_ = reinterpret_cast<hdr*>(last_free); + // TODO why do next 2 lines this give me this warning? + // error: dereferencing type-punned pointer will break strict-aliasing rules + //r.read(reinterpret_cast<size_t&>(first_free_)); + //r.read(reinterpret_cast<size_t&>(last_free_)); + r.read(pgsz_); + compute_layout<T>(pgsz_, pgcnt_, values_offset_, freemap_words_); + r.read<size_t>(); + } + /** * Deserialize a heap in place. */ @@ -402,6 +428,27 @@ } } + /** + * Deserialize a partial heap in place. + */ + void deserdata_partial(void *data, size_t page_count) { + char *p0 = reinterpret_cast<char*>(data); + char *end = p0 + page_count * pgsz_; + for (char *p = p0; p < end; p += pgsz_) { + hdr &h = hdrof(p); + + check(h.index <= pages_.size()); + if (h.index < pages_.size()) pages_[h.index] = p; + else pages_.push_back(p); + + h.managed = false; + } + for (char *p = p0; p < end; p += pgsz_) { + hdrof(p).next_free = reinterpret_cast<hdr*>(pages_[size_t(hdrof(p).next_free)]); + } + first_free_ = reinterpret_cast<hdr*>(pages_[size_t(first_free_)]); + } + }; /** @@ -433,7 +480,39 @@ } } + /** + * \param[in] summary The start of the summary page entries. + * \param[in] summary_count The number of page entries in the summary. + */ template<typename T> + size_t serdata_partial(const versioned_heap<T> &heap, void *out, + raw_reader &summary_reader, size_t summary_count) + { + char *p = reinterpret_cast<char*>(out); + size_t i = 0, ser_count = 0; + foreach (void *page, heap.pages()) { + typedef typename versioned_heap<T>::hdr hdr; + hdr &h = *reinterpret_cast<hdr*>(page); + assert(i == h.index); + bool do_ser = true; + if (i < summary_count) { + checkeq(summary_reader.read<size_t>(), i); + // Serialize iff the other heap is behind our version. + do_ser = summary_reader.read<int>() < h.version; + } + if (do_ser) { + memcpy(p, page, heap.pgsz()); + ++ser_count; + hdr &h = *reinterpret_cast<hdr*>(p); + ptr2ind_mut(h.next_free); + p += heap.pgsz(); + } + ++i; + } + return ser_count; + } + + template<typename T> size_t ptr2ind(T *p) { return p == nullptr ? size_t(-1) : p->index; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:05:57
|
Revision: 1490 http://assorted.svn.sourceforge.net/assorted/?rev=1490&view=rev Author: yangzhang Date: 2009-10-14 18:05:48 +0000 (Wed, 14 Oct 2009) Log Message: ----------- overloaded write_file; added try_rm Modified Paths: -------------- cpp-commons/trunk/src/commons/files.h Modified: cpp-commons/trunk/src/commons/files.h =================================================================== --- cpp-commons/trunk/src/commons/files.h 2009-10-14 18:05:13 UTC (rev 1489) +++ cpp-commons/trunk/src/commons/files.h 2009-10-14 18:05:48 UTC (rev 1490) @@ -78,13 +78,18 @@ return buf; } + UNUSED static void write_file(int fd, const void *buf, size_t len) + { + checkeqnneg(write(fd, buf, len), ssize_t(len)); + } + /** * Write a whole array to disk. */ - UNUSED static void write_file(const char *path, const char *buf, size_t len) + UNUSED static void write_file(const char *path, const void *buf, size_t len) { closingfd fd(checknnegerr(creat(path, 0644))); - checkeqnneg(write(fd, buf, len), ssize_t(len)); + write_file(fd, buf, len); } /** @@ -133,6 +138,16 @@ return buf; } + UNUSED static void try_rm(const char *path) + { + if (unlink(path) != 0 && errno != ENOENT) { + int e = errno; + check0x(e); + // TODO throw errno_exception(e); + } + errno = 0; + } + } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:05:20
|
Revision: 1489 http://assorted.svn.sourceforge.net/assorted/?rev=1489&view=rev Author: yangzhang Date: 2009-10-14 18:05:13 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added timed() macro Modified Paths: -------------- cpp-commons/trunk/src/commons/time.h Modified: cpp-commons/trunk/src/commons/time.h =================================================================== --- cpp-commons/trunk/src/commons/time.h 2009-10-14 18:04:49 UTC (rev 1488) +++ cpp-commons/trunk/src/commons/time.h 2009-10-14 18:05:13 UTC (rev 1489) @@ -45,6 +45,13 @@ long long start, last; }; +#define timed(label, stmt) \ + do { \ + timer t(label); \ + stmt; \ + t.print(); \ + } while (0); + } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:05:00
|
Revision: 1488 http://assorted.svn.sourceforge.net/assorted/?rev=1488&view=rev Author: yangzhang Date: 2009-10-14 18:04:49 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added math.h Added Paths: ----------- cpp-commons/trunk/src/commons/math.h Added: cpp-commons/trunk/src/commons/math.h =================================================================== --- cpp-commons/trunk/src/commons/math.h (rev 0) +++ cpp-commons/trunk/src/commons/math.h 2009-10-14 18:04:49 UTC (rev 1488) @@ -0,0 +1,20 @@ +#ifndef COMMONS_MATH_H +#define COMMONS_MATH_H + +#include <cmath> + +namespace commons { + + using namespace std; + + /* Round to integer. See also boost/math/special_functions/round.hpp. */ + template<typename T> + T round(T x) { return floor(x + .5); } + + /* Round number n to d decimal points. */ + template<typename T, typename U> + T round(T n, U d) { return floor(n / pow(.1, d) + .5) * pow(.1, d); } + +} + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 18:04:27
|
Revision: 1487 http://assorted.svn.sourceforge.net/assorted/?rev=1487&view=rev Author: yangzhang Date: 2009-10-14 18:04:14 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added note about concurrent_queue Modified Paths: -------------- cpp-commons/trunk/src/commons/squeue.h Modified: cpp-commons/trunk/src/commons/squeue.h =================================================================== --- cpp-commons/trunk/src/commons/squeue.h 2009-10-14 07:38:32 UTC (rev 1486) +++ cpp-commons/trunk/src/commons/squeue.h 2009-10-14 18:04:14 UTC (rev 1487) @@ -10,6 +10,10 @@ using namespace std; using namespace boost; + /** + * Written because TBB's concurrent_queue doesn't support C++0x, because we + * needed conditional puts (for bounded queues), and because it's easy. + */ template<typename T> class concurrent_queue { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 07:38:38
|
Revision: 1486 http://assorted.svn.sourceforge.net/assorted/?rev=1486&view=rev Author: yangzhang Date: 2009-10-14 07:38:32 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added network, makefile Added Paths: ----------- sandbox/trunk/src/win/mingw/Makefile sandbox/trunk/src/win/mingw/network.c Added: sandbox/trunk/src/win/mingw/Makefile =================================================================== --- sandbox/trunk/src/win/mingw/Makefile (rev 0) +++ sandbox/trunk/src/win/mingw/Makefile 2009-10-14 07:38:32 UTC (rev 1486) @@ -0,0 +1,3 @@ +CC = i586-mingw32msvc-gcc +all: hello network +network: LDLIBS = -lws2_32 Added: sandbox/trunk/src/win/mingw/network.c =================================================================== --- sandbox/trunk/src/win/mingw/network.c (rev 0) +++ sandbox/trunk/src/win/mingw/network.c 2009-10-14 07:38:32 UTC (rev 1486) @@ -0,0 +1,16 @@ +#define UNICODE +#include <windows.h> +#include <winsock2.h> +WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, + int nCmdShow) { + wchar_t str[] = L"hello, world!\n"; + DWORD count; + WSADATA wsaData; + WSAStartup(MAKEWORD(2,2), &wsaData); + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), + str, + sizeof str / sizeof(wchar_t), + &count, + NULL); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 07:32:00
|
Revision: 1485 http://assorted.svn.sourceforge.net/assorted/?rev=1485&view=rev Author: yangzhang Date: 2009-10-14 07:31:51 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added mingw demo Added Paths: ----------- sandbox/trunk/src/win/mingw/ sandbox/trunk/src/win/mingw/hello.c Added: sandbox/trunk/src/win/mingw/hello.c =================================================================== --- sandbox/trunk/src/win/mingw/hello.c (rev 0) +++ sandbox/trunk/src/win/mingw/hello.c 2009-10-14 07:31:51 UTC (rev 1485) @@ -0,0 +1,13 @@ +#define UNICODE +#include <windows.h> +WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, + int nCmdShow) { + wchar_t str[] = L"hello, world!\n"; + DWORD count; + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), + str, + sizeof str / sizeof(wchar_t), + &count, + NULL); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 04:58:28
|
Revision: 1484 http://assorted.svn.sourceforge.net/assorted/?rev=1484&view=rev Author: yangzhang Date: 2009-10-14 04:58:22 +0000 (Wed, 14 Oct 2009) Log Message: ----------- hdr-grep also searches titles Modified Paths: -------------- shell-tools/trunk/src/hdr-grep.py Modified: shell-tools/trunk/src/hdr-grep.py =================================================================== --- shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:52:45 UTC (rev 1483) +++ shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:58:22 UTC (rev 1484) @@ -1,10 +1,10 @@ #!/usr/bin/env python """ -Prints the titles of sections in stdin whose bodies contain the given query -text (case-insensitive). Assumes input is markdown-/pandoc-formatted and only -looks for level-1 and -2 headers (lines that are underlined with at least 3 = -or - characters). +Given a markdown-/pandoc-formatted document on stdin, print the titles of +sections whose titles or bodies contain the given query text +(case-insensitive). Only looks for underlined level-1 and -2 headers (lines +that are underlined with at least 3 = or - characters). """ from commons.seqs import pairwise @@ -15,6 +15,9 @@ for prev, line in pairwise(line.rstrip() for line in sys.stdin): if len(line) >= 3 and set(line) in [set('-'), set('=')]: hdr = prev - elif hdr is not None and query.lower() in line.lower(): + haystack = prev + else: + haystack = line + if hdr is not None and query.lower() in haystack.lower(): print hdr hdr = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-14 04:52:54
|
Revision: 1483 http://assorted.svn.sourceforge.net/assorted/?rev=1483&view=rev Author: yangzhang Date: 2009-10-14 04:52:45 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added hdr-grep Added Paths: ----------- shell-tools/trunk/src/hdr-grep.py Added: shell-tools/trunk/src/hdr-grep.py =================================================================== --- shell-tools/trunk/src/hdr-grep.py (rev 0) +++ shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:52:45 UTC (rev 1483) @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +""" +Prints the titles of sections in stdin whose bodies contain the given query +text (case-insensitive). Assumes input is markdown-/pandoc-formatted and only +looks for level-1 and -2 headers (lines that are underlined with at least 3 = +or - characters). +""" + +from commons.seqs import pairwise +import sys + +query = sys.argv[1] +hdr = None +for prev, line in pairwise(line.rstrip() for line in sys.stdin): + if len(line) >= 3 and set(line) in [set('-'), set('=')]: + hdr = prev + elif hdr is not None and query.lower() in line.lower(): + print hdr + hdr = None Property changes on: shell-tools/trunk/src/hdr-grep.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-13 22:54:06
|
Revision: 1482 http://assorted.svn.sourceforge.net/assorted/?rev=1482&view=rev Author: yangzhang Date: 2009-10-13 22:53:52 +0000 (Tue, 13 Oct 2009) Log Message: ----------- added ostream_overload demo Added Paths: ----------- sandbox/trunk/src/cc/ostream_overload.cc Added: sandbox/trunk/src/cc/ostream_overload.cc =================================================================== --- sandbox/trunk/src/cc/ostream_overload.cc (rev 0) +++ sandbox/trunk/src/cc/ostream_overload.cc 2009-10-13 22:53:52 UTC (rev 1482) @@ -0,0 +1,77 @@ +// <http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16> + +#include <iostream> +#include <iomanip> + +using namespace std; + +// This doesn't work. + +#if 0 + +template<typename T> +class word_fmt +{ + public: + word_fmt(T x) : x_(x) {} + friend ostream & operator<<(ostream &o, word_fmt w); + private: + T x_; +}; + +template<typename T> +ostream & operator<<(ostream &o, word_fmt<T> w) { + o << setfill('0') << setw(8) << hex << w.x_; + return o; +} + +#endif + +// This works. + +#if 0 +template<typename T> +class word_fmt +{ + public: + word_fmt(T x) : x_(x) {} + // Defining in-body works. + friend ostream & operator<<(ostream &o, word_fmt w) { + o << setfill('0') << setw(8) << hex << w.x_; + return o; + } + private: + T x_; +}; +#endif + +// This also works: pre-declaring template, and adding `<>`. + +template<typename T> class word_fmt; +template<typename T> ostream & operator<<(ostream &o, word_fmt<T> w); + +template<typename T> +class word_fmt +{ + public: + word_fmt(T x) : x_(x) {} + // Defining in-body works. + friend ostream & operator<< <>(ostream &o, word_fmt w); + private: + T x_; +}; + +template<typename T> +ostream & operator<<(ostream &o, word_fmt<T> w) { + o << setfill('0') << setw(8) << hex << w.x_; + return o; +} + +// The rest. + +template<typename T> word_fmt<T> word(T x) { return word_fmt<T>(x); } + +int main() { + cout << word(3) << endl; + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-12 02:21:46
|
Revision: 1481 http://assorted.svn.sourceforge.net/assorted/?rev=1481&view=rev Author: yangzhang Date: 2009-10-12 02:21:32 +0000 (Mon, 12 Oct 2009) Log Message: ----------- tweaks to make things work again under windows; using new ir_black color scheme Modified Paths: -------------- configs/trunk/src/vim/plugin/_yang.vim configs/trunk/src/vim/plugin/mru.vim Added Paths: ----------- configs/trunk/src/vim/colors/ir_black.vim Added: configs/trunk/src/vim/colors/ir_black.vim =================================================================== --- configs/trunk/src/vim/colors/ir_black.vim (rev 0) +++ configs/trunk/src/vim/colors/ir_black.vim 2009-10-12 02:21:32 UTC (rev 1481) @@ -0,0 +1,212 @@ +" ir_black color scheme +" More at: http://blog.infinitered.com/entries/show/8 + + +" ******************************************************************************** +" Standard colors used in all ir_black themes: +" Note, x:x:x are RGB values +" +" normal: #f6f3e8 +" +" string: #A8FF60 168:255:96 +" string inner (punc, code, etc): #00A0A0 0:160:160 +" number: #FF73FD 255:115:253 +" comments: #7C7C7C 124:124:124 +" keywords: #96CBFE 150:203:254 +" operators: white +" class: #FFFFB6 255:255:182 +" method declaration name: #FFD2A7 255:210:167 +" regular expression: #E9C062 233:192:98 +" regexp alternate: #FF8000 255:128:0 +" regexp alternate 2: #B18A3D 177:138:61 +" variable: #C6C5FE 198:197:254 +" +" Misc colors: +" red color (used for whatever): #FF6C60 255:108:96 +" light red: #FFB6B0 255:182:176 +" +" brown: #E18964 good for special +" +" lightpurpleish: #FFCCFF +" +" Interface colors: +" background color: black +" cursor (where underscore is used): #FFA560 255:165:96 +" cursor (where block is used): white +" visual selection: #1D1E2C +" current line: #151515 21:21:21 +" search selection: #07281C 7:40:28 +" line number: #3D3D3D 61:61:61 + + +" ******************************************************************************** +" The following are the preferred 16 colors for your terminal +" Colors Bright Colors +" Black #4E4E4E #7C7C7C +" Red #FF6C60 #FFB6B0 +" Green #A8FF60 #CEFFAB +" Yellow #FFFFB6 #FFFFCB +" Blue #96CBFE #FFFFCB +" Magenta #FF73FD #FF9CFE +" Cyan #C6C5FE #DFDFFE +" White #EEEEEE #FFFFFF + + +" ******************************************************************************** +set background=dark +hi clear + +if exists("syntax_on") + syntax reset +endif + +let colors_name = "ir_black" + + +"hi Example guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE + +" General colors +hi Normal guifg=#f6f3e8 guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE +hi NonText guifg=#070707 guibg=black gui=NONE ctermfg=black ctermbg=NONE cterm=NONE + +hi Cursor guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=reverse +hi LineNr guifg=#3D3D3D guibg=black gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE + +hi VertSplit guifg=#202020 guibg=#202020 gui=NONE ctermfg=darkgray ctermbg=darkgray cterm=NONE +hi StatusLine guifg=#CCCCCC guibg=#202020 gui=italic ctermfg=white ctermbg=darkgray cterm=NONE +hi StatusLineNC guifg=black guibg=#202020 gui=NONE ctermfg=blue ctermbg=darkgray cterm=NONE + +hi Folded guifg=#a0a8b0 guibg=#384048 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE +hi Title guifg=#f6f3e8 guibg=NONE gui=bold ctermfg=NONE ctermbg=NONE cterm=NONE +hi Visual guifg=NONE guibg=#262D51 gui=NONE ctermfg=NONE ctermbg=darkgray cterm=NONE + +hi SpecialKey guifg=#808080 guibg=#343434 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE + +hi WildMenu guifg=green guibg=yellow gui=NONE ctermfg=black ctermbg=yellow cterm=NONE +hi PmenuSbar guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=NONE +"hi Ignore guifg=gray guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE + +hi Error guifg=NONE guibg=NONE gui=undercurl ctermfg=white ctermbg=red cterm=NONE guisp=#FF6C60 " undercurl color +hi ErrorMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE +hi WarningMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE + +" Message displayed in lower left, such as --INSERT-- +hi ModeMsg guifg=black guibg=#C6C5FE gui=BOLD ctermfg=black ctermbg=cyan cterm=BOLD + +if version >= 700 " Vim 7.x specific colors + hi CursorLine guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD + hi CursorColumn guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD + hi MatchParen guifg=#f6f3e8 guibg=#857b6f gui=BOLD ctermfg=white ctermbg=darkgray cterm=NONE + hi Pmenu guifg=#f6f3e8 guibg=#444444 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE + hi PmenuSel guifg=#000000 guibg=#cae682 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE + hi Search guifg=NONE guibg=NONE gui=underline ctermfg=NONE ctermbg=NONE cterm=underline +endif + +" Syntax highlighting +hi Comment guifg=#7C7C7C guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE +hi String guifg=#A8FF60 guibg=NONE gui=NONE ctermfg=green ctermbg=NONE cterm=NONE +hi Number guifg=#FF73FD guibg=NONE gui=NONE ctermfg=magenta ctermbg=NONE cterm=NONE + +hi Keyword guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE +hi PreProc guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE +hi Conditional guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE " if else end + +hi Todo guifg=#8f8f8f guibg=NONE gui=NONE ctermfg=red ctermbg=NONE cterm=NONE +hi Constant guifg=#99CC99 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE + +hi Identifier guifg=#C6C5FE guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE +hi Function guifg=#FFD2A7 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE +hi Type guifg=#FFFFB6 guibg=NONE gui=NONE ctermfg=yellow ctermbg=NONE cterm=NONE +hi Statement guifg=#6699CC guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE + +hi Special guifg=#E18964 guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE +hi Delimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE +hi Operator guifg=white guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE + +hi link Character Constant +hi link Boolean Constant +hi link Float Number +hi link Repeat Statement +hi link Label Statement +hi link Exception Statement +hi link Include PreProc +hi link Define PreProc +hi link Macro PreProc +hi link PreCondit PreProc +hi link StorageClass Type +hi link Structure Type +hi link Typedef Type +hi link Tag Special +hi link SpecialChar Special +hi link SpecialComment Special +hi link Debug Special + + +" Special for Ruby +hi rubyRegexp guifg=#B18A3D guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE +hi rubyRegexpDelimiter guifg=#FF8000 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE +hi rubyEscape guifg=white guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE +hi rubyInterpolationDelimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE +hi rubyControl guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE "and break, etc +"hi rubyGlobalVariable guifg=#FFCCFF guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE "yield +hi rubyStringDelimiter guifg=#336633 guibg=NONE gui=NONE ctermfg=lightgreen ctermbg=NONE cterm=NONE +"rubyInclude +"rubySharpBang +"rubyAccess +"rubyPredefinedVariable +"rubyBoolean +"rubyClassVariable +"rubyBeginEnd +"rubyRepeatModifier +"hi link rubyArrayDelimiter Special " [ , , ] +"rubyCurlyBlock { , , } + +hi link rubyClass Keyword +hi link rubyModule Keyword +hi link rubyKeyword Keyword +hi link rubyOperator Operator +hi link rubyIdentifier Identifier +hi link rubyInstanceVariable Identifier +hi link rubyGlobalVariable Identifier +hi link rubyClassVariable Identifier +hi link rubyConstant Type + + +" Special for Java +" hi link javaClassDecl Type +hi link javaScopeDecl Identifier +hi link javaCommentTitle javaDocSeeTag +hi link javaDocTags javaDocSeeTag +hi link javaDocParam javaDocSeeTag +hi link javaDocSeeTagParam javaDocSeeTag + +hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE +hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE +"hi javaClassDecl guifg=#CCFFCC guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE + + +" Special for XML +hi link xmlTag Keyword +hi link xmlTagName Conditional +hi link xmlEndTag Identifier + + +" Special for HTML +hi link htmlTag Keyword +hi link htmlTagName Conditional +hi link htmlEndTag Identifier + + +" Special for Javascript +hi link javaScriptNumber Number + + +" Special for Python +"hi link pythonEscape Keyword + + +" Special for CSharp +hi link csXmlTag Keyword + + +" Special for PHP Modified: configs/trunk/src/vim/plugin/_yang.vim =================================================================== --- configs/trunk/src/vim/plugin/_yang.vim 2009-10-10 03:37:41 UTC (rev 1480) +++ configs/trunk/src/vim/plugin/_yang.vim 2009-10-12 02:21:32 UTC (rev 1481) @@ -70,7 +70,9 @@ " XXX This doesn't work for setting options on the triggering buffer. " XXX This is highly insecure; should only allow the same things allowed in modelines. -autocmd BufNewFile,BufRead * if glob(ProjectDir() . "/.project.vim") !~ "^$" | execute "source " . ProjectDir() . "/.project.vim" | endif +if system("uname") =~ ".*Linux.*" " TODO fix this so cygwin is also accepted + autocmd BufNewFile,BufRead * if glob(ProjectDir() . "/.project.vim") !~ "^$" | execute "source " . ProjectDir() . "/.project.vim" | endif +endif @@ -108,7 +110,7 @@ set sp=>& " guifont " TODO fix the zoom resulting zoom issue (when specifying backup fonts) - set gfn=Bitstream_Vera_Sans_Mono:h14,Andale_Mono:h11 + set gfn=Consolas "set gfn=Lucida_Console:h8:cANSI " guifont "set gfn=Lucida_Console:h11 " guifont else @@ -138,7 +140,7 @@ hi User4 guibg=#000000 guifg=LightBlue gui=bold hi LineNr guibg=grey30 -colorscheme desert +colorscheme ir_black " desert syntax enable " set number " number lines Modified: configs/trunk/src/vim/plugin/mru.vim =================================================================== --- configs/trunk/src/vim/plugin/mru.vim 2009-10-10 03:37:41 UTC (rev 1480) +++ configs/trunk/src/vim/plugin/mru.vim 2009-10-12 02:21:32 UTC (rev 1481) @@ -1,7 +1,7 @@ " File: mru.vim " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) -" Version: 3.1 -" Last Modified: February 17, 2008 +" Version: 3.2 +" Last Modified: September 22, 2008 " " Overview " -------- @@ -47,10 +47,10 @@ " " Usage " ----- -" You can use the ":MRU" command to list all the most recently edited file -" names. The file names will be listed in a temporary Vim window. If the MRU -" window is already opened, then the MRU list displayed in the window will be -" refreshed. +" To list and edit files from the MRU list, you have to use the ":MRU" +" command. The ":MRU" command displays the MRU file list in a temporary Vim +" window. If the MRU window is already opened, then the MRU list displayed in +" the window is refreshed. " " If you are using GUI Vim, then the names of the recently edited files are " added to the "File->Recent Files" menu. You can select the name of a file @@ -99,11 +99,11 @@ " plugin. Set the following variables in your .vimrc file using the 'let' " command. " -" The list of recently edit file names is stored in the file specified by the +" The list of recently edited file names is stored in the file specified by the " MRU_File variable. The default setting for this variable is -" $HOME/.vim_mru_files for Unix systems and $VIM/_vim_mru_files for non-Unix -" systems. You can change this variable to point to a file by adding the -" following line to the .vimrc file: +" $HOME/.vim_mru_files for Unix-like systems and $USERPROFILE/_vim_mru_files +" for MS-Windows systems. You can change this variable to point to a file by +" adding the following line to the .vimrc file: " " let MRU_File = 'd:\myhome\_vim_mru_files' " @@ -126,6 +126,16 @@ " " The specified pattern should be a Vim regular expression pattern. " +" If you want to add only file names matching a set of patterns to the MRU +" list, then you can set the MRU_Include_Files variable. This variable should +" be set to a Vim regular expression pattern. For example, to add only .c and +" .h files to the MRU list, you can set this variable as below: +" +" let MRU_Include_Files = '\.c$\|\.h$' +" +" By default, MRU_Include_Files is set to an empty string and all the edited +" filenames are added to the MRU list. +" " The default height of the MRU window is 8. You can set the MRU_Window_Height " variable to change the window height. " @@ -177,6 +187,11 @@ let MRU_Exclude_Files = '' endif +" Files to include in the MRU list +if !exists('MRU_Include_Files') + let MRU_Include_Files = '' +endif + " Height of the MRU window " Default height is 8 if !exists('MRU_Window_Height') @@ -192,10 +207,16 @@ endif if !exists('MRU_File') - if has('unix') - let MRU_File = $HOME . "/.vim_mru_files" + if has('unix') || has('macunix') + let MRU_File = $HOME . '/.vim_mru_files' else - let MRU_File = $VIM . "/_vim_mru_files" + let MRU_File = $VIM . '/_vim_mru_files' + if has('win32') + " MS-Windows + if $USERPROFILE != '' + let MRU_File = $USERPROFILE . '\_vim_mru_files' + endif + endif endif endif @@ -204,19 +225,26 @@ let MRU_Add_Menu = 1 endif +" Control to temporarily lock the MRU list. Used to prevent files from +" getting added to the MRU list when the ':vimgrep' command is executed. +let s:mru_list_locked = 0 + " MRU_LoadList " Load the latest MRU file list from the MRU file function! s:MRU_LoadList() " Read the list from the MRU file. if filereadable(g:MRU_File) let s:MRU_files = readfile(g:MRU_File) - if s:MRU_files[0] =~# '^" Most recently edited files in Vim' - " Generated by the previous version of the MRU plugin. Ignore the - " list + if s:MRU_files[0] =~# '^\s*" Most recently edited files in Vim' + " Generated by the previous version of the MRU plugin. + " Discard the list. let s:MRU_files = [] elseif s:MRU_files[0] =~# '^#' " Remove the comment line call remove(s:MRU_files, 0) + else + " Unsupported format + let s:MRU_files = [] endif else let s:MRU_files = [] @@ -238,6 +266,11 @@ " MRU_AddFile " Add a file to the MRU file list function! s:MRU_AddFile(acmd_bufnr) + if s:mru_list_locked + " MRU list is currently locked + return + endif + " Get the full path to the filename let fname = fnamemodify(bufname(a:acmd_bufnr + 0), ':p') if fname == '' @@ -249,16 +282,24 @@ return endif + if g:MRU_Include_Files != '' + " If MRU_Include_Files is set, include only files matching the + " specified pattern + if fname !~# g:MRU_Include_Files + return + endif + endif + if g:MRU_Exclude_Files != '' " Do not add files matching the pattern specified in the " MRU_Exclude_Files to the MRU list - if fname =~? g:MRU_Exclude_Files + if fname =~# g:MRU_Exclude_Files return endif endif - " If the filename is already present in the MRU list, then move - " it to the beginning of the list + " If the filename is not already present in the MRU list and is not + " readable then ignore it let idx = index(s:MRU_files, fname) if idx == -1 if !filereadable(fname) @@ -276,7 +317,7 @@ " Add the new file list to the beginning of the updated old file list call insert(s:MRU_files, fname, 0) - " Return the trimmed list + " Trim the list if len(s:MRU_files) > g:MRU_Max_Entries call remove(s:MRU_files, g:MRU_Max_Entries, -1) endif @@ -299,12 +340,23 @@ endif endfunction +" Special characters in file names that should be escaped (for security +" reasons) +let s:esc_filename_chars = ' *?[{`$%#"|!<>();&' . "'\t\n" +function! s:MRU_escape_filename(fname) + return escape(a:fname, s:esc_filename_chars) +endfunction + " MRU_Edit_File " Edit the specified file -function! s:MRU_Edit_File(filename) - let fname = escape(a:filename, ' %#"') +function! s:MRU_Edit_File(filename, sanitized) + if !a:sanitized + let esc_fname = s:MRU_escape_filename(a:filename) + else + let esc_fname = a:filename + endif " If the file is already open in one of the windows, jump to it - let winnum = bufwinnr('^' . fname . '$') + let winnum = bufwinnr('^' . a:filename . '$') if winnum != -1 if winnum != winnr() exe winnum . 'wincmd w' @@ -313,9 +365,9 @@ if &modified || &buftype != '' || &previewwindow " Current buffer has unsaved changes or is a special buffer or is " the preview window. So open the file in a new window - exe 'split ' . fname + exe 'split ' . esc_fname else - exe 'edit ' . fname + exe 'edit ' . esc_fname endif endif endfunction @@ -332,11 +384,11 @@ return endif - let fname = escape(fname, ' %#"') + let esc_fname = s:MRU_escape_filename(fname) if a:win_opt == 'newwin' " Edit the file in a new window - exe 'leftabove new ' . fname + exe 'leftabove new ' . esc_fname if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0 " Go back to the MRU window and close it @@ -375,7 +427,7 @@ exe 'tabnext ' . i else " Open a new tab as the last tab page - exe '999tabnew ' . fname + exe '999tabnew ' . esc_fname endif endif @@ -427,9 +479,9 @@ if &modified || &buftype != '' || &previewwindow " Current buffer has unsaved changes or is a special buffer or " is the preview window. So open the file in a new window - exe 'split ' . fname + exe 'split ' . esc_fname else - exe 'edit ' . fname + exe 'edit ' . esc_fname endif endif endif @@ -546,11 +598,17 @@ silent! 0put =s:MRU_files else " Display only the entries matching the specified pattern - silent! 0put =filter(copy(s:MRU_files), 'v:val =~? a:1') + " First try using it as a literal pattern + let m = filter(copy(s:MRU_files), 'stridx(v:val, a:1) != -1') + if len(m) == 0 + " No match. Try using it as a regular expression + let m = filter(copy(s:MRU_files), 'v:val =~# a:1') + endif + silent! 0put =m endif " Move the cursor to the beginning of the file - exe 1 + normal! gg setlocal nomodifiable endfunction @@ -588,8 +646,21 @@ " filenames containing the string. If only one filename is found, " then edit it. let m = filter(copy(s:MRU_files), 'stridx(v:val, a:pat) != -1') - if len(m) == 1 - call s:MRU_Edit_File(m[0]) + if len(m) > 0 + if len(m) == 1 + call s:MRU_Edit_File(m[0], 0) + return + endif + + " More than one file matches. Try find an accurate match + let new_m = filter(m, 'v:val ==# a:pat') + if len(new_m) == 1 + call s:MRU_Edit_File(new_m[0], 0) + return + endif + + " Couldn't find an exact match, open the MRU window + call s:MRU_Open_Window(a:pat) return endif @@ -605,7 +676,7 @@ endif if len(m) == 1 - call s:MRU_Edit_File(m[0]) + call s:MRU_Edit_File(m[0], 0) return endif @@ -615,7 +686,9 @@ function! s:MRU_add_files_to_menu(prefix, file_list) for fname in a:file_list " Escape special characters in the filename - let esc_fname = escape(fnamemodify(fname, ':t'), ". \\|\t%#") + let esc_fname = escape(fnamemodify(fname, ':t'), ".\\" . + \ s:esc_filename_chars) + let esc_fname = substitute(esc_fname, '&', '&&', 'g') " Truncate the directory name if it is long let dir_name = fnamemodify(fname, ':h') @@ -627,11 +700,15 @@ \ '...' . \ strpart(dir_name, len - 20) endif - let esc_dir_name = escape(dir_name, ". \\|\t") + let esc_dir_name = escape(dir_name, ".\\" . s:esc_filename_chars) + let esc_dir_name = substitute(esc_dir_name, '&', '&&', 'g') - exe 'anoremenu <silent> &File.Recent\ Files.' . a:prefix . esc_fname . - \ '\ (' . esc_dir_name . ')' . - \ " :call <SID>MRU_Edit_File('" . fname . "')<CR>" + let menu_path = '&File.Recent\ Files.' . a:prefix . esc_fname . + \ '\ (' . esc_dir_name . ')' + let esc_mfname = s:MRU_escape_filename(fname) + exe 'anoremenu <silent> ' . menu_path . + \ " :call <SID>MRU_Edit_File('" . esc_mfname . "', 1)<CR>" + exe 'tmenu ' . menu_path . ' Edit file ' . esc_mfname endfor endfunction @@ -658,11 +735,14 @@ anoremenu <silent> &File.Recent\ Files.Refresh\ list \ :call <SID>MRU_LoadList()<CR> + exe 'tmenu File.Recent\ Files.Refresh\ list Reload the MRU file list from ' + \ . s:MRU_escape_filename(g:MRU_File) anoremenu File.Recent\ Files.-SEP1- : " Add the filenames in the MRU list to the menu let entry_cnt = len(s:MRU_files) if entry_cnt > 10 + " Split the MRU menu into sub-menus for start_idx in range(0, entry_cnt, 10) let last_idx = start_idx + 9 if last_idx >= entry_cnt @@ -692,6 +772,12 @@ autocmd BufNewFile * call s:MRU_AddFile(expand('<abuf>')) autocmd BufWritePost * call s:MRU_AddFile(expand('<abuf>')) +" The ':vimgrep' command adds all the files searched to the buffer list. +" This also modifies the MRU list, even though the user didn't edit the +" files. Use the following autocmds to prevent this. +autocmd QuickFixCmdPre *vimgrep* let s:mru_list_locked = 1 +autocmd QuickFixCmdPost *vimgrep* let s:mru_list_locked = 0 + " Command to open the MRU window command! -nargs=? -complete=customlist,s:MRU_Complete MRU \ call s:MRU_Cmd(<q-args>) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-10 03:37:48
|
Revision: 1480 http://assorted.svn.sourceforge.net/assorted/?rev=1480&view=rev Author: yangzhang Date: 2009-10-10 03:37:41 +0000 (Sat, 10 Oct 2009) Log Message: ----------- updated eventshare to work again Modified Paths: -------------- sandbox/trunk/src/win/eventshare/README sandbox/trunk/src/win/eventshare/eventshare/eventshare.c Modified: sandbox/trunk/src/win/eventshare/README =================================================================== --- sandbox/trunk/src/win/eventshare/README 2009-10-10 03:37:02 UTC (rev 1479) +++ sandbox/trunk/src/win/eventshare/README 2009-10-10 03:37:41 UTC (rev 1480) @@ -1,2 +1 @@ -This is from an osronline article in 9/2002-10/2002 issue. It no longer works -due to session changes. +This is from an osronline article in 9/2002-10/2002 issue. Modified: sandbox/trunk/src/win/eventshare/eventshare/eventshare.c =================================================================== --- sandbox/trunk/src/win/eventshare/eventshare/eventshare.c 2009-10-10 03:37:02 UTC (rev 1479) +++ sandbox/trunk/src/win/eventshare/eventshare/eventshare.c 2009-10-10 03:37:41 UTC (rev 1480) @@ -84,7 +84,7 @@ // \BaseNamedObjects\ by the object manager so we will need to add // that to the event name when we try and open this event from kernel mode // - SharedEvent = CreateEvent(NULL, TRUE, FALSE, "SharedEvent"); + SharedEvent = CreateEvent(NULL, TRUE, FALSE, "Global\\SharedEvent"); if (SharedEvent == NULL) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-10 03:37:22
|
Revision: 1479 http://assorted.svn.sourceforge.net/assorted/?rev=1479&view=rev Author: yangzhang Date: 2009-10-10 03:37:02 +0000 (Sat, 10 Oct 2009) Log Message: ----------- added hello world driver Added Paths: ----------- sandbox/trunk/src/win/hellodrv/ sandbox/trunk/src/win/hellodrv/README sandbox/trunk/src/win/hellodrv/hello.c sandbox/trunk/src/win/hellodrv/sources Added: sandbox/trunk/src/win/hellodrv/README =================================================================== --- sandbox/trunk/src/win/hellodrv/README (rev 0) +++ sandbox/trunk/src/win/hellodrv/README 2009-10-10 03:37:02 UTC (rev 1479) @@ -0,0 +1 @@ +simple hello world driver Added: sandbox/trunk/src/win/hellodrv/hello.c =================================================================== --- sandbox/trunk/src/win/hellodrv/hello.c (rev 0) +++ sandbox/trunk/src/win/hellodrv/hello.c 2009-10-10 03:37:02 UTC (rev 1479) @@ -0,0 +1,8 @@ +#include <ntddk.h> + +NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) +{ + DbgPrint("Hello, World\n"); + DbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Hello, world!\n"); + return STATUS_SUCCESS; +} Added: sandbox/trunk/src/win/hellodrv/sources =================================================================== --- sandbox/trunk/src/win/hellodrv/sources (rev 0) +++ sandbox/trunk/src/win/hellodrv/sources 2009-10-10 03:37:02 UTC (rev 1479) @@ -0,0 +1,6 @@ +TARGETNAME = hello +TARGETPATH = obj +TARGETTYPE = DRIVER +INCLUDES = %BUILD%\inc +LIBS = %BUILD%\lib +SOURCES = hello.c This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2009-10-09 21:56:00
|
Revision: 1478 http://assorted.svn.sourceforge.net/assorted/?rev=1478&view=rev Author: yangzhang Date: 2009-10-09 21:55:49 +0000 (Fri, 09 Oct 2009) Log Message: ----------- starting to add windows configs Added Paths: ----------- configs/trunk/src/win/ configs/trunk/src/win/vim.reg Added: configs/trunk/src/win/vim.reg =================================================================== (Binary files differ) Property changes on: configs/trunk/src/win/vim.reg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |