| Directory: | ./ |
|---|---|
| File: | src/phoenix_composeType.cpp |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 64 | 64 | 100.0% |
| Branches: | 72 | 81 | 88.9% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "phoenix_composeType.h" | ||
| 8 | |||
| 9 | ///Check if two compose type are equal | ||
| 10 | /** @param testName : name of the test | ||
| 11 | * @param value : PComposeType to be checked | ||
| 12 | * @param reference : reference of PComposeType | ||
| 13 | * @return true if they a re equal, false otherwise | ||
| 14 | */ | ||
| 15 | 130 | bool checkValue(const std::string & testName, const PComposeType & value, const PComposeType & reference){ | |
| 16 | 130 | bool b(true); | |
| 17 | 130 | b &= value.getType() == reference.getType(); | |
| 18 | 130 | const std::vector<PComposeType> & vecValueType = value.getVecType(); | |
| 19 | 130 | const std::vector<PComposeType> & vecReferenceType = reference.getVecType(); | |
| 20 | 130 | b &= checkValue(testName, vecValueType, vecReferenceType); | |
| 21 |
8/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 129 times.
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 21 taken 1 times.
|
130 | if(!b){std::cerr << testName << " error value = '" << ts_pcomposeTypeToStr(value) << "' diffrent from reference '" << ts_pcomposeTypeToStr(reference) << "'" << std::endl;} |
| 22 | 130 | return b; | |
| 23 | } | ||
| 24 | |||
| 25 | ///Check if two compose type are equal | ||
| 26 | /** @param testName : name of the test | ||
| 27 | * @param vecValueType : vector of PComposeType to be checked | ||
| 28 | * @param vecReferenceType : vector of reference of PComposeType | ||
| 29 | * @return true if they a re equal, false otherwise | ||
| 30 | */ | ||
| 31 | 150 | bool checkValue(const std::string & testName, const std::vector<PComposeType> & vecValueType, const std::vector<PComposeType> & vecReferenceType){ | |
| 32 | 150 | bool b(true); | |
| 33 | 150 | b &= vecValueType.size() == vecReferenceType.size(); | |
| 34 |
1/2✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
|
150 | if(b){ |
| 35 | 150 | std::vector<PComposeType>::const_iterator itValue(vecValueType.begin()); | |
| 36 | 150 | std::vector<PComposeType>::const_iterator itReference(vecReferenceType.begin()); | |
| 37 |
6/8✓ Branch 2 taken 25 times.
✓ Branch 3 taken 150 times.
✓ Branch 6 taken 25 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 25 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 25 times.
✓ Branch 11 taken 150 times.
|
175 | while(itValue != vecValueType.end() && itReference != vecReferenceType.end() && b){ |
| 38 |
2/2✓ Branch 3 taken 25 times.
✓ Branch 6 taken 25 times.
|
25 | b &= checkValue(testName + " subType", *itValue, *itReference); |
| 39 | 25 | ++itValue; | |
| 40 | 25 | ++itReference; | |
| 41 | } | ||
| 42 | } | ||
| 43 | 150 | return b; | |
| 44 | } | ||
| 45 | |||
| 46 | ///Convert a PType to string | ||
| 47 | /** @param type : PType to be converted | ||
| 48 | * @return corresponding string | ||
| 49 | */ | ||
| 50 | 136 | std::string ts_ptypeToStr(PType type){ | |
| 51 |
12/12✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 109 times.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
|
136 | switch(type){ |
| 52 | 1 | case TYPE_STREAM_CHAR: return ts_getTypeToStr<char>(); | |
| 53 | 1 | case TYPE_STREAM_SHORT: return ts_getTypeToStr<short>(); | |
| 54 | 8 | case TYPE_STREAM_INT: return ts_getTypeToStr<int>(); | |
| 55 | 1 | case TYPE_STREAM_LONG: return ts_getTypeToStr<long>(); | |
| 56 | |||
| 57 | 1 | case TYPE_STREAM_UNSIGNED_CHAR: return ts_getTypeToStr<unsigned char>(); | |
| 58 | 1 | case TYPE_STREAM_UNSIGNED_SHORT: return ts_getTypeToStr<unsigned short>(); | |
| 59 | 1 | case TYPE_STREAM_UNSIGNED_INT: return ts_getTypeToStr<unsigned int>(); | |
| 60 | 109 | case TYPE_STREAM_UNSIGNED_LONG: return ts_getTypeToStr<unsigned long>(); | |
| 61 | |||
| 62 | 5 | case TYPE_STREAM_BOOL: return ts_getTypeToStr<bool>(); | |
| 63 | 6 | case TYPE_STREAM_FLOAT: return ts_getTypeToStr<float>(); | |
| 64 | 1 | case TYPE_STREAM_DOUBLE: return ts_getTypeToStr<double>(); | |
| 65 | 1 | default: | |
| 66 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "UnknownType"; |
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | ///Convert a vector of PComposeType into a string | ||
| 71 | /** @param vecComposeType : vector of PComposeType to be converted into a string | ||
| 72 | * @return corresponding string | ||
| 73 | */ | ||
| 74 | 72 | std::string ts_pveccomposeTypeToStr(const std::vector<PComposeType> & vecComposeType){ | |
| 75 |
2/2✓ Branch 2 taken 72 times.
✓ Branch 6 taken 72 times.
|
144 | std::string body(""), comma(""); |
| 76 |
2/2✓ Branch 4 taken 44 times.
✓ Branch 5 taken 72 times.
|
116 | for(std::vector<PComposeType>::const_iterator it(vecComposeType.begin()); it != vecComposeType.end(); ++it){ |
| 77 |
3/3✓ Branch 2 taken 44 times.
✓ Branch 5 taken 44 times.
✓ Branch 8 taken 44 times.
|
44 | body += comma + ts_pcomposeTypeToStr(*it); |
| 78 |
1/1✓ Branch 1 taken 44 times.
|
44 | comma = ", "; |
| 79 | } | ||
| 80 | 144 | return body; | |
| 81 | 72 | } | |
| 82 | |||
| 83 | ///Convert a PComposeType into a string | ||
| 84 | /** @param composeType : PComposeType to be converted into a string | ||
| 85 | * @return corresponding string | ||
| 86 | */ | ||
| 87 | 128 | std::string ts_pcomposeTypeToStr(const PComposeType & composeType){ | |
| 88 | 128 | size_t type = composeType.getType(); | |
| 89 |
4/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
|
129 | if(type == TYPE_STREAM_VECTOR){return "std::vector<" + ts_pveccomposeTypeToStr(composeType.getVecType()) + " >";} |
| 90 |
4/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 126 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
|
128 | else if(type == TYPE_STREAM_LIST){return "std::list<" + ts_pveccomposeTypeToStr(composeType.getVecType()) + " >";} |
| 91 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 124 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
|
128 | else if(type == TYPE_STREAM_MAP){return "std::map<" + ts_pveccomposeTypeToStr(composeType.getVecType()) + " >";} |
| 92 | else{ | ||
| 93 | 124 | return ts_ptypeToStr(type); | |
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | ///Convert a PComposeVar into a string | ||
| 98 | /** @param composeVar : PComposeVar to be converted | ||
| 99 | * @return corresponding string | ||
| 100 | */ | ||
| 101 | 78 | std::string ts_pcomposeVarToStr(const PComposeVar & composeVar){ | |
| 102 |
1/1✓ Branch 2 taken 78 times.
|
78 | std::string body(""); |
| 103 |
3/3✓ Branch 1 taken 78 times.
✓ Branch 4 taken 78 times.
✓ Branch 7 taken 78 times.
|
78 | body += ts_pcomposeTypeToStr(composeVar.getType()); |
| 104 |
3/3✓ Branch 1 taken 78 times.
✓ Branch 4 taken 78 times.
✓ Branch 7 taken 78 times.
|
78 | body += " " + composeVar.getName(); |
| 105 | 78 | return body; | |
| 106 | } | ||
| 107 | |||
| 108 | ///Convert a PFunctionPrototype into a string | ||
| 109 | /** @param prototype : PFunctionPrototype to be converted | ||
| 110 | * @return corresponding string | ||
| 111 | */ | ||
| 112 | 34 | std::string ts_protoTypeToStr(const PFunctionPrototype & prototype){ | |
| 113 |
1/1✓ Branch 2 taken 34 times.
|
34 | std::string body(""); |
| 114 |
1/1✓ Branch 1 taken 34 times.
|
34 | bool needTuple(prototype.getVecReturnType().size() > 1lu); |
| 115 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
34 | if(needTuple){body += "(";} |
| 116 |
3/3✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
✓ Branch 7 taken 34 times.
|
34 | body += ts_pveccomposeTypeToStr(prototype.getVecReturnType()); |
| 117 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
34 | if(needTuple){body += ")";} |
| 118 |
4/4✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
✓ Branch 7 taken 34 times.
✓ Branch 10 taken 34 times.
|
34 | body += " " + prototype.getName() + "("; |
| 119 |
3/3✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
✓ Branch 7 taken 34 times.
|
34 | body += ts_pveccomposeTypeToStr(prototype.getVecParam()); |
| 120 |
1/1✓ Branch 1 taken 34 times.
|
34 | body += ")"; |
| 121 | 34 | return body; | |
| 122 | } | ||
| 123 | |||
| 124 | ///Convert a PFunctionCall into a string | ||
| 125 | /** @param functionCall : PFunctionCall to be converted | ||
| 126 | * @return corresponding string | ||
| 127 | */ | ||
| 128 | 30 | std::string ts_pfunctioncallToStr(const PFunctionCall & functionCall){ | |
| 129 | 30 | return ts_protoTypeToStr(functionCall.getPrototype()); | |
| 130 | } | ||
| 131 | |||
| 132 |