1 /* Copyright (C) 2012-2021 by László Nagy 2 This file is part of Bear. 3 4 Bear is a tool to generate compilation database for clang tooling. 5 6 Bear is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Bear is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include <map> 23 #include <string> 24 25 namespace sys::env { 26 27 // Memory resource guard class. 28 // 29 // The OS expect `const char**`, but the caller usually manipulated 30 // the values in different form. This class let the caller use a more 31 // convenient form (`std::map<std::string, std::string>`) to use, 32 // but makes the final `const char**` not leak. 33 class Guard { 34 public: 35 explicit Guard(const std::map<std::string, std::string>& environ); 36 37 [[nodiscard]] const char** data() const; 38 39 public: 40 Guard() = delete; 41 ~Guard() noexcept; 42 43 Guard(Guard&&) noexcept = delete; 44 Guard(Guard const&) = delete; 45 46 Guard& operator=(Guard&&) noexcept = delete; 47 Guard& operator=(Guard const&) = delete; 48 49 private: 50 const char** data_; 51 }; 52 } 53