This commit is contained in:
fgerlits 2007-01-22 11:56:46 +00:00
parent 6700878ccb
commit 7b79a6835e
8 changed files with 95 additions and 0 deletions

View file

@ -11,4 +11,8 @@
<rdsContainer> <rdsContainer>
<rdsItem key="PS" value="BBC Four" enabled="1" /> <rdsItem key="PS" value="BBC Four" enabled="1" />
<rdsItem key="RT" value="C. Monster - Monsterpiece Theater"
enabled="1" />
<rdsItem key="RT" value="Acme Birdseed for the discerning coyote"
enabled="0" />
</rdsContainer> </rdsContainer>

View file

@ -271,6 +271,20 @@ class OptionsContainer
getRdsEnabled(Ptr<const Glib::ustring>::Ref key) getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument); throw (std::invalid_argument);
/**
* Get a string containing all the RDS values.
* This string can be sent to the RDS encoder.
*
* @return a string which can be sent to the RDS encoder;
* a 0 pointer if no RDS options have been defined.
*/
Ptr<Glib::ustring>::Ref
getCompleteRdsString(void) throw ()
{
return rdsContainer ? rdsContainer->toString()
: Ptr<Glib::ustring>::Ref();
}
/** /**
* Save the options to a file. * Save the options to a file.
* *

View file

@ -201,6 +201,14 @@ class RdsContainer : public Configurable
getRdsEnabled(Ptr<const Glib::ustring>::Ref key) getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument); throw (std::invalid_argument);
/**
* Convert the object to a string.
*
* @return a string which can be sent to the RDS encoder.
*/
Ptr<Glib::ustring>::Ref
toString(void) throw ();
/** /**
* Convert the object to XML. * Convert the object to XML.
* *

View file

@ -241,6 +241,14 @@ class RdsItem : public Configurable
touched = true; touched = true;
} }
/**
* Convert the object to a string.
*
* @return a string which can be sent to the RDS encoder.
*/
Ptr<Glib::ustring>::Ref
toString(void) throw ();
/** /**
* Convert the object to XML. * Convert the object to XML.
* *

View file

@ -155,6 +155,24 @@ RdsContainer :: getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
} }
/*------------------------------------------------------------------------------
* Convert the object to a string.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
RdsContainer :: toString(void) throw ()
{
Ptr<Glib::ustring>::Ref rdsString(new Glib::ustring);
RdsItemListType::const_iterator it;
for(it = rdsItemList.begin(); it != rdsItemList.end(); ++it) {
Ptr<RdsItem>::Ref rdsItem = *it;
rdsString->append(*rdsItem->toString());
}
return rdsString;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Convert the object to XML. * Convert the object to XML.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -40,6 +40,7 @@
#endif #endif
#include <fstream> #include <fstream>
#include <iostream>
#include "RdsContainerTest.h" #include "RdsContainerTest.h"
@ -133,3 +134,17 @@ RdsContainerTest :: firstTest(void)
CPPUNIT_ASSERT(enabled); CPPUNIT_ASSERT(enabled);
} }
/*------------------------------------------------------------------------------
* Test the toString() method.
*----------------------------------------------------------------------------*/
void
RdsContainerTest :: toStringTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<const Glib::ustring>::Ref string = rdsContainer->toString();
CPPUNIT_ASSERT(string);
CPPUNIT_ASSERT(*string == "PS=BBC Four\n"
"RT=C. Monster - Monsterpiece Theater\n");
}

View file

@ -72,6 +72,7 @@ class RdsContainerTest : public BaseTestMethod
{ {
CPPUNIT_TEST_SUITE(RdsContainerTest); CPPUNIT_TEST_SUITE(RdsContainerTest);
CPPUNIT_TEST(firstTest); CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(toStringTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -91,6 +92,14 @@ class RdsContainerTest : public BaseTestMethod
void void
firstTest(void) throw (CPPUNIT_NS::Exception); firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the toString() method.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
toStringTest(void) throw (CPPUNIT_NS::Exception);
public: public:

View file

@ -122,6 +122,25 @@ RdsItem :: configure(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Convert the object to a string.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
RdsItem :: toString(void) throw ()
{
Ptr<Glib::ustring>::Ref rdsString(new Glib::ustring);
if (enabled) {
rdsString->append(*key);
rdsString->append("=");
rdsString->append(*value);
rdsString->append("\n");
}
return rdsString;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Convert the object to XML. * Convert the object to XML.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/