| Directory: | ./ |
|---|---|
| File: | src/phoenix_mockControlBackend_impl.h |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 20 | 21 | 95.2% |
| Branches: | 10 | 11 | 90.9% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PHOENIX_MOCKCONTROLBACKEND_IMPL_H__ | ||
| 8 | #define __PHOENIX_MOCKCONTROLBACKEND_IMPL_H__ | ||
| 9 | |||
| 10 | #include "phoenix_mockControlBackend.h" | ||
| 11 | |||
| 12 | |||
| 13 | ///Find a data for the connector by name | ||
| 14 | /** @param mapData : map of the data to be used | ||
| 15 | * @param name : name of the data to be used | ||
| 16 | * @return pointer to the corresponding data or NULL the the data is not found | ||
| 17 | */ | ||
| 18 | template<typename T> | ||
| 19 | 624 | T* phoenix_findConnectorData(std::map<std::string, T> & mapData, const std::string & name){ | |
| 20 |
1/1✓ Branch 1 taken 312 times.
|
624 | typename std::map<std::string, T >::iterator it(mapData.find(name)); |
| 21 |
2/2✓ Branch 2 taken 267 times.
✓ Branch 3 taken 45 times.
|
624 | if(it != mapData.end()){ |
| 22 | 534 | return &(it->second); | |
| 23 | }else{ | ||
| 24 | 90 | return NULL; | |
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | ///Say if a data does exist in a given map | ||
| 29 | /** @param mapData : map of the data to be used | ||
| 30 | * @param name : name of the data to be searched | ||
| 31 | * @return true if the name has been found, false otherwise | ||
| 32 | */ | ||
| 33 | template<typename T> | ||
| 34 | 344 | bool phoenix_isDataExist(std::map<std::string, T> & mapData, const std::string & name){ | |
| 35 |
1/1✓ Branch 1 taken 172 times.
|
344 | typename std::map<std::string, T >::iterator it(mapData.find(name)); |
| 36 | 344 | return it != mapData.end(); | |
| 37 | } | ||
| 38 | |||
| 39 | ///Save the data of the connector | ||
| 40 | /** @param logger : logger to be used | ||
| 41 | * @param data : variable/method call to be saved | ||
| 42 | * @param keyName : name of the data used | ||
| 43 | */ | ||
| 44 | template<typename T> | ||
| 45 | 48 | void phoenix_saveConnectorData(PLog & logger, const T & data, const std::string & keyName){ | |
| 46 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
|
48 | if(data.getIsWriteMode()){ //If we want to write information (so not in read mode) |
| 47 |
1/2✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
24 | if(data_save(data.getFileNameMock(), data)){ |
| 48 | 24 | logger.getLogInfo() << "\tSave map of data '"<< keyName <<"' in file '"<<data.getFileNameMock()<<"'" << std::endl; | |
| 49 | }else{ | ||
| 50 | ✗ | logger.getLogError() << "\tCannot save map of data '"<< keyName <<"' in file '"<<data.getFileNameMock()<<"'" << std::endl; | |
| 51 | } | ||
| 52 | }else{ | ||
| 53 | 24 | logger.getLogInfo() << "\tNo modif on '"<< keyName <<"' (file '"<<data.getFileNameMock()<<"')" << std::endl; | |
| 54 | } | ||
| 55 | 48 | } | |
| 56 | |||
| 57 | ///Save the data of the connector | ||
| 58 | /** @param logger : logger to be used | ||
| 59 | * @param mapData : map of variable/method call to be saved | ||
| 60 | * @param callName : name of the method used | ||
| 61 | */ | ||
| 62 | template<typename T> | ||
| 63 | 316 | void phoenix_saveConnectorData(PLog & logger, const std::map<std::string, T> & mapData, const std::string & callName){ | |
| 64 | 316 | logger.getLogInfo() << "["<<callName<<"] Save " << mapData.size() << " map of data" << std::endl; | |
| 65 |
2/2✓ Branch 4 taken 24 times.
✓ Branch 5 taken 158 times.
|
364 | for(typename std::map<std::string, T >::const_iterator it(mapData.begin()); it != mapData.end(); ++it){ |
| 66 | 48 | const T & data = it->second; | |
| 67 |
1/1✓ Branch 2 taken 24 times.
|
48 | phoenix_saveConnectorData(logger, data, it->first); |
| 68 | } | ||
| 69 | 316 | } | |
| 70 | |||
| 71 | #endif | ||
| 72 | |||
| 73 |