1 module des.util.helpers;
2 
3 import core.runtime;
4 import std.file;
5 import std.path;
6 import std.algorithm;
7 
8 
9 /// `buildNormalizedPath`
10 string bnPath( string[] path... ) 
11 { return buildNormalizedPath( path ); }
12 
13 /++
14 normalized path from executable dir,
15 no matter where the program was launched, result stable
16 
17 code:
18     return bnPath( dirName( thisExePath ) ~ path );
19  +/
20 string appPath( string[] path... ) 
21 { return bnPath( dirName( thisExePath ) ~ path ); }
22 
23 /// read text from app path file
24 string readAPF( string[] path... )
25 { return readText( appPath( path ) ); }
26 
27 /// convert array of values to bit fields
28 auto packBitMask(T)( T[] list... )
29 { return reduce!((a,b)=>a|=b)(0,list); }
30 
31 ///
32 unittest
33 {
34     assert( packBitMask!uint() == 0 );
35     auto a = 0b0001;
36     assert( packBitMask(a) == a );
37     auto b = 0b0010;
38     assert( packBitMask(b) == b );
39     auto c = 0b0011;
40     assert( packBitMask(a,b) == c );
41 }
42