| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "FieldType.h" | ||
| 8 | |||
| 9 | |||
| 10 | ///Get the FieldType of a uint64 | ||
| 11 | /** @return corresponding FieldType | ||
| 12 | */ | ||
| 13 | template<> | ||
| 14 | 18 | FieldType::FieldType phoenix_fieldType<long unsigned int>(){ | |
| 15 | 18 | return FieldType::UINT64; | |
| 16 | } | ||
| 17 | |||
| 18 | ///Get the FieldType of a uint32 | ||
| 19 | /** @return corresponding FieldType | ||
| 20 | */ | ||
| 21 | template<> | ||
| 22 | 25 | FieldType::FieldType phoenix_fieldType<unsigned int>(){ | |
| 23 | 25 | return FieldType::UINT32; | |
| 24 | } | ||
| 25 | |||
| 26 | ///Get the FieldType of a uint16 | ||
| 27 | /** @return corresponding FieldType | ||
| 28 | */ | ||
| 29 | template<> | ||
| 30 | 7 | FieldType::FieldType phoenix_fieldType<unsigned short>(){ | |
| 31 | 7 | return FieldType::UINT16; | |
| 32 | } | ||
| 33 | |||
| 34 | ///Get the FieldType of a uint8 | ||
| 35 | /** @return corresponding FieldType | ||
| 36 | */ | ||
| 37 | template<> | ||
| 38 | 1 | FieldType::FieldType phoenix_fieldType<unsigned char>(){ | |
| 39 | 1 | return FieldType::UINT8; | |
| 40 | } | ||
| 41 | |||
| 42 | ///Get the FieldType of a int64 | ||
| 43 | /** @return corresponding FieldType | ||
| 44 | */ | ||
| 45 | template<> | ||
| 46 | 1 | FieldType::FieldType phoenix_fieldType<long>(){ | |
| 47 | 1 | return FieldType::INT64; | |
| 48 | } | ||
| 49 | |||
| 50 | ///Get the FieldType of a int32 | ||
| 51 | /** @return corresponding FieldType | ||
| 52 | */ | ||
| 53 | template<> | ||
| 54 | 1 | FieldType::FieldType phoenix_fieldType<int>(){ | |
| 55 | 1 | return FieldType::INT32; | |
| 56 | } | ||
| 57 | |||
| 58 | ///Get the FieldType of a int16 | ||
| 59 | /** @return corresponding FieldType | ||
| 60 | */ | ||
| 61 | template<> | ||
| 62 | 1 | FieldType::FieldType phoenix_fieldType<short>(){ | |
| 63 | 1 | return FieldType::INT16; | |
| 64 | } | ||
| 65 | |||
| 66 | ///Get the FieldType of a int8 | ||
| 67 | /** @return corresponding FieldType | ||
| 68 | */ | ||
| 69 | template<> | ||
| 70 | 1 | FieldType::FieldType phoenix_fieldType<char>(){ | |
| 71 | 1 | return FieldType::INT8; | |
| 72 | } | ||
| 73 | |||
| 74 | ///Convert a string into a FieldType | ||
| 75 | /** @param name : string to be converted into a FieldType | ||
| 76 | * @return corresponding FieldType | ||
| 77 | */ | ||
| 78 | 24 | FieldType::FieldType phoenix_fieldTypeFromStr(const std::string & name){ | |
| 79 |
1/2✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 24 times.
|
24 | if(name == "bytearray"){return FieldType::BYTEARRAY;} |
| 80 |
2/2✓ Branch 0 (6→7) taken 2 times.
✓ Branch 1 (6→8) taken 22 times.
|
24 | else if(name == "enum"){return FieldType::ENUM_TYPE;} |
| 81 |
2/2✓ Branch 0 (9→10) taken 1 times.
✓ Branch 1 (9→11) taken 21 times.
|
22 | else if(name == "int8"){return FieldType::INT8;} |
| 82 |
2/2✓ Branch 0 (12→13) taken 1 times.
✓ Branch 1 (12→14) taken 20 times.
|
21 | else if(name == "int16"){return FieldType::INT16;} |
| 83 |
2/2✓ Branch 0 (15→16) taken 1 times.
✓ Branch 1 (15→17) taken 19 times.
|
20 | else if(name == "int32"){return FieldType::INT32;} |
| 84 |
2/2✓ Branch 0 (18→19) taken 1 times.
✓ Branch 1 (18→20) taken 18 times.
|
19 | else if(name == "int64"){return FieldType::INT64;} |
| 85 |
2/2✓ Branch 0 (21→22) taken 4 times.
✓ Branch 1 (21→23) taken 14 times.
|
18 | else if(name == "submessage"){return FieldType::SUBMESSAGE;} |
| 86 |
2/2✓ Branch 0 (24→25) taken 1 times.
✓ Branch 1 (24→26) taken 13 times.
|
14 | else if(name == "uint8"){return FieldType::UINT8;} |
| 87 |
2/2✓ Branch 0 (27→28) taken 2 times.
✓ Branch 1 (27→29) taken 11 times.
|
13 | else if(name == "uint16"){return FieldType::UINT16;} |
| 88 |
2/2✓ Branch 0 (30→31) taken 5 times.
✓ Branch 1 (30→32) taken 6 times.
|
11 | else if(name == "uint32"){return FieldType::UINT32;} |
| 89 |
2/2✓ Branch 0 (33→34) taken 4 times.
✓ Branch 1 (33→35) taken 2 times.
|
6 | else if(name == "uint64"){return FieldType::UINT64;} |
| 90 | else{ | ||
| 91 | 2 | return FieldType::NONE; | |
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | ///Convert a FieldType into a string | ||
| 96 | /** @param type : FieldType to be converted | ||
| 97 | * @return corresponding string | ||
| 98 | */ | ||
| 99 | 11 | std::string phoenix_fieldTypeToStr(FieldType::FieldType type){ | |
| 100 |
1/3✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→8) taken 11 times.
✗ Branch 2 (5→6) not taken.
|
11 | if(type == FieldType::BYTEARRAY){return "bytearray";} |
| 101 |
3/3✓ Branch 0 (8→9) taken 1 times.
✓ Branch 1 (8→14) taken 10 times.
✓ Branch 2 (11→12) taken 1 times.
|
13 | else if(type == FieldType::ENUM_TYPE){return "enum";} |
| 102 |
3/3✓ Branch 0 (14→15) taken 1 times.
✓ Branch 1 (14→20) taken 9 times.
✓ Branch 2 (17→18) taken 1 times.
|
12 | else if(type == FieldType::INT8){return "int8";} |
| 103 |
3/3✓ Branch 0 (20→21) taken 1 times.
✓ Branch 1 (20→26) taken 8 times.
✓ Branch 2 (23→24) taken 1 times.
|
11 | else if(type == FieldType::INT16){return "int16";} |
| 104 |
3/3✓ Branch 0 (26→27) taken 1 times.
✓ Branch 1 (26→32) taken 7 times.
✓ Branch 2 (29→30) taken 1 times.
|
10 | else if(type == FieldType::INT32){return "int32";} |
| 105 |
3/3✓ Branch 0 (32→33) taken 1 times.
✓ Branch 1 (32→38) taken 6 times.
✓ Branch 2 (35→36) taken 1 times.
|
9 | else if(type == FieldType::INT64){return "int64";} |
| 106 |
3/3✓ Branch 0 (38→39) taken 1 times.
✓ Branch 1 (38→44) taken 5 times.
✓ Branch 2 (41→42) taken 1 times.
|
8 | else if(type == FieldType::SUBMESSAGE){return "submessage";} |
| 107 |
3/3✓ Branch 0 (44→45) taken 1 times.
✓ Branch 1 (44→50) taken 4 times.
✓ Branch 2 (47→48) taken 1 times.
|
7 | else if(type == FieldType::UINT8){return "uint8";} |
| 108 |
3/3✓ Branch 0 (50→51) taken 1 times.
✓ Branch 1 (50→56) taken 3 times.
✓ Branch 2 (53→54) taken 1 times.
|
6 | else if(type == FieldType::UINT16){return "uint16";} |
| 109 |
3/3✓ Branch 0 (56→57) taken 1 times.
✓ Branch 1 (56→62) taken 2 times.
✓ Branch 2 (59→60) taken 1 times.
|
5 | else if(type == FieldType::UINT32){return "uint32";} |
| 110 |
3/3✓ Branch 0 (62→63) taken 1 times.
✓ Branch 1 (62→68) taken 1 times.
✓ Branch 2 (65→66) taken 1 times.
|
4 | else if(type == FieldType::UINT64){return "uint64";} |
| 111 | else { | ||
| 112 |
1/1✓ Branch 0 (70→71) taken 1 times.
|
2 | return "none"; |
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | ///Convert a FIeld Type from protocol buffer to FieldType | ||
| 117 | /** @param fieldType : field type form protocol buffer | ||
| 118 | * @return corresponding FieldType | ||
| 119 | */ | ||
| 120 | 5 | FieldType::FieldType phoenix_pbTypeToFieldType(size_t fieldType){ | |
| 121 |
5/5✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→4) taken 1 times.
✓ Branch 2 (2→5) taken 1 times.
✓ Branch 3 (2→6) taken 1 times.
✓ Branch 4 (2→7) taken 1 times.
|
5 | switch(fieldType){ |
| 122 | 1 | case 0lu: //This is an enum, and its value is in a varint | |
| 123 | 1 | return FieldType::ENUM_TYPE; | |
| 124 | 1 | case 1lu: //This is a uint64_t | |
| 125 | 1 | return FieldType::UINT64; | |
| 126 | 1 | case 5lu: //This is a uint32_t | |
| 127 | 1 | return FieldType::UINT32; | |
| 128 | 1 | case 2lu: //This is a binary array, which starts by a varint | |
| 129 | //It can be a sub message | ||
| 130 | 1 | return FieldType::BYTEARRAY; | |
| 131 | 1 | default: | |
| 132 | 1 | return FieldType::NONE; | |
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | |||
| 137 |