00001 // Copyright 2010-2012 Google00002 // Licensed under the Apache License, Version 2.0 (the "License");00003 // you may not use this file except in compliance with the License.00004 // You may obtain a copy of the License at00005 //00006 // http://www.apache.org/licenses/LICENSE-2.000007 //00008 // Unless required by applicable law or agreed to in writing, software00009 // distributed under the License is distributed on an "AS IS" BASIS,00010 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.00011 // See the License for the specific language governing permissions and00012 // limitations under the License.00013
00014 #ifndef OR_TOOLS_BASE_FILELINEREADER_H_00015 #define OR_TOOLS_BASE_FILELINEREADER_H_00016
00017 #include <cstdlib>00018 #include <cstdio>00019 #include <string>00020
00021 #include "base/callback.h"00022 #include "base/integral_types.h"00023 #include "base/file.h"00024 #include "base/scoped_ptr.h"00025
00026 namespace operations_research {
00027 // The FileLineReader class will read a text file specified by00028 // 'filename' line by line. Each line will be cleaned with respect to00029 // termination ('\n' and '\r'). The line callback will be called in00030 // sequence on each line.00031class FileLineReader {
00032 public:
00033 // Creates a file line reader object that will read the file 'filename'00034 // line by line.00035 explicitFileLineReader(constchar* const filename);
00036
00037 ~FileLineReader();
00038
00039 // Sets the line callback and takes ownership.00040 voidset_line_callback(Callback1<char*>* const callback);
00041 // Reloads the file line by line.00042 voidReload();
00043 // Indicates if the file was loaded successfully.00044 boolloaded_successfully() const;
00045
00046 private:
00047 constchar* filename_;
00048 scoped_ptr<Callback1<char*> > line_callback_;
00049 bool loaded_successfully_;
00050 };
00051 } // namespace operations_research00052 #endif // OR_TOOLS_BASE_FILELINEREADER_H_