42cf5bc1 |
1 | // Created on: 2001-04-26 |
2 | // Created by: OCC Team |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Message_MsgFile_HeaderFile |
17 | #define _Message_MsgFile_HeaderFile |
18 | |
19 | #include <Standard.hxx> |
20 | #include <Standard_DefineAlloc.hxx> |
21 | #include <Standard_Handle.hxx> |
22 | |
23 | #include <Standard_Boolean.hxx> |
24 | #include <Standard_CString.hxx> |
25 | class TCollection_AsciiString; |
26 | class TCollection_ExtendedString; |
27 | |
42cf5bc1 |
28 | //! A tool providing facility to load definitions of message strings from |
29 | //! resource file(s). |
30 | //! |
31 | //! The message file is an ASCII file which defines a set of messages. |
32 | //! Each message is identified by its keyword (string). |
33 | //! |
34 | //! All lines in the file starting with the exclamation sign |
35 | //! (perhaps preceeding by spaces and/or tabs) are ignored as comments. |
36 | //! |
37 | //! Each line in the file starting with the dot character "." |
38 | //! (perhaps preceeding by spaces and/or tabs) defines the keyword. |
39 | //! The keyword is a string starting from the next symbol after dot |
40 | //! and ending at the symbol preceeding ending newline character "\n". |
41 | //! |
42 | //! All the lines in the file after the keyword and before next |
43 | //! keyword (and which are not comments) define the message for that |
44 | //! keyword. If the message consists of several lines, the message |
45 | //! string will contain newline symbols "\n" between parts (but not |
46 | //! at the end). |
47 | //! |
48 | //! The experimental support of Unicode message files is provided. |
49 | //! These are distinguished by two bytes FF.FE or FE.FF at the beginning. |
50 | //! |
51 | //! The loaded messages are stored in static data map; all methods of that |
52 | //! class are also static. |
53 | class Message_MsgFile |
54 | { |
55 | public: |
56 | |
57 | DEFINE_STANDARD_ALLOC |
58 | |
59 | |
60 | //! Load message file <theFileName> from directory <theDirName> |
61 | //! or its sub-directory |
62 | Standard_EXPORT static Standard_Boolean Load (const Standard_CString theDirName, const Standard_CString theFileName); |
63 | |
64 | //! Load the messages from the given file, additive to any previously |
65 | //! loaded messages. Messages with same keywords, if already present, |
66 | //! are replaced with the new ones. |
67 | Standard_EXPORT static Standard_Boolean LoadFile (const Standard_CString theFName); |
68 | |
ee5befae |
69 | //! Loads the messages from the file with name (without extension) given by environment variable. |
70 | //! Extension of the file name is given separately. If its not defined, it is taken: |
42cf5bc1 |
71 | //! - by default from environment CSF_LANGUAGE, |
72 | //! - if not defined either, as "us". |
ee5befae |
73 | //! @name theEnvName environment variable name |
74 | //! @name theFileName file name without language suffix |
75 | //! @name theLangExt language file name extension |
76 | //! @return TRUE on success |
77 | Standard_EXPORT static Standard_Boolean LoadFromEnv (const Standard_CString theEnvName, |
78 | const Standard_CString theFileName, |
79 | const Standard_CString theLangExt = ""); |
80 | |
81 | //! Loads the messages from the given text buffer. |
82 | //! @param theContent string containing the messages |
83 | //! @param theLength length of the buffer; |
84 | //! when -1 specified - theContent will be considered as NULL-terminated string |
85 | Standard_EXPORT static Standard_Boolean LoadFromString (const Standard_CString theContent, |
86 | const Standard_Integer theLength = -1); |
87 | |
42cf5bc1 |
88 | //! Adds new message to the map. Parameter <key> gives |
89 | //! the key of the message, <text> defines the message itself. |
90 | //! If there already was defined the message identified by the |
91 | //! same keyword, it is replaced with the new one. |
92 | Standard_EXPORT static Standard_Boolean AddMsg (const TCollection_AsciiString& key, const TCollection_ExtendedString& text); |
93 | |
94 | //! Returns True if message with specified keyword is registered |
95 | Standard_EXPORT static Standard_Boolean HasMsg (const TCollection_AsciiString& key); |
96 | |
97 | Standard_EXPORT static const TCollection_ExtendedString& Msg (const Standard_CString key); |
98 | |
99 | //! Gives the text for the message identified by the keyword <key> |
100 | //! If there are no messages with such keyword defined, |
101 | //! the error message is returned. |
102 | //! In that case reference to static string is returned, it can |
103 | //! be chenged with next call(s) to Msg(). |
104 | //! Note: The error message is constructed like 'Unknown message: <key>', and can |
105 | //! itself be customized by defining message with key Message_Msg_BadKeyword. |
106 | Standard_EXPORT static const TCollection_ExtendedString& Msg (const TCollection_AsciiString& key); |
107 | |
108 | |
109 | |
110 | |
111 | protected: |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | private: |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | }; |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | #endif // _Message_MsgFile_HeaderFile |