testresources.cpp00001 #include <kdebug.h>
00002 #include <kapplication.h>
00003 #include <kaboutdata.h>
00004 #include <kcmdlineargs.h>
00005
00006 #include "resource.h"
00007 #include "manager.h"
00008
00009 using namespace KRES;
00010
00011 class TestResource : public Resource
00012 {
00013 public:
00014 TestResource() : Resource( 0 ) {}
00015
00016 };
00017
00018 class TestSubResource : public TestResource
00019 {
00020 public:
00021 TestSubResource() : TestResource() {}
00022
00023 void dump() const
00024 {
00025 kdDebug() << "TestSubResource" << endl;
00026 TestResource::dump();
00027 }
00028 };
00029
00030 int main( int argc, char **argv )
00031 {
00032 KAboutData aboutData( "testresources", "Kresource Test", "0" );
00033 KCmdLineArgs::init( argc, argv, &aboutData );
00034
00035 KApplication app;
00036
00037 Manager<TestResource> manager( "test" );
00038
00039 TestResource *resource1 = new TestResource;
00040 resource1->setResourceName( "One" );
00041 manager.add( resource1 );
00042
00043 TestResource *resource2 = new TestSubResource;
00044 resource2->setResourceName( "Two" );
00045 manager.add( resource2 );
00046
00047 TestResource *resource3 = new TestSubResource;
00048 resource3->setResourceName( "Three" );
00049 manager.add( resource3 );
00050
00051 kdDebug() << "LIST ALL:" << endl;
00052 Manager<TestResource>::Iterator it;
00053 for( it = manager.begin(); it != manager.end(); ++it ) {
00054 (*it)->dump();
00055 }
00056
00057 resource2->setActive( false );
00058 resource3->setActive( true );
00059
00060 kdDebug() << "LIST ACTIVE" << endl;
00061 Manager<TestResource>::ActiveIterator it2;
00062 for( it2 = manager.activeBegin(); it2 != manager.activeEnd(); ++it2 ) {
00063 (*it2)->dump();
00064 }
00065
00066 resource1->setActive( false );
00067 resource2->setActive( true );
00068 resource3->setActive( true );
00069
00070 kdDebug() << "LIST ACTIVE" << endl;
00071 for( it2 = manager.activeBegin(); it2 != manager.activeEnd(); ++it2 ) {
00072 (*it2)->dump();
00073 }
00074
00075 kdDebug() << "LIST ALL" << endl;
00076 for( it = manager.begin(); it != manager.end(); ++it ) {
00077 (*it)->dump();
00078 }
00079
00080
00081 }
|