Directory: | ./ |
---|---|
File: | tmp_project/PhoenixOptionParser/src/get_argument_list.cpp |
Date: | 2025-03-14 11:54:19 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 38 | 38 | 100.0% |
Branches: | 30 | 32 | 93.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "get_argument_list.h" | ||
8 | |||
9 | |||
10 | ///Convert the list of given arguments to the program into a list of string | ||
11 | /** @param argc : number of arguments passed to the program | ||
12 | * @param argv : table of arguments passed to the program | ||
13 | * @return corresponding list of string | ||
14 | */ | ||
15 | 3 | std::list<PString> phoenix_getArgumentList(int argc, char** argv){ | |
16 | 3 | std::list<PString> argList; | |
17 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
|
8 | for(int i(0); i < argc; ++i){ |
18 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | argList.push_back(PString(argv[i])); |
19 | } | ||
20 | 3 | return argList; | |
21 | } | ||
22 | |||
23 | ///Check if one of the two passed arguments are in the list of arguments | ||
24 | /** @param listArg : list of arguments given to the program | ||
25 | * @param argCheckList : list of argument to be searched | ||
26 | * @return true if one element of argCheckList has been found in listArg, false otherwise | ||
27 | */ | ||
28 | 6 | bool phoenix_isOptionExist(const std::list<PString> & listArg, const std::list<PString> & argCheckList){ | |
29 | 6 | bool isSearch(true); | |
30 | 6 | std::list<PString>::const_iterator itArg(listArg.begin()); | |
31 |
5/6✓ Branch 2 taken 10 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 6 times.
|
16 | while(itArg != listArg.end() && isSearch){ |
32 | 10 | std::list<PString>::const_iterator itCheck(argCheckList.begin()); | |
33 |
6/6✓ Branch 2 taken 15 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 10 times.
|
24 | while(itCheck != argCheckList.end() && isSearch){ |
34 | 14 | isSearch = *itArg != *itCheck; | |
35 | 14 | ++itCheck; | |
36 | } | ||
37 | 10 | ++itArg; | |
38 | } | ||
39 | 6 | return !isSearch; | |
40 | } | ||
41 | |||
42 | ///Check if one of the two passed arguments are in the list of arguments | ||
43 | /** @param listArg : list of arguments given to the program | ||
44 | * @param arg1 : argument to be searched | ||
45 | * @return true if arg1 or arg2 is in listArg, false otherwise | ||
46 | */ | ||
47 | 3 | bool phoenix_isOptionExist(const std::list<PString> & listArg, const PString & arg1){ | |
48 | 3 | std::list<PString> argCheckList; | |
49 |
1/1✓ Branch 1 taken 3 times.
|
3 | argCheckList.push_back(arg1); |
50 |
1/1✓ Branch 1 taken 3 times.
|
6 | return phoenix_isOptionExist(listArg, argCheckList); |
51 | 3 | } | |
52 | |||
53 | ///Check if one of the two passed arguments are in the list of arguments | ||
54 | /** @param listArg : list of arguments given to the program | ||
55 | * @param arg1 : argument to be searched | ||
56 | * @param arg2 : argument to be searched | ||
57 | * @return true if arg1 or arg2 is in listArg, false otherwise | ||
58 | */ | ||
59 | 3 | bool phoenix_isOptionExist(const std::list<PString> & listArg, const PString & arg1, const PString & arg2){ | |
60 | 3 | std::list<PString> argCheckList; | |
61 |
1/1✓ Branch 1 taken 3 times.
|
3 | argCheckList.push_back(arg1); |
62 |
1/1✓ Branch 1 taken 3 times.
|
3 | argCheckList.push_back(arg2); |
63 |
1/1✓ Branch 1 taken 3 times.
|
6 | return phoenix_isOptionExist(listArg, argCheckList); |
64 | 3 | } | |
65 | |||
66 | ///Convert the given list of arguement into a string | ||
67 | /** @param listArg : list of argument to be converted into a string | ||
68 | * @return corresponding string | ||
69 | */ | ||
70 | 6 | PString phoenix_listArgToString(const std::list<PString> & listArg){ | |
71 | 6 | PString body(""); | |
72 |
2/2✓ Branch 3 taken 7 times.
✓ Branch 4 taken 6 times.
|
13 | for(std::list<PString>::const_iterator itArg(listArg.begin()); itArg != listArg.end(); ++itArg){ |
73 |
5/5✓ Branch 2 taken 7 times.
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
✓ Branch 11 taken 7 times.
✓ Branch 14 taken 7 times.
|
7 | body += itArg->escapeStr(" '\"", "\\") + " "; |
74 | } | ||
75 | 6 | return body; | |
76 | } | ||
77 | |||
78 | ///Get the program call | ||
79 | /** @param listArg : list of argument passed to the program | ||
80 | * @return program call, or empty string if list of argument is empty | ||
81 | */ | ||
82 | 6 | PString phoenix_getProgramCall(const std::list<PString> & listArg){ | |
83 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
|
6 | if(listArg.size() != 0lu){return listArg.front();} |
84 | 1 | else{return "";} | |
85 | } | ||
86 | |||
87 | ///Remove the program call from the list of argument | ||
88 | /** @param[out] listArg : list or argument to be modified | ||
89 | */ | ||
90 | 3 | void phoenix_rmProgramCall(std::list<PString> & listArg){ | |
91 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if(listArg.size() != 0lu){ |
92 | 3 | listArg.pop_front(); | |
93 | } | ||
94 | 3 | } | |
95 | |||
96 | |||
97 | |||
98 |