Skip to content

Commit

Permalink
Merge pull request #1 from Tightdb/column_type_rename
Browse files Browse the repository at this point in the history
Column type rename
  • Loading branch information
kspangsege committed Feb 13, 2013
2 parents 84e1ac2 + d0b91b0 commit 2f389a3
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/tightdb/objc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TIGHTDB_H = tightdb.h

GENERATED_SOURCES = $(TIGHTDB_H)

INST_HEADERS = column_type.h cursor.h group.h query.h table.h group_shared.h helper_macros.h $(TIGHTDB_H)
INST_HEADERS = data_type.h cursor.h group.h query.h table.h group_shared.h helper_macros.h $(TIGHTDB_H)

lib_LIBRARIES = libtightdb-objc.a

Expand Down
44 changes: 0 additions & 44 deletions src/tightdb/objc/column_type.h

This file was deleted.

34 changes: 34 additions & 0 deletions src/tightdb/objc/data_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*************************************************************************
*
* TIGHTDB CONFIDENTIAL
* __________________
*
* [2011] - [2012] TightDB Inc
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of TightDB Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to TightDB Incorporated
* and its suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from TightDB Incorporated.
*
**************************************************************************/
#ifndef TIGHTDB_OBJC_DATA_TYPE_H
#define TIGHTDB_OBJC_DATA_TYPE_H

// Make sure numbers match those in <tightdb/data_type.hpp>
typedef enum {
tightdb_Bool = 1,
tightdb_Int = 0,
tightdb_String = 2,
tightdb_Binary = 4,
tightdb_Date = 7,
tightdb_Table = 5,
tightdb_Mixed = 6,
} TightdbDataType;

#endif // TIGHTDB_OBJC_DATA_TYPE_H
14 changes: 7 additions & 7 deletions src/tightdb/objc/helper_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
#define TIGHTDB_TYPE_Date OCDate *
#define TIGHTDB_TYPE_Mixed OCMixed *

#define TIGHTDB_TYPE_ID_Bool TIGHTDB_COLUMN_TYPE_BOOL
#define TIGHTDB_TYPE_ID_Int TIGHTDB_COLUMN_TYPE_INT
#define TIGHTDB_TYPE_ID_String TIGHTDB_COLUMN_TYPE_STRING
#define TIGHTDB_TYPE_ID_Binary TIGHTDB_COLUMN_TYPE_BINARY
#define TIGHTDB_TYPE_ID_Date TIGHTDB_COLUMN_TYPE_DATE
#define TIGHTDB_TYPE_ID_Mixed TIGHTDB_COLUMN_TYPE_MIXED
#define TIGHTDB_TYPE_ID_Bool tightdb_Bool
#define TIGHTDB_TYPE_ID_Int tightdb_Int
#define TIGHTDB_TYPE_ID_String tightdb_String
#define TIGHTDB_TYPE_ID_Binary tightdb_Binary
#define TIGHTDB_TYPE_ID_Date tightdb_Date
#define TIGHTDB_TYPE_ID_Mixed tightdb_Mixed



Expand Down Expand Up @@ -79,7 +79,7 @@
#define TIGHTDB_CHECK_COLUMN_TYPE_3(is_subtable, spec, col, name, type) TIGHTDB_CHECK_COLUMN_TYPE_4_##is_subtable(spec, col, name, type)
#define TIGHTDB_CHECK_COLUMN_TYPE_4_Y(spec, col, name, type) \
{ \
if ([spec getColumnType:col] != TIGHTDB_COLUMN_TYPE_TABLE) return NO; \
if ([spec getColumnType:col] != tightdb_Table) return NO; \
if (![[spec getColumnName:col] isEqualToString:@#name]) return NO; \
OCSpec *subspec = [spec getSpec:col]; \
if (!subspec) return NO; \
Expand Down
14 changes: 7 additions & 7 deletions src/tightdb/objc/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#import <Foundation/Foundation.h>

#include <tightdb/objc/column_type.h>
#include <tightdb/objc/data_type.h>

@class Table;
@class TableView;
Expand Down Expand Up @@ -49,7 +49,7 @@
+(OCMixed *)mixedWithDate:(OCDate *)date;
+(OCMixed *)mixedWithTable:(Table *)table;
-(BOOL)isEqual:(OCMixed *)other;
-(TightdbColumnType)getType;
-(TightdbDataType)getType;
-(int64_t)getInt;
-(BOOL)getBool;
-(OCDate *)getDate;
Expand All @@ -61,12 +61,12 @@

@interface OCSpec : NSObject
/// Returns NO on memory allocation error.
-(BOOL)addColumn:(TightdbColumnType)type name:(NSString *)name;
-(BOOL)addColumn:(TightdbDataType)type name:(NSString *)name;
/// Returns nil on memory allocation error.
-(OCSpec *)addColumnTable:(NSString *)name;
-(OCSpec *)getSpec:(size_t)columnId;
-(size_t)getColumnCount;
-(TightdbColumnType)getColumnType:(size_t)ndx;
-(TightdbDataType)getColumnType:(size_t)ndx;
-(NSString *)getColumnName:(size_t)ndx;
-(size_t)getColumnIndex:(NSString *)name;
@end
Expand Down Expand Up @@ -110,7 +110,7 @@
-(size_t)getColumnCount;
-(NSString *)getColumnName:(size_t)ndx;
-(size_t)getColumnIndex:(NSString *)name;
-(TightdbColumnType)getColumnType:(size_t)ndx;
-(TightdbDataType)getColumnType:(size_t)ndx;
-(OCSpec *)getSpec;
-(BOOL)isEmpty;
-(size_t)count;
Expand Down Expand Up @@ -151,11 +151,11 @@

// Mixed
-(OCMixed *)getMixed:(size_t)columnId ndx:(size_t)ndx;
-(TightdbColumnType)getMixedType:(size_t)columnId ndx:(size_t)ndx;
-(TightdbDataType)getMixedType:(size_t)columnId ndx:(size_t)ndx;
-(void)insertMixed:(size_t)columnId ndx:(size_t)ndx value:(OCMixed *)value;
-(void)setMixed:(size_t)columnId ndx:(size_t)ndx value:(OCMixed *)value;

-(size_t)addColumn:(TightdbColumnType)type name:(NSString *)name;
-(size_t)addColumn:(TightdbDataType)type name:(NSString *)name;

// Searching
-(size_t)findBool:(size_t)columnId value:(BOOL)value;
Expand Down
50 changes: 25 additions & 25 deletions src/tightdb/objc/table_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,32 @@ +(OCMixed *)mixedWithBinary:(const char*)value length:(size_t)length

-(BOOL)isEqual:(OCMixed *)other
{
const tightdb::ColumnType type = _mixed.get_type();
const tightdb::DataType type = _mixed.get_type();
if (type != other->_mixed.get_type()) return NO;
switch (type) {
case tightdb::COLUMN_TYPE_BOOL:
case tightdb::type_Bool:
return _mixed.get_bool() == other->_mixed.get_bool();
case tightdb::COLUMN_TYPE_INT:
case tightdb::type_Int:
return _mixed.get_int() == other->_mixed.get_int();
case tightdb::COLUMN_TYPE_STRING:
case tightdb::type_String:
return std::strcmp(_mixed.get_string(), other->_mixed.get_string()) == 0;
case tightdb::COLUMN_TYPE_BINARY:
case tightdb::type_Binary:
return _mixed.get_binary().compare_payload(other->_mixed.get_binary());
case tightdb::COLUMN_TYPE_DATE:
case tightdb::type_Date:
return _mixed.get_date() == other->_mixed.get_date();
case tightdb::COLUMN_TYPE_TABLE:
case tightdb::type_Table:
return [_table getTable] == [other->_table getTable]; // Compare table contents
break;
default:
case tightdb::type_Mixed:
TIGHTDB_ASSERT(false);
break;
}
return NO;
}

-(TightdbColumnType)getType
-(TightdbDataType)getType
{
return (TightdbColumnType)_mixed.get_type();
return (TightdbDataType)_mixed.get_type();
}
-(int64_t)getInt
{
Expand Down Expand Up @@ -255,9 +255,9 @@ +(OCSpec *)specWithSpec:(tightdb::Spec *)other isOwned:(BOOL)isOwned

// FIXME: Provide a version of this method that takes a 'const char *'. This will simplify _addColumns of MyTable.
// FIXME: Detect errors from core library
-(BOOL)addColumn:(TightdbColumnType)type name:(NSString *)name
-(BOOL)addColumn:(TightdbDataType)type name:(NSString *)name
{
_spec->add_column((tightdb::ColumnType)type, [name UTF8String]);
_spec->add_column((tightdb::DataType)type, [name UTF8String]);
return YES;
}

Expand All @@ -279,9 +279,9 @@ -(size_t)getColumnCount
{
return _spec->get_column_count();
}
-(TightdbColumnType)getColumnType:(size_t)ndx
-(TightdbDataType)getColumnType:(size_t)ndx
{
return (TightdbColumnType)_spec->get_column_type(ndx);
return (TightdbDataType)_spec->get_column_type(ndx);
}
-(NSString *)getColumnName:(size_t)ndx
{
Expand Down Expand Up @@ -506,8 +506,8 @@ -(void)setReadOnly:(BOOL)readOnly

-(Table *)getSubtable:(size_t)columnId ndx:(size_t)ndx
{
const tightdb::ColumnType t = _table->get_column_type(columnId);
if (t != tightdb::COLUMN_TYPE_TABLE && t != tightdb::COLUMN_TYPE_MIXED) return nil;
const tightdb::DataType t = _table->get_column_type(columnId);
if (t != tightdb::type_Table && t != tightdb::type_Mixed) return nil;
tightdb::TableRef r = _table->get_subtable(columnId, ndx);
if (!r) return nil;
Table *table = [[Table alloc] _initRaw];
Expand All @@ -521,8 +521,8 @@ -(Table *)getSubtable:(size_t)columnId ndx:(size_t)ndx
// FIXME: Check that the specified class derives from Table.
-(id)getSubtable:(size_t)columnId ndx:(size_t)ndx withClass:(__unsafe_unretained Class)classObj
{
const tightdb::ColumnType t = _table->get_column_type(columnId);
if (t != tightdb::COLUMN_TYPE_TABLE && t != tightdb::COLUMN_TYPE_MIXED) return nil;
const tightdb::DataType t = _table->get_column_type(columnId);
if (t != tightdb::type_Table && t != tightdb::type_Mixed) return nil;
tightdb::TableRef r = _table->get_subtable(columnId, ndx);
if (!r) return nil;
Table *table = [[classObj alloc] _initRaw];
Expand Down Expand Up @@ -580,9 +580,9 @@ -(size_t)getColumnIndex:(NSString *)name
{
return _table->get_column_index([name UTF8String]);
}
-(TightdbColumnType)getColumnType:(size_t)ndx
-(TightdbDataType)getColumnType:(size_t)ndx
{
return (TightdbColumnType)_table->get_column_type(ndx);
return (TightdbDataType)_table->get_column_type(ndx);
}
-(OCSpec *)getSpec
{
Expand Down Expand Up @@ -739,15 +739,15 @@ -(OCMixed *)getMixed:(size_t)columnId ndx:(size_t)ndx
{
tightdb::Mixed tmp = _table->get_mixed(columnId, ndx);
OCMixed *mixed = [OCMixed mixedWithMixed:tmp];
if ([mixed getType] == TIGHTDB_COLUMN_TYPE_TABLE) {
if ([mixed getType] == tightdb_Table) {
[mixed setTable:[self getSubtable:columnId ndx:ndx]];
}
return mixed;
}

-(TightdbColumnType)getMixedType:(size_t)columnId ndx:(size_t)ndx
-(TightdbDataType)getMixedType:(size_t)columnId ndx:(size_t)ndx
{
return (TightdbColumnType)_table->get_mixed_type(columnId, ndx);
return (TightdbDataType)_table->get_mixed_type(columnId, ndx);
}

-(void)insertMixed:(size_t)columnId ndx:(size_t)ndx value:(OCMixed *)value
Expand All @@ -765,9 +765,9 @@ -(void)setMixed:(size_t)columnId ndx:(size_t)ndx value:(OCMixed *)value
// FIXME: Insert copy of subtable if type is table
}

-(size_t)addColumn:(TightdbColumnType)type name:(NSString *)name
-(size_t)addColumn:(TightdbDataType)type name:(NSString *)name
{
return _table->add_column((tightdb::ColumnType)type, [name UTF8String]);
return _table->add_column((tightdb::DataType)type, [name UTF8String]);
}
-(size_t)findBool:(size_t)columnId value:(BOOL)value
{
Expand Down
2 changes: 1 addition & 1 deletion src/tightdb/objc/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST_PROGRAMS = unit-tests

XCODE_HOME = $(shell xcode-select --print-path)

unit_tests_SOURCES = column_type.mm table.m group.m group_misc_2.m table_delete_all.m tutorial.m enumerator.m get_subtable.m subtable.m mixed.m shared_group.m
unit_tests_SOURCES = data_type.mm table.m group.m group_misc_2.m table_delete_all.m tutorial.m enumerator.m get_subtable.m subtable.m mixed.m shared_group.m
unit_tests_CFLAGS = -Wno-comment -fobjc-arc -fobjc-abi-version=2 -F$(XCODE_HOME)/Library/Frameworks
unit_tests_LDFLAGS = -bundle -fobjc-link-runtime -F$(XCODE_HOME)/Library/Frameworks -framework Cocoa -framework SenTestingKit
unit_tests_LIBS = ../libtightdb-objc.a
Expand Down
28 changes: 0 additions & 28 deletions src/tightdb/objc/test/column_type.mm

This file was deleted.

28 changes: 28 additions & 0 deletions src/tightdb/objc/test/data_type.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// data_type.mm
// TightDB
//
// Check that data type enumeration values are in synch with the core library
//

#import <SenTestingKit/SenTestingKit.h>

#import <tightdb/objc/data_type.h>
#import <tightdb/data_type.hpp>

@interface TestDataType : SenTestCase
@end
@implementation TestDataType

- (void)testDataType
{
STAssertEquals((int)tightdb_Bool, (int)tightdb::type_Bool, @"Bool");
STAssertEquals((int)tightdb_Int, (int)tightdb::type_Int, @"Int");
STAssertEquals((int)tightdb_String, (int)tightdb::type_String, @"String");
STAssertEquals((int)tightdb_Binary, (int)tightdb::type_Binary, @"Binary");
STAssertEquals((int)tightdb_Date, (int)tightdb::type_Date, @"Date");
STAssertEquals((int)tightdb_Table, (int)tightdb::type_Table, @"Table");
STAssertEquals((int)tightdb_Mixed, (int)tightdb::type_Mixed, @"Mixed");
}

@end
8 changes: 4 additions & 4 deletions src/tightdb/objc/test/get_subtable.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ - (void)testGetSubtable
// Create table with all column types
Table *table = [[Table alloc] init];
OCSpec *s = [table getSpec];
[s addColumn:TIGHTDB_COLUMN_TYPE_BOOL name:@"Outer"];
[s addColumn:TIGHTDB_COLUMN_TYPE_INT name:@"Number"];
[s addColumn:tightdb_Bool name:@"Outer"];
[s addColumn:tightdb_Int name:@"Number"];
OCSpec *sub = [s addColumnTable:@"GetSubtable"];
[sub addColumn:TIGHTDB_COLUMN_TYPE_BOOL name:@"Hired"];
[sub addColumn:TIGHTDB_COLUMN_TYPE_INT name:@"Age"];
[sub addColumn:tightdb_Bool name:@"Hired"];
[sub addColumn:tightdb_Int name:@"Age"];
[table updateFromSpec];

[table insertBool:0 ndx:0 value:NO];
Expand Down
Loading

0 comments on commit 2f389a3

Please sign in to comment.