#include "findshare.h" //test: #if(0) #include <stdio.h> typedef fs::handle<char*,FILE*> hrwfile; typedef hrwfile::key_type rwfh_key_t; typedef hrwfile::hid_type rwfh_hid_t; template <> //specialization unsigned long fs::handle<char*,FILE*>::key_hash(rwfh_key_t const & k) { unsigned long hashval = 55; char * c = k + ::strlen(k) - 1; while(true) { hashval += unsigned char(*c); if( c-- == k ) break; hashval *= 5; } return hashval; } template <> //specialization bool fs::handle<char*,FILE*>::equal_keys(rwfh_key_t const & k1,rwfh_key_t const & k2) { return ! ::strcmp(k1,k2); } template <> //specialization rwfh_hid_t fs::handle<char*,FILE*>::make_handle(rwfh_key_t const & k) { FILE* f = fopen(k,"a+"); return f; } template <> //specialization void fs::handle<char*,FILE*>::free_handle(rwfh_hid_t const & id) { fclose(id); } //template //explicit class template instantiation //fs::handle<char*,FILE*>; int main() { typedef hrwfile rw_file; rw_file a("file1.txt"); //opens or creates file1 rw_file b("file2.txt"); //opens or creates file2 rw_file c("file1.txt"); //re-uses file1's handle; ++refcount { rw_file d("file2.txt"); //re-uses file2's handle; ++refcount ::fprintf(d, "something2\n"); rw_file e(c); //re-uses file1's handle; ++refcount } //--refcounts ::fprintf(a, "something\n"); return 0; } // --refcount's, files closed, handles erased, then hash-table removed #endif
code/root/hpp/test/findshare.cpp.txt · Last modified: 2006/10/09 22:20 by chuck_starchaser


