16a6c8299Sjmmv // Copyright 2010 Google Inc. 26a6c8299Sjmmv // All rights reserved. 36a6c8299Sjmmv // 46a6c8299Sjmmv // Redistribution and use in source and binary forms, with or without 56a6c8299Sjmmv // modification, are permitted provided that the following conditions are 66a6c8299Sjmmv // met: 76a6c8299Sjmmv // 86a6c8299Sjmmv // * Redistributions of source code must retain the above copyright 96a6c8299Sjmmv // notice, this list of conditions and the following disclaimer. 106a6c8299Sjmmv // * Redistributions in binary form must reproduce the above copyright 116a6c8299Sjmmv // notice, this list of conditions and the following disclaimer in the 126a6c8299Sjmmv // documentation and/or other materials provided with the distribution. 136a6c8299Sjmmv // * Neither the name of Google Inc. nor the names of its contributors 146a6c8299Sjmmv // may be used to endorse or promote products derived from this software 156a6c8299Sjmmv // without specific prior written permission. 166a6c8299Sjmmv // 176a6c8299Sjmmv // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186a6c8299Sjmmv // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196a6c8299Sjmmv // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206a6c8299Sjmmv // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216a6c8299Sjmmv // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226a6c8299Sjmmv // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236a6c8299Sjmmv // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246a6c8299Sjmmv // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256a6c8299Sjmmv // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266a6c8299Sjmmv // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276a6c8299Sjmmv // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286a6c8299Sjmmv 296a6c8299Sjmmv /// \file utils/process/fdstream.hpp 306a6c8299Sjmmv /// Provides the utils::process::ifdstream class. 316a6c8299Sjmmv 326a6c8299Sjmmv #if !defined(UTILS_PROCESS_FDSTREAM_HPP) 336a6c8299Sjmmv #define UTILS_PROCESS_FDSTREAM_HPP 346a6c8299Sjmmv 356a6c8299Sjmmv #include <istream> 366a6c8299Sjmmv #include <memory> 376a6c8299Sjmmv 386a6c8299Sjmmv #include "utils/noncopyable.hpp" 396a6c8299Sjmmv 406a6c8299Sjmmv namespace utils { 416a6c8299Sjmmv namespace process { 426a6c8299Sjmmv 436a6c8299Sjmmv 446a6c8299Sjmmv /// An input stream backed by a file descriptor. 456a6c8299Sjmmv /// 466a6c8299Sjmmv /// This class grabs ownership of the file descriptor. I.e. when the class is 476a6c8299Sjmmv /// destroyed, the file descriptor is closed unconditionally. 486a6c8299Sjmmv class ifdstream : public std::istream, noncopyable 496a6c8299Sjmmv { 506a6c8299Sjmmv struct impl; 516a6c8299Sjmmv 526a6c8299Sjmmv /// Pointer to the shared internal implementation. 53*ab619639Slukem std::unique_ptr< impl > _pimpl; 546a6c8299Sjmmv 556a6c8299Sjmmv public: 566a6c8299Sjmmv explicit ifdstream(const int); 576a6c8299Sjmmv ~ifdstream(void); 586a6c8299Sjmmv }; 596a6c8299Sjmmv 606a6c8299Sjmmv 616a6c8299Sjmmv } // namespace process 626a6c8299Sjmmv } // namespace utils 636a6c8299Sjmmv 646a6c8299Sjmmv #endif // !defined(UTILS_PROCESS_FDSTREAM_HPP) 65