This file is indexed.

/usr/share/doc/libeigenbase-resgen-java/overview_cpp.html is in libeigenbase-resgen-java-doc 1.3.0.13768-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<html>
<!--
// $Id: //open/util/resgen/doc/overview_cpp.html#2 $
// package org.eigenbase.resgen is an i18n resource generator
// Copyright (C) 2005-2005 The Eigenbase Project
// Copyright (C) 2005-2005 Disruptive Tech
// Copyright (C) 2005-2005 Red Square, Inc.
// Portions Copyright (C) 2004-2005 Kana Software, Inc. and others.
// All Rights Reserved.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
//
// jhyde, 18 February 2004
  -->
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>ResGen C++ specification</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
<base target="_top">
</head>

<body>
<h1>ResGen: C++ Mode</h1>
<p>Stephan Zuercher, February 18<sup><font face="Verdana">th</font></sup>, 2004.</p>

<h2>C++ Resources</h2>

<p>In practice, ResGen supports three modes of operation:</p>
<ul>
<li><b>Java</b> - resources are generated as described in the main
<a href="overview.html">ResGen documentation</a>.</li>
<li><b>C++</b> - resource are generated as described in this document.</li>
<li><b>both</b> - Java and C++ resources are generated.</li>
</ul>
<p>The main overview document concerns itself exclusively with
ResGen's Java mode.  This document explains how ResGen operates in C++
mode.  See the section on the <a href="overview.html#resgen">resgen ANT task</a>
for more information on selecting ResGen's mode.</p>

<p>ResGen's C++ mode uses the same properties files as Java mode.  In
addition it generates a header (.h) and source (.cpp) file for each
resource bundle.</p>

<h2>C++ framework</h2>

<p>C++ mode requires that project using the generated resouces provide
a framework for managing the messages given.  The framework has the
following requirements:</p>
<ol>
<li>The presence of a class named <b>Locale</b> in the same namespace
as the generated resource files.
    <ul>
    <li>The header file for Locale must be Locale.h.</li>
    <li>The Locale class must be suitable for use as a a key value
    in a <copd>std::map</code> (e.g. it should define
    <code>operator&lt;</code>).</li>
    <li>It must also define a method <code>const Locale
    &getDefault()</code> that returns a suitable default locale.</li>
    </ul>
</li>
<li>The presence of a class named <b>ResourceBundle</b> in the same namespace
as the generated resource files that may be used as a base class for
generated resources.
    <ul>
    <li>The header file for ResourceBundle must be
    ResourceBundle.h</li>
    <li>ResourceBundle's must have constructor
    <code>ResourceBundle(const std::string &basename, const Locale
    &locale, const std::string &location)</code> where basename is
    the name of the resource bundle
    (e.g. <code>BirthdayResource</code> in the previous example),
    locale is the Locale this ResourceBundle will handle and
    location is the path to the directory where the ResourceBundle
    can find its properties file.</li>

    <li>ResourceBundle is responsible for loading the properties
    files, handling the Java format strings (e.g. <code>"There are
    {0, number} letters in {1}."</code>), and returning messages
    in a format usable by ResourceDefinition.  One possible
    implementation is to convert the Java format strings into <a
    href="http://www.boost.org">Boost</a> format strings.</li>
        </ul>
</li>
<li>The presence of a class name <b>ResourceDefinition</b> in the same
namespace as the generated resource files.
    <ul>
    <li>ResourceDefinitions must have a constructor
    <code>ResourceDefinition(ResourceBundle *bundle, const
    std::string &key)</code>.</li>
    <li>ResourceDefinition must implement these methods:
        <code></code> as well as templated
    methods that take varying numbers of arguments:
    <blockquote><pre>
    std::string format() const;
    template&lt;typename t0&gt; string format(const t0 &p0) const;
        template&lt;typename t0, typename t1&gt;
      string format(const t0 &p0, const t1 &p1) const;
    .
    .
    .</pre></blockquote>

    Each <code>format</code> method should lookup up the message
    associated with the key given in the constructor from the
    ResourceBundle given in the constructor and should format the
    message given the arguments, returning the resulting
    std::string.  If a format template method doesn't exist of the
    number of parameters in your message, a compile time error
    will occur.
    </ul>
</li>
<li>The presence of this templated method:
<blockquote><pre>template&lt;class _GRB, class _BC, class _BC_ITER&gt;
_GRB *makeInstance(
    _BC &bundleCache,
    const Locale &locale);
</pre></blockquote>
<p>The template's arguments are a class generated by ResGen in C++ mode
(e.g. <code>BirthdayResources</code> in the examples below), a
<code>std::map&lt;Locale, _GRB *&gt;</code>, and an iterator on that
map.</p>

<p>The method's purpose is to look up the generated resource bundle
instance in the bundle cache for the given locale.  If found, it
should be returned to the caller.  If not found, it should be
instantiated for the locale, added to the map and returned.  Normally,
the method would also attempt to create an instance of the parent
locale's bundle by calling itself recursively.  For example, when
instantiating a resource bundle for the "en_US" locale, one would also
instantiate a bundle for the "en" locale and set it as a parent to the
"en_US" locale.  The "en" locale might have a nameless locale as its
parent so that all message requests are guaranteed to be filled.  This
logic is controlled by the <code>ResourceBundle</code> class and need
only be implemented if you wish locales to inherit messages from their
parent locales.</p>

</li>
</ol>

<p>An example of how to create a framework appropriate for ResGen C++
resources can be found in the <a href="http://fennel.sourceforge.net/">Fennel</a> project.
</p>

<h2>C++ exceptions</h2>

<p>If exception resources are used (as opposed to just message
resources), you will need to provide an exception class.  A default
exception class for all exception resources can be given (see
<code>&lt;resourceBundle&gt;</code>, below), or you can override the
default on a per-resource basis.  The exception class must always have
a basic constructor like this one:</p>

<blockquote><pre>Excn(const std::string &msg);</pre></blockquote>

<p>If chained exceptions are enabled for an exception resource, the
exception class must also have a chained constructor:</p>

<blockquote><pre>Excn(const std::string &msg, const Excn * const chained);</pre></blockquote>

<h2>C++ Example</h2>

<p>The following examples assume you're familiar with the Java example
given above.</p>

<h3>Create a resource file</h3>

<p>First, create a resource file like the following, <code>BirthdayResource_en_US.xml</code>:</p>
<blockquote>
  <pre>&lt;?xml version=&quot;1.0&quot; ?&gt;
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;Resource.xsl&quot; ?&gt;
&lt;resourceBundle
    locale=&quot;en_US&quot;
    cppExceptionClassName=&quot;Excn&quot;
    cppExceptionClassLocation=&quot;Excn.h&quot;&gt;
  &lt;message name=&quot;HappyBirthday&quot;&gt;
    &lt;text&gt;Happy Birthday, {0}! You don''t look {1,number}.&lt;/text&gt;
  &lt;/message&gt;
  &lt;exception name=&quot;TooYoung&quot;&gt;
    &lt;text&gt;{0} has not been born yet.&lt;/text&gt;
  &lt;/exception&gt;
&lt;/resourceBundle&gt;</pre>
</blockquote>

<h3>Create ANT target</h3>
<p>Now modify (or create) your ANT build-file, <code>build.xml</code>, as follows:</p>
<blockquote>
  <pre>&lt;taskdef name=&quot;resgen&quot; classname=&quot;org.eigenbase.resgen.ResourceGenTask&quot;&gt;
  &lt;classpath path=&quot;lib/eigenbase-resgen.jar:lib/eigenbase-xom.jar&quot;/&gt;
&lt;/taskdef&gt;

&lt;target name=&quot;generate.resources&quot;&gt;
  &lt;resgen srcdir=&quot;source&quot; locales=&quot;en_US&quot;&gt;
    &lt;include name=&quot;BirthdayResource_en_US.xml&quot;/&gt;
  &lt;/resgen&gt;
&lt;/target&gt;
&lt;/target&gt;</pre>
</blockquote>

<p>I have assumed that your C++ source files are held in the &quot;<code>source</code>&quot;
directory.  I also assume that you'll write your own Makefile or
equivalent to compile the code generated (<code>BirthdayResource.h</code> and
<code>BirthdayResource.cpp</code> in this example).</p>

<h3>Compile</h3>
<p>Build as follows. (You need 'ant' on your path, and you will need to edit the
project.classpath property in <code>build.xml</code>.)</p>
<blockquote>
  <pre>$ ant
Buildfile: build.xml

generate.resources:
[resgen] Generating source\BirthdayResource.properties
[resgen] Generating source\BirthdayResource_en_US.properties
[resgen] Generating source\BirthdayResource.h
[resgen] Generating source\BirthdayResource.cpp

BUILD SUCCESSFUL

Total time: 3 seconds</pre>
</blockquote>

<p>Four files are generated.</p>
<p><code>source/happy/BirthdayResource.h</code>:</p>
<blockquote>
  <pre>// This class is generated. Do NOT modify it, or
// add it to source control.

/**
 * This class was generated
 * by class mondrian.resource.ResourceGen
 * from /BirthdayResource_en_US.xml
 * on Wed Feb 18 13:10:31 PST 2004.
 * It contains a list of messages, and methods to
 * retrieve and format those messages.
 **/

#ifndef Fennel_BirthdayResource_Included
#define Fennel_BirthdayResource_Included

#include &lt;ctime&gt;
#include &lt;string&gt;

#include "Locale.h"
#include "ResourceDefinition.h"
#include "ResourceBundle.h"

// begin includes specified by BirthdayResource_en_US.xml
#include "Excn.h"
// end includes specified by BirthdayResource_en_US.xml

using namespace std;

    /** <code>HappyBirthday</code> is 'Happy Birthday, {0}! You don''t look {1,number}.'     */
class HappyBirthday : public ResourceDefinition
{
  public:
  HappyBirthday(ResourceBundle *bundle, const string &key);

  string operator()(const string &p0, int p1) const;
};


    /** <code>TooYoung</code> is '{0} has not been born yet.'    */
class TooYoung : public ResourceDefinition
{
  public:
  TooYoung(ResourceBundle *bundle, const string &key);

  string operator()(const string &p0) const;
};


class BirthdayResource;
typedef map<Locale, BirthdayResource*, localeLess> BirthdayResourceBundleCache;

class BirthdayResource : ResourceBundle
{
  protected:
  BirthdayResource(Locale locale);

  public:
  virtual ~BirthdayResource() { }

  static const BirthdayResource &instance();
  static const BirthdayResource &instance(const Locale &locale);

  static void setResourceFileLocation(const string &location);

  HappyBirthday HappyBirthday;

  TooYoung TooYoung;
  Excn* newTooYoung(const string &p0) const;

  template<class _GRB, class _BC, class _BC_ITER>
    friend _GRB *makeInstance(_BC &bundleCache, const Locale &locale);
};

#endif // Fennel_BirthdayResource_Included</pre>
</blockquote>

<p><code>source/happy/BirthdayResource.cpp</code>:</p>
<blockquote>
  <pre>// This class is generated. Do NOT modify it, or
// add it to source control.

/**
 * This class was generated
 * by class mondrian.resource.ResourceGen
 * from BirthdayResource_en_US.xml
 * on Wed Feb 18 13:14:30 PST 2004.
 * It contains a list of messages, and methods to
 * retrieve and format those messages.
 **/

#include "BirthdayResource.h"
#include "ResourceBundle.h"
#include "Locale.h"

#include &lt;map&gt;
#include &lt;string&gt;

using namespace std;

#define BASENAME ("BirthdayResource")

static BirthdayResourceBundleCache bundleCache;
static string bundleLocation("");

const BirthdayResource &BirthdayResource::instance()
{
  return BirthdayResource::instance(Locale::getDefault());
}

const BirthdayResource &BirthdayResource::instance(const Locale &locale)
{
  return *makeInstance<BirthdayResource, BirthdayResourceBundleCache, BirthdayResourceBundleCache::iterator>(bundleCache, locale);
}

void BirthdayResource::setResourceFileLocation(const string &location)
{
  bundleLocation = location;
}

BirthdayResource::BirthdayResource(Locale locale)
  : ResourceBundle(BASENAME, locale, bundleLocation),
    HappyBirthday(this, "HappyBirthday"),
    TooYoung(this, "TooYoung")
{ }

Excn* BirthdayResource::newTooYoung(const string &p0) const
{
  return new Excn(TooYoung.operator()(p0));
}

HappyBirthday::HappyBirthday(ResourceBundle *bundle, const string &key)
  : ResourceDefinition(bundle, key)
{ }

string HappyBirthday::operator()(const string &p0, int p1) const
{
  return format(p0, p1);
}

TooYoung::TooYoung(ResourceBundle *bundle, const string &key)
  : ResourceDefinition(bundle, key)
{ }

string TooYoung::operator()(const string &p0) const
{
  return format(p0);
}</pre></blockquote>

<p><code>source/happy/BirthdayResource.properties</code>:</p>
<blockquote>
  <pre>HappyBirthday=Happy Birthday, {0}! You don''t look {1, number}.
TooYoung={0} has not been born yet.</pre>
</blockquote>
<p><code>source/happy/BirthdayResource_en_US.properties</code>:</p>
<blockquote>
  <pre># This file is intentionally blank. Add property values
# to this file to override the translations in the base
# properties file, BirthdayResource.properties.</pre>
</blockquote>

<p>For each resource, a member variable is generated in the generated
class.  The member variable allows you to use <code>operator()</code>
to generate the resource's message with appropriate arguments
substituted.  In addition a <code>new<i>Xxx</i>()</code> function is
generated for each exception resource to retrieve an instance of that
exception.</p>

<p>To obtain an instance of the resource bundle
(e.g. <code>BirthdayResource</code>), use the static
<code>instance()</code> or <code>instance(const Locale &)</code>
methods.  The former returns an instance for the default locale and
the latter returns an instance for the given locale.

<p>Tokens such as <code>{0}</code> and <code>{1, number}</code> in the
message are automatically converted to method parameters of the right
type. This means that if you ever change the parameters in your error
message, or accidentally delete it, you code will no longer build. (If
your code doesn't compile, you can fix the problem immediately; better
that than getting a phone call, &quot;I just got this really weird
error...&quot;, in a few months time.)</p>

<p>Here's how you might use it in your code:</p>
<blockquote>
  <pre>#include "BirthdayResource.h"

#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

void wishHappyBirthday(const string &name, int age) {
  if (age &lt; 0) {
    throw BirthdayResource::instance().newTooYoung(name);
  }

  cout << BirthdayResource::instance().HappyBirthday(name, age) << endl;
}

int main(int argc, char **argv) {
  BirthdayResources::setResourceFileLocation("./");

  try {
    wishHappyBirthday("Fred", 33);
    wishHappyBirthday("Wilma", -3);
  }
  catch(Excn *x) {
    cout << "Exception: " << x-&gt;getMessage() << endl;
  }

  return 0;
}
</pre></blockquote>
<p>This produces the following output.</p>
<blockquote>
    <pre>Happy Birthday, Fred! You don't look 33.
Exception: Wilma has not been born yet.</pre>
</blockquote>

<p>In ResGen C++ resources, it is the framework's responsibility to
handle switching from locale to locale.</p>

<hr>

</body>
</html>