diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nde/osx/IndexField.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/nde/osx/IndexField.cpp')
-rw-r--r-- | Src/nde/osx/IndexField.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/Src/nde/osx/IndexField.cpp b/Src/nde/osx/IndexField.cpp new file mode 100644 index 00000000..77d39664 --- /dev/null +++ b/Src/nde/osx/IndexField.cpp @@ -0,0 +1,126 @@ +/* --------------------------------------------------------------------------- +Nullsoft Database Engine +-------------------- +codename: Near Death Experience +--------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------- + +IndexField Class + +--------------------------------------------------------------------------- */ + +#include "nde.h" + +//--------------------------------------------------------------------------- +IndexField::IndexField(unsigned char id, int Pos, int type, CFStringRef FieldName) +{ + InitField(); + Type = FIELD_INDEX; + Name = (CFStringRef)CFRetain(FieldName); + ID = id; + Position = Pos; + DataType = type; +} + +//--------------------------------------------------------------------------- +void IndexField::InitField(void) +{ + index = 0; + Type = FIELD_INDEX; + Name = NULL; + ID = 0; + Position = -1; + DataType = FIELD_UNKNOWN; +} + +//--------------------------------------------------------------------------- +IndexField::IndexField() +{ + InitField(); +} + +//--------------------------------------------------------------------------- +IndexField::~IndexField() +{ + if (Name) + CFRelease(Name); + delete index; +} + +//--------------------------------------------------------------------------- +void IndexField::ReadTypedData(const uint8_t *data, size_t len) +{ + unsigned char c; + int pos=0; + CHECK_INT(len); + Position = GET_INT(); pos += 4; + CHECK_INT(len); + DataType = GET_INT(); pos += 4; + CHECK_CHAR(len); + c = GET_CHAR(); pos++; + if (c) + { + CHECK_BIN(len, c); + if (Name) + CFRelease(Name); + Name = CFStringCreateWithBytes(kCFAllocatorDefault, data+pos, c, kCFStringEncodingUTF8, false); + } +} + +//--------------------------------------------------------------------------- +void IndexField::WriteTypedData(uint8_t *data, size_t len) +{ + int pos=0; + CHECK_INT(len); + PUT_INT(Position); pos += 4; + + CHECK_INT(len); + PUT_INT(DataType); pos += 4; + CHECK_CHAR(len); + + if (Name) + { + CFIndex lengthRequired=0; + CFStringGetBytes(Name, CFRangeMake(0, CFStringGetLength(Name)), kCFStringEncodingUTF8, 0, false, NULL, 0, &lengthRequired); + CHECK_BIN(len, lengthRequired+1); + PUT_CHAR(lengthRequired); pos++; + + CFStringGetBytes(Name, CFRangeMake(0, CFStringGetLength(Name)), kCFStringEncodingUTF8, 0, false, data+pos, lengthRequired, 0); + } +} + +//--------------------------------------------------------------------------- +CFStringRef IndexField::GetIndexName(void) +{ + return Name; +} + +//--------------------------------------------------------------------------- +size_t IndexField::GetDataSize(void) +{ + if (Name) + { + CFIndex lengthRequired=0; + CFStringGetBytes(Name, CFRangeMake(0, CFStringGetLength(Name)), kCFStringEncodingUTF8, 0, false, NULL, 0, &lengthRequired); + return lengthRequired+9; + } + else + return 9; +} + +//--------------------------------------------------------------------------- +int IndexField::Compare(Field * /*Entry*/) +{ + return 0; +} + +//--------------------------------------------------------------------------- +int IndexField::TranslateToIndex(int Id, IndexField *toindex) +{ + if (index && toindex && toindex->index) + return index->TranslateIndex(Id, toindex->index); + return -1; +} + + |