<commit_before>//
//  SynthesizeSingleton.h
//  Copyright (c) 2009 <NAME>. All rights reserved.
//
//  Modified by <NAME> and <NAME>.
//
//  Permission is given to use this source code file without charge in any
//  project, commercial or otherwise, entirely at your risk, with the condition
//  that any redistribution (in part or whole) of source code must retain
//  this copyright and permission notice. Attribution in compiled projects is
//  appreciated but not required.
//
//  See:
//    - http://pixelchild.com.au/post/17936761797/objective-c-singleton-macro-that-supports-both-arc
//

#ifndef NITRO_SYNTHESIZE_SINGLETON_H
#define NITRO_SYNTHESIZE_SINGLETON_H

// To use in header files
#define DECLARE_SINGLETON_FOR_CLASS( className, accessorname ) +( className * )accessorname;
#define DEFAULT_DECLARE_SINGLETON_FOR_CLASS( className ) DECLARE_SINGLETON_FOR_CLASS( className, sharedInstance )

// To use in implementation files
#if __has_feature( objc_arc )

#define SYNTHESIZE_SINGLETON_FOR_CLASS( classname, accessorname )           \
                                                                            \
+( classname * )accessorname                                                \
{                                                                           \
    static classname *accessorname = nil;                                   \
    static dispatch_once_t onceToken;                                       \
                                                                            \
    dispatch_once( &onceToken, ^{                                           \
        accessorname = [[classname alloc] init];                            \
    });                                                                     \
                                                                            \
    return accessorname;                                                    \
}

#else

#define SYNTHESIZE_SINGLETON_FOR_CLASS( classname, accessorname )           \
                                                                            \
    static classname *shared##classname = nil;                              \
                                                                            \
    +( void )cleanupFromTerminate                                           \
    {                                                                       \
        classname *temp = shared##classname;                                \
        shared##classname = nil;                                            \
        [temp dealloc];                                                     \
    }                                                                       \
                                                                            \
    +( void )registerForCleanup                                             \
    {                                                                       \
        [[NSNotificationCenter defaultCenter] addObserver: self             \
        selector: @selector( cleanupFromTerminate )                         \
        name: UIApplicationWillTerminateNotification                        \
        object: nil];                                                       \
    }                                                                       \
                                                                            \
    +( classname * )accessorname                                            \
    {                                                                       \
        static dispatch_once_t p;                                           \
        dispatch_once( &p,                                                  \
        ^{                                                                  \
            if( shared##classname == nil )                                  \
            {                                                               \
                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
                shared##classname = [[self alloc] init];                    \
                [self registerForCleanup];                                  \
                [pool drain];                                               \
            }                                                               \
        });                                                                 \
        return shared##classname;                                           \
    }                                                                       \
                                                                            \
    +( id )allocWithZone:( NSZone * )zone                                   \
    {                                                                       \
        static dispatch_once_t p;                                           \
        __block classname *temp = nil;                                      \
                                                                            \
        dispatch_once( &p,                                                  \
        ^{                                                                  \
            if( shared##classname == nil )                                  \
            {                                                               \
                temp = shared##classname = [super allocWithZone: zone];     \
            }                                                               \
        });                                                                 \
        return temp;                                                        \
    }                                                                       \
                                                                            \
    -( id )copyWithZone:( NSZone * )zone { return self; }                   \
    -( id )retain { return self; }                                          \
    -( NSUInteger )retainCount { return NSUIntegerMax; }                    \
    -( oneway void )release { }                                             \
    -( id )autorelease { return self; }

#endif<commit_msg>Removing non-arc implementation Fixing arc implementation<commit_after>//
//  SynthesizeSingleton.h
//  Copyright (c) 2009 <NAME>. All rights reserved.
//
//  Modified by <NAME> and <NAME>.
//
//  Permission is given to use this source code file without charge in any
//  project, commercial or otherwise, entirely at your risk, with the condition
//  that any redistribution (in part or whole) of source code must retain
//  this copyright and permission notice. Attribution in compiled projects is
//  appreciated but not required.
//
//  See:
//    - http://www.cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html
//

#ifndef NITRO_SYNTHESIZE_SINGLETON_H
#define NITRO_SYNTHESIZE_SINGLETON_H

#import <UIKit/UIKit.h>

// To use in header files
#define DECLARE_SINGLETON_FOR_CLASS( className, accessorname ) +( className * )accessorname;
#define DEFAULT_DECLARE_SINGLETON_FOR_CLASS( className ) DECLARE_SINGLETON_FOR_CLASS( className, sharedInstance )

// To use in implementation files
#define SYNTHESIZE_SINGLETON_FOR_CLASS( classname, accessorname )                                   \
                                                                                                    \
static classname *shared##classname = nil;                                                          \
                                                                                                    \
+( void )cleanupFromTerminate                                                                       \
{                                                                                                   \
    shared##classname = nil;                                                                        \
}                                                                                                   \
                                                                                                    \
+( void )registerForCleanup                                                                         \
{                                                                                                   \
NSLog( @">>>>>>>>> Class %s registered for cleanup", #classname );\
    [[NSNotificationCenter defaultCenter] addObserver: self                                         \
                                          selector: @selector( cleanupFromTerminate )               \
                                          name: UIApplicationWillTerminateNotification              \
                                          object: nil];                                             \
}                                                                                                   \
                                                                                                    \
-( void )dealloc                                                                                    \
{                                                                                                   \
    [[NSNotificationCenter defaultCenter] removeObserver: self                                      \
                                                    name: UIApplicationWillTerminateNotification    \
                                                  object: nil];                                     \
}                                                                                                   \
                                                                                                    \
+( classname * )accessorname                                                                        \
{                                                                                                   \
    __block classname *temp;                                                                        \
    temp = shared##classname;                                                                       \
    if( !temp )                                                                                     \
    {                                                                                               \
        static dispatch_once_t p;                                                                   \
        dispatch_once( &p, ^{                                                                       \
            shared##classname = [[self alloc] init];                                                \
            temp = shared##classname;                                                               \
        });                                                                                         \
    }                                                                                               \
    return temp;                                                                                    \
}                                                                                                   \
                                                                                                    \
+( id )allocWithZone:( NSZone * )zone                                                               \
{                                                                                                   \
    static dispatch_once_t p;                                                                       \
                                                                                                    \
    dispatch_once( &p, ^{                                                                           \
        if( shared##classname == nil )                                                              \
        {                                                                                           \
            shared##classname = [super allocWithZone: zone];                                        \
            [self registerForCleanup];                                                              \
        }                                                                                           \
    });                                                                                             \
    return shared##classname;                                                                       \
}                                                                                                   \
                                                                                                    \
-( id )copyWithZone:( NSZone * )zone                                                                \
{                                                                                                   \
    return self;                                                                                    \
}
{'fraction_non_alphanumeric': 0.050566561319663916, 'fraction_numerical': 0.001927079318584753, 'mean_word_length': 0.4105240269623831, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 300, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4659347', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1681, 'n_words': 405}