Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for 'float' and 'double' column types and a lot of other fixes #2

Merged
merged 1 commit into from
Feb 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/tightdb/objc/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import <Foundation/Foundation.h>

@class Table;
@class BinaryData;
@class OCMixed;

#pragma mark - CursorBase
Expand All @@ -39,14 +40,21 @@
accessors. */
@interface OCAccessor : NSObject
-(id)initWithCursor:(CursorBase *)cursor columnId:(size_t)columnId;
-(int64_t)getInt;
-(void)setInt:(int64_t)value;
-(BOOL)getBool;
-(void)setBool:(BOOL)value;
-(time_t)getDate;
-(void)setDate:(time_t)value;
-(int64_t)getInt;
-(void)setInt:(int64_t)value;
-(float)getFloat;
-(void)setFloat:(float)value;
-(double)getDouble;
-(void)setDouble:(double)value;
-(NSString *)getString;
-(void)setString:(NSString *)value;
-(BinaryData *)getBinary;
-(void)setBinary:(BinaryData *)value;
-(void)setBinary:(const char *)data size:(size_t)size;
-(time_t)getDate;
-(void)setDate:(time_t)value;
-(id)getSubtable:(Class)obj;
-(OCMixed *)getMixed;
-(void)setMixed:(OCMixed *)value;
Expand Down
52 changes: 44 additions & 8 deletions src/tightdb/objc/cursor_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ -(id)initWithCursor:(CursorBase *)cursor columnId:(size_t)columnId
}


-(BOOL)getBool
{
return [_cursor.table getBool:_columnId ndx:_cursor.ndx];
}
-(void)setBool:(BOOL)value
{
[_cursor.table setBool:_columnId ndx:_cursor.ndx value:value];
}

-(int64_t)getInt
{
return [_cursor.table get:_columnId ndx:_cursor.ndx];
Expand All @@ -67,22 +76,25 @@ -(void)setInt:(int64_t)value
{
[_cursor.table set:_columnId ndx:_cursor.ndx value:value];
}
-(BOOL)getBool

-(float)getFloat
{
return [_cursor.table getBool:_columnId ndx:_cursor.ndx];
return [_cursor.table getFloat:_columnId ndx:_cursor.ndx];
}
-(void)setBool:(BOOL)value
-(void)setFloat:(float)value
{
[_cursor.table setBool:_columnId ndx:_cursor.ndx value:value];
[_cursor.table setFloat:_columnId ndx:_cursor.ndx value:value];
}
-(time_t)getDate

-(double)getDouble
{
return [_cursor.table getDate:_columnId ndx:_cursor.ndx];
return [_cursor.table getDouble:_columnId ndx:_cursor.ndx];
}
-(void)setDate:(time_t)value
-(void)setDouble:(double)value
{
[_cursor.table setDate:_columnId ndx:_cursor.ndx value:value];
[_cursor.table setDouble:_columnId ndx:_cursor.ndx value:value];
}

-(NSString *)getString
{
return [_cursor.table getString:_columnId ndx:_cursor.ndx];
Expand All @@ -91,10 +103,34 @@ -(void)setString:(NSString *)value
{
[_cursor.table setString:_columnId ndx:_cursor.ndx value:value];
}

-(BinaryData *)getBinary
{
return [_cursor.table getBinary:_columnId ndx:_cursor.ndx];
}
-(void)setBinary:(BinaryData *)value
{
[_cursor.table setBinary:_columnId ndx:_cursor.ndx value:value];
}
-(void)setBinary:(const char *)data size:(size_t)size
{
[_cursor.table setBinary:_columnId ndx:_cursor.ndx data:data size:size];
}

-(time_t)getDate
{
return [_cursor.table getDate:_columnId ndx:_cursor.ndx];
}
-(void)setDate:(time_t)value
{
[_cursor.table setDate:_columnId ndx:_cursor.ndx value:value];
}

-(id)getSubtable:(Class)obj
{
return [_cursor.table getSubtable:_columnId ndx:_cursor.ndx withClass:obj];
}

-(OCMixed *)getMixed
{
return [_cursor.table getMixed:_columnId ndx:_cursor.ndx];
Expand Down
2 changes: 2 additions & 0 deletions src/tightdb/objc/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
typedef enum {
tightdb_Bool = 1,
tightdb_Int = 0,
tightdb_Float = 9,
tightdb_Double = 10,
tightdb_String = 2,
tightdb_Binary = 4,
tightdb_Date = 7,
Expand Down
4 changes: 2 additions & 2 deletions src/tightdb/objc/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@interface Group : NSObject
+(Group *)groupWithFilename:(NSString *)filename;
+(Group *)groupWithBuffer:(char*)buffer len:(size_t)len;
+(Group *)groupWithBuffer:(const char*)data size:(size_t)size;
+(Group *)group;

-(size_t)getTableCount;
Expand Down Expand Up @@ -55,7 +55,7 @@

// Serialization
-(void)write:(NSString *)filePath;
-(char*)writeToMem:(size_t*)len;
-(const char*)writeToMem:(size_t*)size;

// Conversion
// FIXME: Do we want to conversion methods? Maybe use NSData.
Expand Down
8 changes: 4 additions & 4 deletions src/tightdb/objc/group_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ +(Group *)groupWithFilename:(NSString *)filename
return group2;
}

+(Group *)groupWithBuffer:(char *)buffer len:(size_t)len
+(Group *)groupWithBuffer:(const char *)data size:(size_t)size
{
tightdb::Group* group;
try {
group = new tightdb::Group(tightdb::Group::BufferSpec(buffer, len));
group = new tightdb::Group(tightdb::Group::BufferSpec(data, size));
}
catch (...) {
// FIXME: Diffrent exception types mean different things. More
Expand Down Expand Up @@ -111,10 +111,10 @@ -(void)write:(NSString *)filePath
{
_group->write([filePath UTF8String]); // FIXME: May throw at least tightdb::File::OpenError (and various derivatives), tightdb::ResourceAllocError, and std::bad_alloc
}
-(char*)writeToMem:(size_t*)len
-(const char*)writeToMem:(size_t*)size
{
tightdb::Group::BufferSpec buffer = _group->write_to_mem(); // FIXME: May throw at least std::bad_alloc
*len = buffer.m_size;
*size = buffer.m_size;
return buffer.m_data;
}

Expand Down
Loading