Xavax C++ Library Class Index   FAQ   Overview

Class xavax::MessageCatalog

MessageCatalog implements a message catalog consisting of one or more message sets, each consisting of one or more messages.

Constructor Summary
MessageCatalog(const char* name, const MessageSetData* setData, UInt16 nSets)
         Construct a MessageCatalog object.

Method Summary
const char* defaultText(UInt16 setNum, UInt16 msgNum)
         Return the default text for a message.
UInt16 maxSets() const
         Return the maximum set capacity for this catalog.
const char* name() const
         Return the filename for this message catalog.
MessageSet* set(UInt16) const
         Return a pointer to the specified message set.
UInt16 setCount() const
         Return the number of message sets in this catalog.
bool open()
         Open the message catalog.
const char* text(UInt16 setNum, UInt16 msgNum)
         Return the text for a message.

Related Classes
Formatter, Message, MessageSet

Constructor Detail

MessageCatalog

MessageCatalog(const char* name, const MessageSetData* setData, UInt16 nSets)
Construct a MessageCatalog object using the set definitions provided by setData.
Parameters:
name - the filename of the message catalog.
setData - an array of message set definitions.
nSets - the number of set definitions in setData.

Method Detail

defaultText

const char* defaultText(UInt16 setNum, UInt16 msgNum)
Return the default text for the specified message set and message. The default text is used when the message catalog file is not available.
Parameters:
setNum - the message set number.
msgNum - the message number.
Returns:
the default text for a message, or null if the message was not found.

maxsets

UInt16 maxSets() const
Return the maximum number of sets for this catalog. Sets can be added after a catalog is created.
Returns:
the maximum number of sets for this catalog.

name

const char* name() const
Return the filename of the message catalog.
Returns:
the filename of the message catalog.

open

bool open()
Open the message catalog and merge the data from the message catalog with the default data.
Returns:
true if the operation was successful.
Throws:
MsgCatOpenError - if an error occurred opening the message catalog.
MsgCatReadError - if an error occurred reading the message catalog.
MsgCatResourceException - if sufficient resources were not available.

set

MessageSet* set(UInt16 setNum) const
Return the message set specified by setNum.
Parameters:
setNum - the message set number.
Returns:
a pointer to the specified message set, or null if no set was found.

setcount

UInt16 setCount() const
Return the number of message sets in this catalog.
Returns:
the number of message sets.

text

const char* text(UInt16 setNum, UInt16 msgNum)
Return the message text for the specified message. If the message catalog file is not available, the default text is returned.
Parameters:
setNum - the message set number.
msgNum - the message number.
Returns:
the text for a message.

Example Code

//
// Copyright (c) 1997,2003 Phillip L. Harbison
// All Rights Reserved
//
// Program Name: Test4
// Usage:
//   Test4
// Description:
//   This program tests the message catalog facility.
//

#include Headers_h
#include Headers_h
#include Cx_h
#include MessageCatalog_h
#include <stdlib.h>
#include <iostream.h>

//
// Include the definitions created by the message editor.
//
#include "Test4Msg.h"

int main(int argc, char **argv)
{
  //
  // Create the message catalog using default data provided
  // by the message editor in Test4Msg.h and Test4Msg.C.
  //
  MessageCatalog* mcp = new MessageCatalog("./Test4.cat", Test4Catalog);
  try {
    // Open the message catalog.
    mcp->open();
    const char *cp;
    // Output message 1 of set 1.
    cp = mcp->text(1, Set1Msg1);
    cout << cp << endl;
    // Output message 2 of set 1.
    cp = mcp->text(1, Set1Msg2);
    cout << cp << endl;
    // Output message 1 of set 2.
    cp = mcp->text(2, Set2Msg1);
    cout << cp << endl;
    // Output message 2 of set 2.
    cp = mcp->text(2, Set2Msg2);
    cout << cp << endl;
  }
  catch (Exception &e) {
    cerr << "Exception type: " << e.classRecord()->name() << endl;
    e.print();
  }
}

Test4Msg.h

//
// This file was created by the message editor and should not be edited.
// Make any changes using the message editor and regenerate the file.
//
#ifndef _Test4Msg_h
#define _Test4Msg_h

typedef enum Test4Set1_e {
  Set1Msg1 = 1,
  Set1Msg2 = 2
} Test4Set1;

typedef enum Test4Set2_e {
  Set2Msg1 = 1,
  Set2Msg2 = 2
} Test4Set2;

extern MessageCatalogData Test4Catalog;

#endif

Test4Msg.C

//
// This file was created by the message editor and should not be edited.
// Make any changes using the message editor and regenerate the file.
//
#include Headers_h
#include Headers_h
#include Cx_h
#include MessageCatalog_h
#include "Test4Msg.h"

MessageData Test4Set1Msgs[] = {
  { Set1Msg1, "## default ## Set 1 Test message 1." },
  { Set1Msg2, "## default ## Set 1 Test message 2." }
};
  
MessageData Test4Set2Msgs[] = {
  { Set2Msg1, "## default ## Set 2 Test message 1." },
  { Set2Msg2, "## default ## Set 2 Test message 2." }
};
  
MessageSetData Test4Sets[] = {
  { 1, Number(Test4Set1Msgs), Test4Set1Msgs },
  { 2, Number(Test4Set2Msgs), Test4Set2Msgs }
};

MessageCatalogData Test4Catalog = {
  Number(Test4Sets), Test4Sets
};

Copyright © 2003 Xavax Inc. -- All Rights Reserved