MCPcopy Create free account
hub / github.com/DragonJoker/Castor3D / parseArgs

Function parseArgs

tools/HeightMapToNormalMap/HeightMapToNormalMap.cpp:33–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 };
32
33 bool parseArgs( int argc
34 , char * argv[]
35 , Options & options )
36 {
37 StringArray args{ argv + 1, argv + argc };
38
39 if ( args.empty() )
40 {
41 std::cerr << "Missing parameters." << std::endl << std::endl;
42 printUsage();
43 return false;
44 }
45
46 auto it = std::find( args.begin(), args.end(), "-h" );
47
48 if ( it == args.end() )
49 {
50 it = std::find( args.begin(), args.end(), "--help" );
51 }
52
53 if ( it != args.end() )
54 {
55 args.erase( it );
56 printUsage();
57 return false;
58 }
59
60 it = std::find( args.begin(), args.end(), "-s" );
61
62 if ( it == args.end() )
63 {
64 it = std::find( args.begin(), args.end(), "--strength" );
65 }
66
67 if ( it != args.end()
68 && std::distance( args.begin(), it ) == ptrdiff_t( args.size() - 1 ) )
69 {
70 std::cerr << "-s option is missing strength parameter" << std::endl << std::endl;
71 printUsage();
72 return false;
73 }
74
75 if ( it != args.end() )
76 {
77 it = args.erase( it );
78 options.normalStrength = castor::string::toFloat( castor::makeString( *it ) );
79 args.erase( it );
80 }
81
82 if ( args.empty() )
83 {
84 std::cerr << "Missing file parameter" << std::endl << std::endl;
85 printUsage();
86 return false;
87 }
88
89 it = std::next( args.begin(), ptrdiff_t( args.size() - 1u ) );
90

Callers 1

mainFunction · 0.70

Calls 9

toFloatFunction · 0.85
emplace_backMethod · 0.80
printUsageFunction · 0.70
makeStringFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected