00001 /* 00002 // $Id: //open/dev/fennel/common/ResourceDefinition.cpp#12 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2004-2009 SQLstream, Inc. 00006 // Copyright (C) 2005-2009 LucidEra, Inc. 00007 // 00008 // This program is free software; you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by the Free 00010 // Software Foundation; either version 2 of the License, or (at your option) 00011 // any later version approved by The Eigenbase Project. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #include "fennel/common/CommonPreamble.h" 00024 #include "fennel/common/ResourceDefinition.h" 00025 #include "fennel/common/ResourceBundle.h" 00026 00027 #include <cassert> 00028 #include <string> 00029 #include <sstream> 00030 #include <boost/format.hpp> 00031 00032 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/common/ResourceDefinition.cpp#12 $"); 00033 00034 using namespace std; 00035 00036 ResourceDefinition::ResourceDefinition( 00037 ResourceBundle *bundle, 00038 const string &key) 00039 : _key(key), _bundle(bundle) 00040 { 00041 assert(!key.empty()); 00042 assert(bundle != NULL); 00043 } 00044 00045 ResourceDefinition::~ResourceDefinition() 00046 { 00047 } 00048 00049 // REVIEW jvs 18-Feb-2004: Why the special case for no-args? 00050 string ResourceDefinition::format() const 00051 { 00052 if (_bundle->hasMessage(_key)) { 00053 return _bundle->getMessage(_key); 00054 } else { 00055 boost::format fmt("%1%.%2%.%3%()"); 00056 return (fmt 00057 % _bundle->getBaseName() 00058 % _bundle->getLocale().getDisplayName() 00059 % _key).str(); 00060 } 00061 } 00062 00063 00064 boost::format ResourceDefinition::prepareFormatter(int numArgs) const 00065 { 00066 if (_bundle->hasMessage(_key)) { 00067 return boost::format(_bundle->getMessage(_key)); 00068 } else { 00069 stringstream formatSpecifier; 00070 formatSpecifier << "%1%.%2%.%3%("; 00071 for (int i = 0; i < numArgs; i++) { 00072 if (i != 0) { 00073 formatSpecifier << ", "; 00074 } 00075 formatSpecifier << "%" << (i + 4) << "%"; 00076 } 00077 formatSpecifier << ")"; 00078 00079 boost::format fmt(formatSpecifier.str()); 00080 00081 fmt 00082 % _bundle->getBaseName() 00083 % _bundle->getLocale().getDisplayName() 00084 % _key; 00085 00086 // formatter is now ready for numArgs parameters 00087 return fmt; 00088 } 00089 } 00090 00091 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/common/ResourceDefinition.cpp#12 $"); 00092 00093 // End ResourceDefinition.cpp