tbx  0.7.6
messagefile.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 /*
26  * messagefile.h
27  *
28  * Created on: 14 Oct 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_MESSAGEFILE_H_
33 #define TBX_MESSAGEFILE_H_
34 
35 #include <string>
36 
37 namespace tbx {
38 
43 {
44 private:
45  int _messageFD[4];
46  char *_buffer;
47  enum Status {CLOSED, OPENED, ATTACHED} _status;
48 public:
49  MessageFile();
50  MessageFile(const std::string &file_name);
51  MessageFile(int *messageFD);
52  ~MessageFile();
53 
54  bool open(const std::string &file_name);
55  void close();
56  void attach(int *messageFD);
57 
61  bool is_open() const {return (_status != CLOSED);}
62 
63  bool contains(const std::string &token) const;
64 
65  std::string message(const std::string &token) const;
66  std::string message(const std::string &token, const std::string &arg0, int max_size = 255) const;
67  std::string message(const std::string &token, const std::string &arg0, const std::string &arg1, int max_size = 255) const;
68  std::string message(const std::string &token, const std::string &arg0, const std::string &arg1, const std::string &arg2, int max_size = 255) const;
69  std::string message(const std::string &token, const std::string &arg0, const std::string &arg1, const std::string &arg2, const std::string &arg3, int max_size = 255) const;
70 
71  std::string gsmessage(const std::string &token, int max_size = 255) const;
72  std::string gsmessage(const std::string &token, const std::string &arg0, int max_size = 255) const;
73  std::string gsmessage(const std::string &token, const std::string &arg0, const std::string &arg1, int max_size = 255) const;
74  std::string gsmessage(const std::string &token, const std::string &arg0, const std::string &arg1, const std::string &arg2, int max_size = 255) const;
75  std::string gsmessage(const std::string &token, const std::string &arg0, const std::string &arg1, const std::string &arg2, const std::string &arg3, int max_size = 255) const;
76 };
77 
78 }
79 
80 #endif /* TBX_MESSAGEFILE_H_ */
tbx::MessageFile::MessageFile
MessageFile()
Unused message file constructor.
Definition: messagefile.cc:43
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::MessageFile::contains
bool contains(const std::string &token) const
Checks to see if the message file contains the given token.
Definition: messagefile.cc:136
tbx::MessageFile::attach
void attach(int *messageFD)
Attach this messages file class to the given message file descriptor.
Definition: messagefile.cc:123
tbx::MessageFile::open
bool open(const std::string &file_name)
Open a messages file.
Definition: messagefile.cc:89
tbx::MessageFile::~MessageFile
~MessageFile()
Destructor - close file if opened with constructor or open function.
Definition: messagefile.cc:78
tbx::MessageFile::is_open
bool is_open() const
Returns true if message file is open.
Definition: messagefile.h:61
tbx::MessageFile::message
std::string message(const std::string &token) const
Get the string with the given token name without argument substitution.
Definition: messagefile.cc:159
tbx::MessageFile::close
void close()
Closes the message file if its has been successfully opened.
Definition: messagefile.cc:107
tbx::MessageFile
Class to lookup token translations from a messages file.
Definition: messagefile.h:43
tbx::MessageFile::gsmessage
std::string gsmessage(const std::string &token, int max_size=255) const
Get the string with the given token name and converts it from the GSTrans format.
Definition: messagefile.cc:309