Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_ |
| 18 | #define SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_ |
| 19 | |
| 20 | #include <tinyxml2.h> |
| 21 | #include <sstream> |
| 22 | #include <string> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace automotive { |
| 27 | namespace sv { |
| 28 | namespace V1_0 { |
| 29 | namespace implementation { |
| 30 | |
| 31 | // Macro returning false if condition evaluates to false. |
| 32 | #define RETURN_IF_FALSE(cond) \ |
| 33 | do { \ |
| 34 | if (!(cond)) { \ |
| 35 | return false; \ |
| 36 | } \ |
| 37 | } while (0) |
| 38 | |
| 39 | // Returns true if element has text. |
| 40 | bool ElementHasText(const tinyxml2::XMLElement* element); |
| 41 | |
| 42 | // Gets a xml element from the parent element, returns false if not found. |
| 43 | bool GetElement(const tinyxml2::XMLElement* parent, const char* elementName, |
| 44 | tinyxml2::XMLElement const** element); |
| 45 | |
Tanmay Patil | fcb633d | 2020-06-15 13:39:31 -0700 | [diff] [blame^] | 46 | // Reads a boolean value from a element, returns false if not found. |
Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame] | 47 | bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, bool* value); |
| 48 | |
Tanmay Patil | fcb633d | 2020-06-15 13:39:31 -0700 | [diff] [blame^] | 49 | // Reads a string value from a element, returns false if not found. |
Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame] | 50 | bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, std::string* value); |
| 51 | |
Tanmay Patil | fcb633d | 2020-06-15 13:39:31 -0700 | [diff] [blame^] | 52 | // Reads a float value from a element, returns false if not found. |
Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame] | 53 | bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, float* value); |
| 54 | |
Tanmay Patil | fcb633d | 2020-06-15 13:39:31 -0700 | [diff] [blame^] | 55 | // Reads a int value from a element, returns false if not found. |
Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame] | 56 | bool ReadValue(const tinyxml2::XMLElement* parent, const char* elementName, int* value); |
| 57 | |
| 58 | } // namespace implementation |
| 59 | } // namespace V1_0 |
| 60 | } // namespace sv |
| 61 | } // namespace automotive |
| 62 | } // namespace hardware |
| 63 | } // namespace android |
| 64 | |
| 65 | #endif // SURROUND_VIEW_SERVICE_IMPL_CONFIGREADERUTIL_H_ |