diff options
| author | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 14:04:47 -0700 |
|---|---|---|
| committer | Mike Buland <mbuland@penny-arcade.com> | 2022-04-20 14:04:47 -0700 |
| commit | fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975 (patch) | |
| tree | f16f7e7f54399ef9c753beb87069eed8122dbccb /src/unstable | |
| parent | d10e6a5ca0905f0ef2836cd98aebfb48e7f1e8a3 (diff) | |
| download | libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.gz libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.bz2 libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.tar.xz libbu++-fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975.zip | |
Gradually moving to better archive structure.
It's dragging other new API changes along with it, including use of Blob
and Text.
Diffstat (limited to 'src/unstable')
| -rw-r--r-- | src/unstable/archivestream.cpp | 127 | ||||
| -rw-r--r-- | src/unstable/archivestream.h | 49 | ||||
| -rw-r--r-- | src/unstable/blob.cpp | 20 | ||||
| -rw-r--r-- | src/unstable/blob.h | 3 | ||||
| -rw-r--r-- | src/unstable/uuid.cpp | 34 | ||||
| -rw-r--r-- | src/unstable/uuid.h | 15 |
6 files changed, 51 insertions, 197 deletions
diff --git a/src/unstable/archivestream.cpp b/src/unstable/archivestream.cpp deleted file mode 100644 index 90a9599..0000000 --- a/src/unstable/archivestream.cpp +++ /dev/null | |||
| @@ -1,127 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2019 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "bu/archivestream.h" | ||
| 9 | |||
| 10 | Bu::ArchiveStream::ArchiveStream( Bu::Archive &ar ) : | ||
| 11 | ar( ar ), | ||
| 12 | iPos( 0 ) | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | Bu::ArchiveStream::~ArchiveStream() | ||
| 17 | { | ||
| 18 | } | ||
| 19 | |||
| 20 | void Bu::ArchiveStream::close() | ||
| 21 | { | ||
| 22 | ar.close(); | ||
| 23 | } | ||
| 24 | |||
| 25 | Bu::size Bu::ArchiveStream::read( void *pBuf, size iBytes ) | ||
| 26 | { | ||
| 27 | ar.read( pBuf, iBytes ); | ||
| 28 | iPos += iBytes; | ||
| 29 | return iBytes; | ||
| 30 | } | ||
| 31 | |||
| 32 | Bu::size Bu::ArchiveStream::write( const void *pBuf, size iBytes ) | ||
| 33 | { | ||
| 34 | ar.write( pBuf, iBytes ); | ||
| 35 | iPos += iBytes; | ||
| 36 | return iBytes; | ||
| 37 | } | ||
| 38 | |||
| 39 | Bu::size Bu::ArchiveStream::tell() | ||
| 40 | { | ||
| 41 | return iPos; | ||
| 42 | } | ||
| 43 | |||
| 44 | void Bu::ArchiveStream::seek( Bu::size ) | ||
| 45 | { | ||
| 46 | throw Bu::UnsupportedException(); | ||
| 47 | } | ||
| 48 | |||
| 49 | void Bu::ArchiveStream::setPos( Bu::size ) | ||
| 50 | { | ||
| 51 | throw Bu::UnsupportedException(); | ||
| 52 | } | ||
| 53 | |||
| 54 | void Bu::ArchiveStream::setPosEnd( Bu::size ) | ||
| 55 | { | ||
| 56 | throw Bu::UnsupportedException(); | ||
| 57 | } | ||
| 58 | |||
| 59 | bool Bu::ArchiveStream::isEos() | ||
| 60 | { | ||
| 61 | return false; | ||
| 62 | } | ||
| 63 | |||
| 64 | bool Bu::ArchiveStream::isOpen() | ||
| 65 | { | ||
| 66 | return true; | ||
| 67 | } | ||
| 68 | |||
| 69 | void Bu::ArchiveStream::flush() | ||
| 70 | { | ||
| 71 | } | ||
| 72 | |||
| 73 | bool Bu::ArchiveStream::canRead() | ||
| 74 | { | ||
| 75 | return true; | ||
| 76 | } | ||
| 77 | |||
| 78 | bool Bu::ArchiveStream::canWrite() | ||
| 79 | { | ||
| 80 | return true; | ||
| 81 | } | ||
| 82 | |||
| 83 | bool Bu::ArchiveStream::isReadable() | ||
| 84 | { | ||
| 85 | return true; | ||
| 86 | } | ||
| 87 | |||
| 88 | bool Bu::ArchiveStream::isWritable() | ||
| 89 | { | ||
| 90 | return true; | ||
| 91 | } | ||
| 92 | |||
| 93 | bool Bu::ArchiveStream::isSeekable() | ||
| 94 | { | ||
| 95 | return false; | ||
| 96 | } | ||
| 97 | |||
| 98 | bool Bu::ArchiveStream::isBlocking() | ||
| 99 | { | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | |||
| 103 | void Bu::ArchiveStream::setBlocking( bool ) | ||
| 104 | { | ||
| 105 | throw Bu::UnsupportedException(); | ||
| 106 | } | ||
| 107 | |||
| 108 | void Bu::ArchiveStream::setSize( Bu::size ) | ||
| 109 | { | ||
| 110 | throw Bu::UnsupportedException(); | ||
| 111 | } | ||
| 112 | |||
| 113 | Bu::size Bu::ArchiveStream::getSize() const | ||
| 114 | { | ||
| 115 | return iPos; | ||
| 116 | } | ||
| 117 | |||
| 118 | Bu::size Bu::ArchiveStream::getBlockSize() const | ||
| 119 | { | ||
| 120 | return 1; | ||
| 121 | } | ||
| 122 | |||
| 123 | Bu::String Bu::ArchiveStream::getLocation() const | ||
| 124 | { | ||
| 125 | return "Archive"; | ||
| 126 | } | ||
| 127 | |||
diff --git a/src/unstable/archivestream.h b/src/unstable/archivestream.h deleted file mode 100644 index da6c6b0..0000000 --- a/src/unstable/archivestream.h +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2019 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | #ifndef BU_ARCHIVE_STREAM_H | ||
| 8 | #define BU_ARCHIVE_STREAM_H | ||
| 9 | |||
| 10 | #include "bu/archive.h" | ||
| 11 | #include "bu/stream.h" | ||
| 12 | |||
| 13 | namespace Bu | ||
| 14 | { | ||
| 15 | class ArchiveStream : public Stream | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | ArchiveStream( Bu::Archive &ar ); | ||
| 19 | virtual ~ArchiveStream(); | ||
| 20 | |||
| 21 | virtual void close(); | ||
| 22 | virtual size read( void *pBuf, size iBytes ); | ||
| 23 | virtual size write( const void *pBuf, size iBytes ); | ||
| 24 | virtual size tell(); | ||
| 25 | virtual void seek( size offset ); | ||
| 26 | virtual void setPos( size pos ); | ||
| 27 | virtual void setPosEnd( size pos ); | ||
| 28 | virtual bool isEos(); | ||
| 29 | virtual bool isOpen(); | ||
| 30 | virtual void flush(); | ||
| 31 | virtual bool canRead(); | ||
| 32 | virtual bool canWrite(); | ||
| 33 | virtual bool isReadable(); | ||
| 34 | virtual bool isWritable(); | ||
| 35 | virtual bool isSeekable(); | ||
| 36 | virtual bool isBlocking(); | ||
| 37 | virtual void setBlocking( bool bBlocking=true ); | ||
| 38 | virtual void setSize( size iSize ); | ||
| 39 | virtual size getSize() const; | ||
| 40 | virtual size getBlockSize() const; | ||
| 41 | virtual Bu::String getLocation() const; | ||
| 42 | |||
| 43 | private: | ||
| 44 | Bu::Archive &ar; | ||
| 45 | size iPos; | ||
| 46 | }; | ||
| 47 | } | ||
| 48 | |||
| 49 | #endif | ||
diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index e72e265..51e74ff 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp | |||
| @@ -142,6 +142,26 @@ bool Bu::Blob::isNullOrEmpty() const | |||
| 142 | return pData == NULL || iSize == 0; | 142 | return pData == NULL || iSize == 0; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | void Bu::Blob::set( const Blob &rRhs ) | ||
| 146 | { | ||
| 147 | *this = rRhs; | ||
| 148 | } | ||
| 149 | |||
| 150 | void Bu::Blob::set( const char *pRhs ) | ||
| 151 | { | ||
| 152 | *this = pRhs; | ||
| 153 | } | ||
| 154 | |||
| 155 | void Bu::Blob::set( const char *pRhs, int32_t iSize ) | ||
| 156 | { | ||
| 157 | delete[] pData; | ||
| 158 | |||
| 159 | this->iSize = iSize; | ||
| 160 | pData = new char[iSize+1]; | ||
| 161 | memcpy( pData, pRhs, iSize ); | ||
| 162 | pData[iSize] = '\0'; | ||
| 163 | } | ||
| 164 | |||
| 145 | Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs ) | 165 | Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs ) |
| 146 | { | 166 | { |
| 147 | delete[] pData; | 167 | delete[] pData; |
diff --git a/src/unstable/blob.h b/src/unstable/blob.h index d6c40e3..214ab41 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h | |||
| @@ -55,6 +55,9 @@ namespace Bu | |||
| 55 | bool isNull() const; | 55 | bool isNull() const; |
| 56 | bool isNullOrEmpty() const; | 56 | bool isNullOrEmpty() const; |
| 57 | 57 | ||
| 58 | void set( const Blob &rRhs ); | ||
| 59 | void set( const char *pRhs ); | ||
| 60 | void set( const char *pRhs, int32_t iSize ); | ||
| 58 | Blob &operator=( const Blob &rRhs ); | 61 | Blob &operator=( const Blob &rRhs ); |
| 59 | Blob &operator=( const char *pRhs ); | 62 | Blob &operator=( const char *pRhs ); |
| 60 | 63 | ||
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index 6642d75..9708423 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp | |||
| @@ -10,6 +10,8 @@ | |||
| 10 | #include "bu/formatter.h" | 10 | #include "bu/formatter.h" |
| 11 | #include "bu/membuf.h" | 11 | #include "bu/membuf.h" |
| 12 | #include "bu/random.h" | 12 | #include "bu/random.h" |
| 13 | #include "bu/archive.h" | ||
| 14 | #include "bu/blobbuilder.h" | ||
| 13 | #include <string.h> | 15 | #include <string.h> |
| 14 | 16 | ||
| 15 | #ifdef WIN32 | 17 | #ifdef WIN32 |
| @@ -27,11 +29,11 @@ Bu::Uuid::Uuid( const Uuid &src ) | |||
| 27 | memcpy( data, src.data, 16 ); | 29 | memcpy( data, src.data, 16 ); |
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | Bu::Uuid::Uuid( const Bu::String &sSrc ) | 32 | Bu::Uuid::Uuid( const Bu::Blob &sSrc ) |
| 31 | { | 33 | { |
| 32 | if( sSrc.getSize() == 16 ) | 34 | if( sSrc.getSize() == 16 ) |
| 33 | { | 35 | { |
| 34 | memcpy( data, sSrc.getStr(), 16 ); | 36 | memcpy( data, sSrc.getData(), 16 ); |
| 35 | } | 37 | } |
| 36 | else if( sSrc.getSize() == 36 ) | 38 | else if( sSrc.getSize() == 36 ) |
| 37 | { | 39 | { |
| @@ -44,12 +46,12 @@ Bu::Uuid::~Uuid() | |||
| 44 | { | 46 | { |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 47 | Bu::String Bu::Uuid::toRawString() const | 49 | Bu::Blob Bu::Uuid::toRawBlob() const |
| 48 | { | 50 | { |
| 49 | return Bu::String( (char *)data, 16 ); | 51 | return Bu::Blob( (char *)data, 16 ); |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | Bu::String Bu::Uuid::toString() const | 54 | Bu::Blob Bu::Uuid::toBlob() const |
| 53 | { | 55 | { |
| 54 | Bu::MemBuf mb; | 56 | Bu::MemBuf mb; |
| 55 | Bu::Formatter f( mb ); | 57 | Bu::Formatter f( mb ); |
| @@ -61,12 +63,14 @@ Bu::String Bu::Uuid::toString() const | |||
| 61 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; | 63 | f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | return mb.getString(); | 66 | return mb.getBlob(); |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | Bu::String Bu::Uuid::toUrn() const | 69 | Bu::Blob Bu::Uuid::toUrn() const |
| 68 | { | 70 | { |
| 69 | return "urn:uuid:" + toString(); | 71 | BlobBuilder bb("urn:uuid:"); |
| 72 | bb.append( toBlob() ); | ||
| 73 | return bb.getBlob(); | ||
| 70 | } | 74 | } |
| 71 | 75 | ||
| 72 | int Bu::Uuid::getVersion() | 76 | int Bu::Uuid::getVersion() |
| @@ -129,9 +133,9 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) | |||
| 129 | return id; | 133 | return id; |
| 130 | } | 134 | } |
| 131 | 135 | ||
| 132 | void Bu::Uuid::set( const Bu::String &sSrc ) | 136 | void Bu::Uuid::set( const Bu::Blob &sSrc ) |
| 133 | { | 137 | { |
| 134 | const char *dat = sSrc.getStr(); | 138 | const char *dat = sSrc.getData(); |
| 135 | int iNibble = 0; | 139 | int iNibble = 0; |
| 136 | memset( data, 0, 16 ); | 140 | memset( data, 0, 16 ); |
| 137 | for( int j = 0; j < 36; j++ ) | 141 | for( int j = 0; j < 36; j++ ) |
| @@ -162,7 +166,7 @@ Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs ) | |||
| 162 | 166 | ||
| 163 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) | 167 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) |
| 164 | { | 168 | { |
| 165 | return __calcHashCode<String>( k.toRawString() ); | 169 | return __calcHashCode<Blob>( k.toRawBlob() ); |
| 166 | } | 170 | } |
| 167 | 171 | ||
| 168 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) | 172 | template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) |
| @@ -172,18 +176,20 @@ template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid & | |||
| 172 | 176 | ||
| 173 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) | 177 | Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) |
| 174 | { | 178 | { |
| 175 | ar.read( u.data, 16 ); | 179 | Bu::Blob b; |
| 180 | ar >> b; | ||
| 181 | memcpy( b.getData(), u.data, 16 ); | ||
| 176 | return ar; | 182 | return ar; |
| 177 | } | 183 | } |
| 178 | 184 | ||
| 179 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) | 185 | Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) |
| 180 | { | 186 | { |
| 181 | ar.write( u.data, 16 ); | 187 | ar << u.toRawBlob(); |
| 182 | return ar; | 188 | return ar; |
| 183 | } | 189 | } |
| 184 | 190 | ||
| 185 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) | 191 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) |
| 186 | { | 192 | { |
| 187 | return f << u.toString(); | 193 | return f << u.toBlob(); |
| 188 | } | 194 | } |
| 189 | 195 | ||
diff --git a/src/unstable/uuid.h b/src/unstable/uuid.h index d61a928..902942e 100644 --- a/src/unstable/uuid.h +++ b/src/unstable/uuid.h | |||
| @@ -9,10 +9,11 @@ | |||
| 9 | #define BU_UUID_H | 9 | #define BU_UUID_H |
| 10 | 10 | ||
| 11 | #include "bu/util.h" | 11 | #include "bu/util.h" |
| 12 | #include "bu/string.h" | 12 | #include "bu/blob.h" |
| 13 | 13 | ||
| 14 | namespace Bu | 14 | namespace Bu |
| 15 | { | 15 | { |
| 16 | class Archive; | ||
| 16 | class Uuid | 17 | class Uuid |
| 17 | { | 18 | { |
| 18 | friend Bu::Archive &operator>>( Bu::Archive &ar, Uuid &u ); | 19 | friend Bu::Archive &operator>>( Bu::Archive &ar, Uuid &u ); |
| @@ -20,12 +21,12 @@ namespace Bu | |||
| 20 | public: | 21 | public: |
| 21 | Uuid(); | 22 | Uuid(); |
| 22 | Uuid( const Uuid &src ); | 23 | Uuid( const Uuid &src ); |
| 23 | Uuid( const Bu::String &sSrc ); | 24 | Uuid( const Bu::Blob &sSrc ); |
| 24 | virtual ~Uuid(); | 25 | virtual ~Uuid(); |
| 25 | 26 | ||
| 26 | Bu::String toRawString() const; | 27 | Bu::Blob toRawBlob() const; |
| 27 | Bu::String toString() const; | 28 | Bu::Blob toBlob() const; |
| 28 | Bu::String toUrn() const; | 29 | Bu::Blob toUrn() const; |
| 29 | 30 | ||
| 30 | enum Type | 31 | enum Type |
| 31 | { | 32 | { |
| @@ -43,11 +44,11 @@ namespace Bu | |||
| 43 | DEPRECATED static Uuid gen() { return generate(); } | 44 | DEPRECATED static Uuid gen() { return generate(); } |
| 44 | 45 | ||
| 45 | void clear(); | 46 | void clear(); |
| 46 | void set( const Bu::String &sSrc ); | 47 | void set( const Bu::Blob &sSrc ); |
| 47 | 48 | ||
| 48 | bool operator==( const Uuid &rhs ) const; | 49 | bool operator==( const Uuid &rhs ) const; |
| 49 | bool operator!=( const Uuid &rhs ) const; | 50 | bool operator!=( const Uuid &rhs ) const; |
| 50 | Uuid &operator=( const Bu::String &rhs ) { set( rhs ); return *this; } | 51 | Uuid &operator=( const Bu::Blob &rhs ) { set( rhs ); return *this; } |
| 51 | Uuid &operator=( const Uuid &rhs ); | 52 | Uuid &operator=( const Uuid &rhs ); |
| 52 | 53 | ||
| 53 | private: | 54 | private: |
