GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUrlString.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GUrlString.hpp - String 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 GUrlString.hpp
23  * @brief String URL class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GURLSTRING_HPP
28 #define GURLSTRING_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GUrl.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GUrlString
37  *
38  * @brief String URL class
39  *
40  * This class implements the URL interface for a string.
41  ***************************************************************************/
42 class GUrlString : public GUrl {
43 
44 public:
45  // Constructors and destructors
46  GUrlString(void);
47  GUrlString(const std::string& string);
48  GUrlString(const GUrlString& url);
49  virtual ~GUrlString(void);
50 
51  // Operators
52  GUrlString& operator=(const GUrlString& url);
53 
54  // Implemented pure virtual base class methods
55  virtual void clear(void);
56  virtual GUrlString* clone(void) const;
57  virtual std::string classname(void) const;
58  virtual void open(const std::string& string, const std::string& mode = "");
59  virtual void close(void);
60  virtual int read(void* buffer, const int& nbyte);
61  virtual int write(const void* buffer, const int& nbyte);
62  virtual int get_char(void) const;
63  virtual void put_char(const int& character);
64  virtual void scanf(const char* format, ...);
65  virtual void printf(const char* format, ...);
66  virtual std::string print(const GChatter& chatter = NORMAL) const;
67 
68  // Other methods
69  const std::string& string(void) const { return m_buffer; }
70  void rewind(void) { m_index=0; }
71 
72 protected:
73  // Protected methods
74  void init_members(void);
75  void copy_members(const GUrlString& url);
76  void free_members(void);
77 
78  // Protected members
79  mutable int m_index; //!< String position indicator
80  std::string m_buffer; //!< Text string
81 };
82 
83 
84 /***********************************************************************//**
85  * @brief Return class name
86  *
87  * @return String containing the class name ("GUrlString").
88  ***************************************************************************/
89 inline
90 std::string GUrlString::classname(void) const
91 {
92  return ("GUrlString");
93 }
94 
95 #endif /* GURLSTRING_HPP */
virtual int read(void *buffer, const int &nbyte)
Read block of data from string buffer.
Definition: GUrlString.cpp:248
GUrlString & operator=(const GUrlString &url)
Assignment operator.
Definition: GUrlString.cpp:131
virtual void printf(const char *format,...)
Write formatted data into string.
Definition: GUrlString.cpp:451
virtual std::string classname(void) const
Return class name.
Definition: GUrlString.hpp:90
void free_members(void)
Delete class members.
Definition: GUrlString.cpp:557
String URL class.
Definition: GUrlString.hpp:42
std::string m_buffer
Text string.
Definition: GUrlString.hpp:80
virtual void scanf(const char *format,...)
Read formatted data from string.
Definition: GUrlString.cpp:409
void copy_members(const GUrlString &url)
Copy class members.
Definition: GUrlString.cpp:543
virtual void put_char(const int &character)
Write character into string.
Definition: GUrlString.cpp:380
Abstract URL base class interface definition.
Abstract URL base class.
Definition: GUrl.hpp:44
virtual int get_char(void) const
Return next character from string.
Definition: GUrlString.cpp:351
virtual std::string print(const GChatter &chatter=NORMAL) const
Print URL information.
Definition: GUrlString.cpp:492
virtual void clear(void)
Clear string URL.
Definition: GUrlString.cpp:164
virtual void close(void)
Close file.
Definition: GUrlString.cpp:214
GChatter
Definition: GTypemaps.hpp:33
GUrlString(void)
Void constructor.
Definition: GUrlString.cpp:57
const std::string & string(void) const
Definition: GUrlString.hpp:69
int m_index
String position indicator.
Definition: GUrlString.hpp:79
virtual void open(const std::string &string, const std::string &mode="")
Open string URL.
Definition: GUrlString.cpp:197
virtual GUrlString * clone(void) const
Clone string URL.
Definition: GUrlString.cpp:184
void rewind(void)
Definition: GUrlString.hpp:70
void init_members(void)
Initialise class members.
Definition: GUrlString.cpp:527
virtual ~GUrlString(void)
Destructor.
Definition: GUrlString.cpp:109
virtual int write(const void *buffer, const int &nbyte)
Write block of data buffer into string.
Definition: GUrlString.cpp:305