<commit_before>//
//  group.m
//  TightDB
//

#import <tightdb/group.hpp>
#import <tightdb/lang_bind_helper.hpp>

#import <tightdb/objc/group.h>
#import <tightdb/objc/table.h>
#import <tightdb/objc/table_priv.h>


@interface Group()
@property(nonatomic) tightdb::Group *group;
@property(nonatomic) BOOL readOnly;
@end
@implementation Group
@synthesize group = _group;
@synthesize readOnly = _readOnly;

+(Group *)group
{
    Group *group = [[Group alloc] init];
    group.group = new tightdb::Group(); // FIXME: Both new-operator and Group constructor may throw at least std::bad_alloc.
    group.readOnly = NO;
    return group;
}

// Careful with this one - Remember that group will be deleted on dealloc.
+(Group *)groupTightdbGroup:(tightdb::Group *)tightdbGroup readOnly:(BOOL)readOnly
{
    Group *group = [[Group alloc] init];
    group.group = tightdbGroup;
    group.readOnly = readOnly;
    return group;
}

+(Group *)groupWithFilename:(NSString *)filename
{
    tightdb::Group* group;
    try {
        group = new tightdb::Group([filename UTF8String]);
    }
    catch (...) {
        // FIXME: Diffrent exception types mean different things. More
        // details must be made available. We should proably have
        // special catches for at least these:
        // tightdb::File::OpenError (and various derivatives),
        // tightdb::ResourceAllocError, std::bad_alloc. In general,
        // any core library function or operator that is not declared
        // 'noexcept' must be considered as being able to throw
        // anything derived from std::exception.
        return nil;
    }
    Group* group2 = [[Group alloc] init];
    if (group2) {
      group2.group = group;
      group2.readOnly = NO;
    }
    return group2;
}

+(Group *)groupWithBuffer:(const char *)data size:(size_t)size
{
    tightdb::Group* group;
    try {
        group = new tightdb::Group(tightdb::Group::BufferSpec(data, size));
    }
    catch (...) {
        // FIXME: Diffrent exception types mean different things. More
        // details must be made available. We should proably have
        // special catches for at least these:
        // tightdb::File::OpenError (and various derivatives),
        // tightdb::ResourceAllocError, std::bad_alloc. In general,
        // any core library function or operator that is not declared
        // 'noexcept' must be considered as being able to throw
        // anything derived from std::exception.
        return nil;
    }
    Group* group2 = [[Group alloc] init];
    group2.group = group;
    group2.readOnly = NO;
    return group2;
}

-(void)clearGroup
{
    _group = 0;
}

-(void)dealloc
{
#ifdef TIGHTDB_DEBUG
    NSLog(@"Group dealloc");
#endif
    delete _group;
}


-(size_t)getTableCount
{
    return _group->get_table_count();
}
-(NSString *)getTableName:(size_t)table_ndx
{
    return [NSString stringWithUTF8String:_group->get_table_name(table_ndx)];
}<commit_msg>Fix due to core lib change: Group::get_table_count() -> Group::size()<commit_after>//
//  group.m
//  TightDB
//

#import <tightdb/group.hpp>
#import <tightdb/lang_bind_helper.hpp>

#import <tightdb/objc/group.h>
#import <tightdb/objc/table.h>
#import <tightdb/objc/table_priv.h>


@interface Group()
@property(nonatomic) tightdb::Group *group;
@property(nonatomic) BOOL readOnly;
@end
@implementation Group
@synthesize group = _group;
@synthesize readOnly = _readOnly;

+(Group *)group
{
    Group *group = [[Group alloc] init];
    group.group = new tightdb::Group(); // FIXME: Both new-operator and Group constructor may throw at least std::bad_alloc.
    group.readOnly = NO;
    return group;
}

// Careful with this one - Remember that group will be deleted on dealloc.
+(Group *)groupTightdbGroup:(tightdb::Group *)tightdbGroup readOnly:(BOOL)readOnly
{
    Group *group = [[Group alloc] init];
    group.group = tightdbGroup;
    group.readOnly = readOnly;
    return group;
}

+(Group *)groupWithFilename:(NSString *)filename
{
    tightdb::Group* group;
    try {
        group = new tightdb::Group([filename UTF8String]);
    }
    catch (...) {
        // FIXME: Diffrent exception types mean different things. More
        // details must be made available. We should proably have
        // special catches for at least these:
        // tightdb::File::OpenError (and various derivatives),
        // tightdb::ResourceAllocError, std::bad_alloc. In general,
        // any core library function or operator that is not declared
        // 'noexcept' must be considered as being able to throw
        // anything derived from std::exception.
        return nil;
    }
    Group* group2 = [[Group alloc] init];
    if (group2) {
      group2.group = group;
      group2.readOnly = NO;
    }
    return group2;
}

+(Group *)groupWithBuffer:(const char *)data size:(size_t)size
{
    tightdb::Group* group;
    try {
        group = new tightdb::Group(tightdb::Group::BufferSpec(data, size));
    }
    catch (...) {
        // FIXME: Diffrent exception types mean different things. More
        // details must be made available. We should proably have
        // special catches for at least these:
        // tightdb::File::OpenError (and various derivatives),
        // tightdb::ResourceAllocError, std::bad_alloc. In general,
        // any core library function or operator that is not declared
        // 'noexcept' must be considered as being able to throw
        // anything derived from std::exception.
        return nil;
    }
    Group* group2 = [[Group alloc] init];
    group2.group = group;
    group2.readOnly = NO;
    return group2;
}

-(void)clearGroup
{
    _group = 0;
}

-(void)dealloc
{
#ifdef TIGHTDB_DEBUG
    NSLog(@"Group dealloc");
#endif
    delete _group;
}


-(size_t)getTableCount
{
    return _group->size();
}
-(NSString *)getTableName:(size_t)table_ndx
{
    return [NSString stringWithUTF8String:_group->get_table_name(table_ndx)];
}
{'fraction_non_alphanumeric': 0.12214901165737456, 'fraction_numerical': 0.0040547389761784085, 'mean_word_length': 3.0437158469945356, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2244686', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1766, 'n_words': 529}