2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
26 #define TECPLOTENGINEMODULE
28 *****************************************************************
29 *****************************************************************
31 ****** Copyright (C) 1988-2008 Tecplot, Inc. *******
33 *****************************************************************
34 *****************************************************************
39 #include "Q_UNICODE.h"
49 #if defined MSWIN && !defined TECPLOTKERNEL
51 * Stub function for non-TECPLOTKERNEL
53 string
LookUpTranslation(string
& str
)
60 * Convenience function for creating Utf8 string translations.
63 * String to translate.
66 * A new Utf8 translated string.
68 static inline string
* createUtf8StringTranslation(string
& str
)
71 string
*result
= new string(LookUpTranslation(str
));
73 string
*result
= new string(str
);
75 ENSURE(VALID_REF(result
));
81 * Convenience function for creating wide string translations.
84 * String to translate.
87 * A new wide translated string.
89 static inline wstring
* createWideStringTranslation(string
& str
)
91 wstring
*result
= new wstring
;
92 *result
= StringToWString(LookUpTranslation(str
));
94 ENSURE(VALID_REF(result
));
101 * Convenience function for creating wide string with the given mode.
104 * Indicates if this string is to be translated or not.
106 * String to translate.
109 * A new wide translated string.
111 static inline wstring
* createWideString(TranslatedString::Mode mode
,
114 REQUIRE(mode
== TranslatedString::DoTranslate
|| mode
== TranslatedString::DontTranslate
);
117 if (mode
== TranslatedString::DoTranslate
)
118 result
= createWideStringTranslation(str
);
120 result
= new wstring(StringToWString(str
));
128 void TranslatedString::init(TranslatedString::Mode mode
,
130 const char* translatorNotes
)
132 REQUIRE(mode
== DoTranslate
|| mode
== DontTranslate
);
133 REQUIRE(VALID_REF_OR_NULL(str
));
134 REQUIRE(VALID_REF_OR_NULL(translatorNotes
));
137 m_isNull
= (str
== NULL
);
140 m_utf8String
= NULL
; // ...on demand resource
142 m_wideString
= NULL
; // ...on demand resource
148 TranslatedString::TranslatedString()
150 init(DontTranslate
, (const char*)NULL
, (const char*)NULL
);
151 ENSURE(this->isValid());
156 TranslatedString
TranslatedString::null()
158 return dontTranslate(NULL
);
163 TranslatedString::TranslatedString(TranslatedString::Mode mode
,
165 const char* translatorNotes
)
168 REQUIRE(mode
== DoTranslate
|| mode
== DontTranslate
);
169 REQUIRE(VALID_REF_OR_NULL(str
));
170 REQUIRE(VALID_REF_OR_NULL(translatorNotes
));
172 init(mode
, str
, translatorNotes
);
173 ENSURE(this->isValid());
178 TranslatedString::~TranslatedString()
186 #if !defined NO_ASSERTS
189 bool TranslatedString::isValid() const
191 CHECK(IMPLICATION(m_isNull
, m_string
.length() == 0));
193 /* TODO(DTO/RMS/CAM): 11/2/2007
194 * Code currently exists in Tecplot where we call translate() on a
195 * variable. This seems wrong and at times (PleaseWait() in
196 * particular) the variable passed is a NULL pointer which causes
197 * this assertion to fail. There is not enough time before v11.2
198 * release to remove all translate() calls to non-literal strings so
199 * we'll have to do this as a post release cleanup. For now just
200 * deactivate this assertion.
202 CHECK(IMPLICATION(m_isNull
, m_mode
== DontTranslate
));
211 bool TranslatedString::isNull() const
213 INVARIANT(this->isValid());
219 bool TranslatedString::isNullOrZeroLength() const
221 INVARIANT(this->isValid());
222 return m_isNull
|| m_string
.length() == 0;
227 const char* TranslatedString::c_str()
229 INVARIANT(this->isValid());
231 const char* result
= NULL
;
234 if (m_mode
== DoTranslate
)
236 if (m_utf8String
== NULL
)
237 m_utf8String
= createUtf8StringTranslation(m_string
);
238 result
= m_utf8String
->c_str();
240 else // ...if we aren't translating don't bother creating another Utf8 copy just use m_string
241 result
= m_string
.c_str();
244 ENSURE(result
== NULL
|| VALID_REF(result
));
251 const wchar_t *TranslatedString::c_wstr()
253 INVARIANT(this->isValid());
255 const wchar_t *result
= NULL
;
258 if (m_wideString
== NULL
)
259 m_wideString
= createWideString(m_mode
, m_string
);
260 result
= m_wideString
->c_str();
263 ENSURE(result
== NULL
|| VALID_REF(result
));
270 TranslatedString::operator string()
272 INVARIANT(this->isValid());
276 if (m_mode
== DoTranslate
)
278 if (m_utf8String
== NULL
)
279 m_utf8String
= createUtf8StringTranslation(m_string
);
280 result
= m_utf8String
;
282 else // ...if we aren't translating don't bother creating another Utf8 copy just use m_string
291 TranslatedString::operator wstring()
293 INVARIANT(this->isValid());
296 if (m_wideString
== NULL
)
297 m_wideString
= createWideString(m_mode
, m_string
);
299 return *m_wideString
;
305 TranslatedString
& TranslatedString::operator =(const TranslatedString
& other
)
307 REQUIRE(other
.isValid());
309 if (this != &other
) // ...only perform if not self assignment
311 m_mode
= other
.m_mode
;
312 m_isNull
= other
.m_isNull
;
313 m_string
= other
.m_string
;
314 m_utf8String
= (other
.m_utf8String
!= NULL
? new string(*other
.m_utf8String
) : NULL
);
316 m_wideString
= (other
.m_wideString
!= NULL
? new wstring(*other
.m_wideString
) : NULL
);
320 ENSURE(this->isValid());
326 TranslatedString::TranslatedString(const TranslatedString
& other
)
328 REQUIRE(other
.isValid());
330 m_mode
= other
.m_mode
;
331 m_isNull
= other
.m_isNull
;
332 m_string
= other
.m_string
;
333 m_utf8String
= (other
.m_utf8String
!= NULL
? new string(*other
.m_utf8String
) : NULL
);
335 m_wideString
= (other
.m_wideString
!= NULL
? new wstring(*other
.m_wideString
) : NULL
);
338 ENSURE(this->isValid());
343 TranslatedString
TranslatedString::translate(const char* str
,
344 const char* translatorNotes
)
346 REQUIRE(VALID_REF_OR_NULL(str
));
347 REQUIRE(VALID_REF_OR_NULL(translatorNotes
));
349 return TranslatedString(DoTranslate
, str
, translatorNotes
);
354 TranslatedString
TranslatedString::dontTranslate(const char* str
)
356 REQUIRE(VALID_REF_OR_NULL(str
));
358 return TranslatedString(DontTranslate
, str
, NULL
);