IBR-DTNSuite  0.8
ibrcommon/ibrcommon/appstreambuf.h
Go to the documentation of this file.
00001 /*
00002  * appstreambuf.h
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef IBRCOMMON_APPSTREAMBUF_H_
00018 #define IBRCOMMON_APPSTREAMBUF_H_
00019 
00020 #include <streambuf>
00021 #include <vector>
00022 #include <string>
00023 #include <stdio.h>
00024 
00025 namespace ibrcommon
00026 {
00038         class appstreambuf : public std::basic_streambuf<char, std::char_traits<char> >
00039         {
00040         public:
00041                 enum { BUF_SIZE = 512 };
00042 
00043                 enum Mode
00044                 {
00045                         MODE_READ = 0,
00046                         MODE_WRITE = 1
00047                 };
00048 
00054                 appstreambuf(std::string command, appstreambuf::Mode mode);
00055                 virtual ~appstreambuf();
00056 
00057         protected:
00058                 virtual std::char_traits<char>::int_type underflow();
00059                 virtual int sync();
00060                 virtual std::char_traits<char>::int_type overflow( std::char_traits<char>::int_type m = traits_type::eof() );
00061 
00062         private:
00063                 std::vector< char_type > m_buf;
00064                 FILE *_handle;
00065         };
00066 }
00067 
00068 #endif /* APPSTREAMBUF_H_ */