From 509d136e9adb60c56369565b9545e613cac3678e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 12 Nov 2009 17:05:30 +0000 Subject: I've started my campaign to clean up all of the header files in libbu++ as far as includes go. This required a little bit of reworking as far as archive goes, but I've been planning on changing it aronud for a bit anyway. The final result here is that you may need to add some more includes in your own code, libbu++ doesn't include as many random things you didn't ask for anymore, most of these seem to be bu/hash.h, unistd.h, and time.h. Also, any Archive functions and operators should use ArchiveBase when they can instead of Archive, archivebase.h is a much lighterweight include that will be used everywhere in core that it can be, there are a few classes that actually want a specific archiver to be used, they will use it (such as the nids storage class). So far, except for adding header files, nothing has changed in functionality, and no other code changes should be required, although the above mentioned archive changeover is reccomended. --- src/tests/archive.cpp | 3 ++- src/tests/archive2.cpp | 6 ++--- src/tests/cache.cpp | 1 + src/tests/fastcgi.cpp | 2 ++ src/tests/heap.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ src/tests/itoheap.cpp | 1 + src/tests/listsort.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/tests/ringbuffer.cpp | 2 ++ src/tests/serverticks.cpp | 1 + src/tests/socketblock.cpp | 1 + src/tests/socketbreak.cpp | 1 + src/tests/uuid.cpp | 14 +++++++++++ 12 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 src/tests/listsort.cpp create mode 100644 src/tests/uuid.cpp (limited to 'src/tests') diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp index 131d4de..8a5f6ee 100644 --- a/src/tests/archive.cpp +++ b/src/tests/archive.cpp @@ -7,6 +7,7 @@ #include "bu/archive.h" #include "bu/file.h" +#include "bu/fstring.h" using namespace Bu; @@ -15,7 +16,7 @@ int main() File f("test.dat", File::Write ); Archive ar( f, Archive::save ); - std::string s("Hello there"); + Bu::FString s("Hello there"); ar << s; return 0; diff --git a/src/tests/archive2.cpp b/src/tests/archive2.cpp index fddb91b..3d95c2f 100644 --- a/src/tests/archive2.cpp +++ b/src/tests/archive2.cpp @@ -23,7 +23,7 @@ public: { } - virtual void archive( Bu::Archive &ar ) + virtual void archive( Bu::ArchiveBase &ar ) { ar && iId; } @@ -47,7 +47,7 @@ public: delete a2; } - virtual void archive( Bu::Archive &ar ) + virtual void archive( Bu::ArchiveBase &ar ) { //ar && iId && a1 && a2; ar << iId << a1 << a2; @@ -73,7 +73,7 @@ public: delete b; } - virtual void archive( Bu::Archive &ar ) + virtual void archive( Bu::ArchiveBase &ar ) { //ar && iId && a && b; ar << iId; diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 3fcc34c..a098145 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "bu/cache.h" #include "bu/file.h" diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp index cd6cdda..46a7d62 100644 --- a/src/tests/fastcgi.cpp +++ b/src/tests/fastcgi.cpp @@ -7,6 +7,8 @@ #include "bu/fastcgi.h" +#include + class Cgi : public Bu::FastCgi { public: diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp index daa0356..ae130ec 100644 --- a/src/tests/heap.cpp +++ b/src/tests/heap.cpp @@ -8,7 +8,10 @@ #include #include +#include "bu/formatter.h" #include "bu/heap.h" +#include "bu/fstring.h" +#include "bu/file.h" typedef struct num { @@ -35,8 +38,18 @@ typedef struct num } } num; +void printHeap( Bu::Heap &h, int j ) +{ + Bu::FString sFName; + sFName.format("graph-step-%02d.dot", j ); + Bu::File fOut( sFName, Bu::File::WriteNew ); + Bu::Formatter f( Bu::File ); + //h.print( f ); +} + int main() { + /* Bu::Heap hNum; for( int j = 0; j < 30; j++ ) @@ -53,6 +66,46 @@ int main() hNum.dequeue(); } printf("\n"); +*/ + Bu::Heap hStr; + int j = 0; + + hStr.enqueue("George"); + printHeap( hStr, j++ ); + hStr.enqueue("Sam"); + printHeap( hStr, j++ ); + hStr.enqueue("Abby"); + printHeap( hStr, j++ ); + hStr.enqueue("Zorro"); + printHeap( hStr, j++ ); + hStr.enqueue("Brianna"); + printHeap( hStr, j++ ); + hStr.enqueue("Kate"); + printHeap( hStr, j++ ); + hStr.enqueue("Soggy"); + printHeap( hStr, j++ ); + + while( !hStr.isEmpty() ) + { + printf("\"%s\" ", hStr.dequeue().getStr() ); + printHeap( hStr, j++ ); + } + printf("\n"); + + Bu::List lStr; + + lStr.insertSorted("George"); + lStr.insertSorted("Sam"); + lStr.insertSorted("Abby"); + lStr.insertSorted("Zorro"); + lStr.insertSorted("Brianna"); + lStr.insertSorted("Kate"); + lStr.insertSorted("Soggy"); + for( Bu::List::iterator i = lStr.begin(); i; i++ ) + { + printf("\"%s\" ", (*i).getStr() ); + } + printf("\n"); return 0; } diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp index 9016d86..c5816b2 100644 --- a/src/tests/itoheap.cpp +++ b/src/tests/itoheap.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "bu/itoheap.h" #include "bu/ito.h" diff --git a/src/tests/listsort.cpp b/src/tests/listsort.cpp new file mode 100644 index 0000000..f9236e6 --- /dev/null +++ b/src/tests/listsort.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +using namespace Bu; + +int main() +{ + FString a("Soggy"), b("Sam"); + + if( a < b ) + { + sio << "Bad" << sio.nl; + } + else + { + sio << "Good" << sio.nl; + } + + typedef List StrList; + + StrList lNames; + + lNames.append("George"); + lNames.append("Sam"); + lNames.append("Abby"); + lNames.append("Zorro"); + lNames.append("Brianna"); + lNames.append("Kate"); + lNames.append("Soggy"); + + sio << "Names: " << lNames << sio.nl; + lNames.sort(); + + sio << "Names: " << lNames << sio.nl; + + StrList lNames2; + + lNames2.insertSorted("George"); + lNames2.insertSorted("Sam"); + lNames2.insertSorted("Abby"); + lNames2.insertSorted("Zorro"); + lNames2.insertSorted("Brianna"); + lNames2.insertSorted("Kate"); + lNames2.insertSorted("Soggy"); + + sio << "Names: " << lNames2 << sio.nl; + + if( lNames == lNames2 ) + { + sio << "They're the same." << sio.nl; + } + else + { + sio << "They're different." << sio.nl; + } + + return 0; +} + diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp index 46c515b..9489b30 100644 --- a/src/tests/ringbuffer.cpp +++ b/src/tests/ringbuffer.cpp @@ -7,6 +7,8 @@ #include "bu/ringbuffer.h" #include +#include +#include int main() { diff --git a/src/tests/serverticks.cpp b/src/tests/serverticks.cpp index e599444..3aad746 100644 --- a/src/tests/serverticks.cpp +++ b/src/tests/serverticks.cpp @@ -8,6 +8,7 @@ #include "bu/server.h" #include "bu/client.h" #include "bu/protocol.h" +#include class TickProtocol : public Bu::Protocol { diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp index 2a7dfdc..5dad46c 100644 --- a/src/tests/socketblock.cpp +++ b/src/tests/socketblock.cpp @@ -9,6 +9,7 @@ #include "bu/socket.h" #include "bu/serversocket.h" #include +#include class TstServer : public Bu::Ito { diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp index e77ae4f..b873830 100644 --- a/src/tests/socketbreak.cpp +++ b/src/tests/socketbreak.cpp @@ -7,6 +7,7 @@ #include "bu/serversocket.h" #include "bu/socket.h" +#include int main() { diff --git a/src/tests/uuid.cpp b/src/tests/uuid.cpp new file mode 100644 index 0000000..4544543 --- /dev/null +++ b/src/tests/uuid.cpp @@ -0,0 +1,14 @@ +#include +#include + +using namespace Bu; + +int main() +{ + Uuid i = Uuid::gen(); + + sio << i.toString() << sio.nl; + + return 0; +} + -- cgit v1.2.3