Line data Source code
1 : //
2 : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #ifndef VSET_VSET_BUFFER_PERSISTENT_FILE_AD_FILE_SIZE_HPP
8 : #define VSET_VSET_BUFFER_PERSISTENT_FILE_AD_FILE_SIZE_HPP
9 :
10 : #include <vset/buffer/tags.hpp>
11 : #include <vset/buffer/persistent/tags.hpp>
12 : #include <sys/stat.h>
13 : #include <string.h>
14 : #include <stdexcept>
15 : #include <errno.h>
16 :
17 : namespace vset { namespace buffer { namespace persistent{ namespace file{
18 :
19 12 : struct ad_file_size
20 : {
21 : template<typename T>
22 53 : size_t operator()( T& t )
23 : {
24 : struct stat sb;
25 53 : memset(&sb, 0, sizeof(sb));
26 :
27 53 : if ( -1 == stat( t.get_aspect().template get<_file_name_>().c_str(), &sb) )
28 0 : throw std::domain_error(strerror(errno));
29 :
30 53 : return static_cast<size_t>(sb.st_size);
31 : }
32 : };
33 :
34 : }}}}
35 :
36 : #endif
|