GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUrlFile.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GUrlFile.hpp - File URL class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2014 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GUrlFile.hpp
23  * @brief File URL class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GURLFILE_HPP
28 #define GURLFILE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <cstdio> // FILE
33 #include "GUrl.hpp"
34 
35 
36 /***********************************************************************//**
37  * @class GUrlFile
38  *
39  * @brief File URL class
40  ***************************************************************************/
41 class GUrlFile : public GUrl {
42 
43 public:
44  // Constructors and destructors
45  GUrlFile(void);
46  GUrlFile(const std::string& url, const std::string& mode);
47  GUrlFile(const GUrlFile& url);
48  virtual ~GUrlFile(void);
49 
50  // Operators
51  GUrlFile& operator=(const GUrlFile& url);
52 
53  // Implemented pure virtual base class methods
54  virtual void clear(void);
55  virtual GUrlFile* clone(void) const;
56  virtual std::string classname(void) const;
57  virtual void open(const std::string& url, const std::string& mode);
58  virtual void close(void);
59  virtual int read(void* buffer, const int& nbyte);
60  virtual int write(const void* buffer, const int& nbyte);
61  virtual int get_char(void) const;
62  virtual void put_char(const int& character);
63  virtual void scanf(const char* format, ...);
64  virtual void printf(const char* format, ...);
65  virtual std::string print(const GChatter& chatter = NORMAL) const;
66 
67 protected:
68  // Protected methods
69  void init_members(void);
70  void copy_members(const GUrlFile& url);
71  void free_members(void);
72 
73  // Protected members
74  std::string m_url; //!< File URL
75  std::string m_mode; //!< File mode
76  FILE* m_fptr; //!< File pointer
77 };
78 
79 
80 /***********************************************************************//**
81  * @brief Return class name
82  *
83  * @return String containing the class name ("GUrlFile").
84  ***************************************************************************/
85 inline
86 std::string GUrlFile::classname(void) const
87 {
88  return ("GUrlFile");
89 }
90 
91 #endif /* GURLFILE_HPP */
std::string m_mode
File mode.
Definition: GUrlFile.hpp:75
virtual void clear(void)
Clear instance.
Definition: GUrlFile.cpp:165
GUrlFile(void)
Void constructor.
Definition: GUrlFile.cpp:56
void free_members(void)
Delete class members.
Definition: GUrlFile.cpp:562
GUrlFile & operator=(const GUrlFile &url)
Assignment operator.
Definition: GUrlFile.cpp:132
virtual int write(const void *buffer, const int &nbyte)
Write block of data buffer into file.
Definition: GUrlFile.cpp:312
virtual std::string print(const GChatter &chatter=NORMAL) const
Print URL information.
Definition: GUrlFile.cpp:473
virtual ~GUrlFile(void)
Destructor.
Definition: GUrlFile.cpp:110
Abstract URL base class interface definition.
Abstract URL base class.
Definition: GUrl.hpp:44
File URL class.
Definition: GUrlFile.hpp:41
std::string m_url
File URL.
Definition: GUrlFile.hpp:74
virtual void close(void)
Close file.
Definition: GUrlFile.cpp:232
virtual void open(const std::string &url, const std::string &mode)
Open file.
Definition: GUrlFile.cpp:206
GChatter
Definition: GTypemaps.hpp:33
virtual void printf(const char *format,...)
Write formatted data into file.
Definition: GUrlFile.cpp:443
void copy_members(const GUrlFile &url)
Copy class members.
Definition: GUrlFile.cpp:547
virtual std::string classname(void) const
Return class name.
Definition: GUrlFile.hpp:86
virtual void scanf(const char *format,...)
Read formatted data from file.
Definition: GUrlFile.cpp:403
virtual int get_char(void) const
Return next character from file.
Definition: GUrlFile.cpp:348
virtual GUrlFile * clone(void) const
Clone instance.
Definition: GUrlFile.cpp:185
virtual int read(void *buffer, const int &nbyte)
Read block of data from file in buffer.
Definition: GUrlFile.cpp:271
virtual void put_char(const int &character)
Write character into file.
Definition: GUrlFile.cpp:375
void init_members(void)
Initialise class members.
Definition: GUrlFile.cpp:526
FILE * m_fptr
File pointer.
Definition: GUrlFile.hpp:76