Re: Announcing Xrtti - Extended Runtime Type Information for C++
On May 3, 9:53 am, bji-gg...@ischo.com wrote:
2) Essential follows a style that I prefer greatly over
Boost and *especially* the C++ STL. I tried to be more "Java-like"
and less "template-programming-like".
The two are not incomparible. The following is a snippet from a unit
test that implemented the JMS interface over MQ using C++. You can see
that it very much has the feel of Java, but 100% composed of standard
tools, like STL, and tr1 smart pointers. THis is the part that tests
queueBrowsers, selected because it demonstrates how to use iterators
even without templates
using namespace jmsi;//interface is in jmsi
try
{
jmsi::ConnectionFactory connfactory (loadMQJMSProvider());
jmsmq::MQConnectionFactory qm=
interface_cast<jmsmq::MQConnectionFactory>(connfactory);
CPPUNIT_ASSERT(qm);
qm.setQueueManager(lookupqname());
Connection conn= connfactory.createConnection();
QueueConnection queueConn=interface_cast<QueueConnection >(conn);
CPPUNIT_ASSERT(queueConn);
QueueSession queueSession = queueConn.createQueueSession(false,
SessionAckMode::DUPS_OK_ACKNOWLEDGE);
Queue queue =queueSession.createTemporaryQueue();
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
queueConn.start();
{
//empty the queue for the tests
Message rmessage;
do
{
rmessage = queueReceiver.receiveNoWait();
if(rmessage)
{
TextMessage tmsg=interface_cast<TextMessage>(rmessage);
if(tmsg)
{
std::cout<<"Got a TextMessage that says "<<
tmsg.getText()<<"\n";
std::cout<<"\tDeliveryMode
"<<tmsg.getJMSDeliveryMode();
std::cout<<"\tPriority "<<tmsg.getJMSPriority();
std::cout<<"\n";
}
}
}
while(rmessage);
}
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage();
message.setText("hello world");
message.setJMSExpiration(_test_big_reps);
message.setStringProperty("JMSXGroupID","Lance");
CPPUNIT_ASSERT(message.getText()=="hello world");
CPPUNIT_ASSERT(message.getStringProperty("JMSXGroupID")=="Lance");
queueSender.send(message);
for (int i = 0;i<10;++i){
std::ostringstream ii;
ii<<"This is message :"<<i;
TextMessage message2 = queueSession.createTextMessage(ii.str());
message2.setStringProperty("JMSXGroupID","LanceTest");
queueSender.send(message2);
}
{
QueueBrowser queueBrowser = queueSession.createBrowser(queue);
CPPUNIT_ASSERT(
queueBrowser.getQueue().getName()==queue.getName() );
MessageIterator msgiter=queueBrowser.begin();
MessageIterator msgiterend=queueBrowser.end();
CPPUNIT_ASSERT(msgiter != msgiterend);
int i = 0;
while(msgiter!= msgiterend){
++msgiter;
++i;
}
CPPUNIT_ASSERT(i>9);//at least the messages we just put on the
queue
}
{
QueueBrowser queueBrowser = queueSession.createBrowser(queue);
std::vector<Message> vecmsg;
std::copy(queueBrowser.begin(),queueBrowser.end(),std::back_inserter(vecmsg));
std::sort(vecmsg.begin(),vecmsg.end());
CPPUNIT_ASSERT(vecmsg.size()>9);//at least the messages we just
put on the queue
}
//MORE TESTS.....
}
catch(std::exception const&_j)
{ //ETC
}
And - the Xrtti library only uses the Essential library in a very
minimal way; just for Hashtables, Strings, and Vectors. These could
*easily* be replaced by C++ STL, in which case there would be no need
to link anything into a program using Xrtti except the Xrtti library
itself.
That would be a huge selling point.
In any case I have my own 'essentials' library as well, because I need
sometime a different implementation of string or a shared_ptr that
boost or other vendors do not have (e.g. the above code uses intrusive
ref counted shared_ptrs, with weak_ptr support, plus, "strings" that
do not allocate memory) , but it is 100% standard compatible.
Thanks for your comments, they are much appreciated.
Bryan
You are welcome :)
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]