PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/Foundation/CPFunctionOperation.j

http://github.com/cacaodev/cappuccino
Unknown | 88 lines | 77 code | 11 blank | 0 comment | 0 complexity | d5f84fc1cb0b8b738867edfea16021d0 MD5 | raw file
 1/*
 2 * CPFunctionOperation.j
 3 *
 4 * Created by Johannes Fahrenkrug.
 5 * Copyright 2009, Springenwerk.
 6 *
 7 * This library is free software; you can redistribute it and/or
 8 * modify it under the terms of the GNU Lesser General Public
 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22@import "CPArray.j"
23@import "CPObject.j"
24@import "CPOperation.j"
25
26/*!
27    @class CPFunctionOperation
28    @brief Represents an operation using a JavaScript function that can be run in an CPOperationQueue
29*/
30@implementation CPFunctionOperation : CPOperation
31{
32    CPArray _functions;
33}
34
35- (void)main
36{
37    if (_functions && [_functions count] > 0)
38    {
39        var i = 0,
40            count = [_functions count];
41
42        for (; i < count; i++)
43        {
44            var func = [_functions objectAtIndex:i];
45            func();
46        }
47    }
48}
49
50- (id)init
51{
52    self = [super init];
53
54    if (self)
55    {
56        _functions = [];
57    }
58    return self;
59}
60
61/*!
62    Adds the specified JS function to the receiver’s list of functions to perform.
63*/
64- (void)addExecutionFunction:(JSObject)jsFunction
65{
66    [_functions addObject:jsFunction];
67}
68
69/*!
70    Returns an array containing the functions associated with the receiver.
71*/
72- (CPArray)executionFunctions
73{
74    return _functions;
75}
76
77/*!
78    Creates and returns an CPFunctionOperation object and adds the specified function to it.
79*/
80+ (id)functionOperationWithFunction:(JSObject)jsFunction
81{
82    functionOp = [[CPFunctionOperation alloc] init];
83    [functionOp addExecutionFunction:jsFunction];
84
85    return functionOp;
86}
87
88@end