This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
user-defined messages facet
- From: awlaframboise at aol dot com
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 05 May 2002 08:56:29 -0400
- Subject: user-defined messages facet
hello,
i'm trying to use a user-defined messages facet that derives from std::messages, in the manner described in bjarne's book (D.4.7). however, i'm having some difficulties, and the manual at http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/messages.html didnt discuss using the messages facet this way.
i'm using the latest snapshot "gcc version 3.1 20020429 (prerelease)" on i686-pc-mingw32, Windows XP, MSYS 1.0.7.
Here is my test program:
-----
#include <iostream>
#include <locale>
#include <string>
class mymsgs : public std::messages<char> {
public:
explicit mymsgs(size_t = 0) {
}
virtual catalog do_open(const std::basic_string<char> &name,
const std::locale &loc) const {
std::cout << "do_open: " << name << ", " << loc.name() << '\n';
return 2;
}
virtual string_type do_get(catalog cat, int set, int msgid,
const string_type &dfault) const {
std::cout << "do_get: " << cat << ", " << set << ", " << msgid
<< ", " << dfault << '\n';
return std::string("mystring");
}
virtual void do_close(catalog cat) const {
std::cout << "do_close: " << cat << '\n';
}
};
int main() {
const std::messages<char> &msgfacet = std::use_facet<mymsgs>(std::locale());
std::messages<char>::catalog cat = msgfacet.open(std::string("myname"), std::locale());
msgfacet.get(cat, 2, 3, std::string("mydefault"));
msgfacet.close(cat);
try {
const mymsgs &test = dynamic_cast<const mymsgs &>(msgfacet);
std::cout << "ok\n";
}
catch(...) {
std::cout << "failed\n";
}
}
-----
i invoke gcc with "g++ -Wall -W -ansi -pedantic -O0 -g3 -o mytest mytest.cpp" and only get one warning about the unused variable. when i run it, i only get "failed" as output. none of the print statements in the facet members are run, and apparently the facet is not actually my facet.
i cant figure out whats going wrong here: 1) gdb is kindof flakey on this target for some reason 2) i cant quite figure out the design of libstdc++-v3 locales..
can someone lend me some guidance?
AaronWL