/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. @import "CPArray.j"
  22. @import "CPObject.j"
  23. @import "CPOperation.j"
  24. /*!
  25. @class CPFunctionOperation
  26. @brief Represents an operation using a JavaScript function that can be run in an CPOperationQueue
  27. */
  28. @implementation CPFunctionOperation : CPOperation
  29. {
  30. CPArray _functions;
  31. }
  32. - (void)main
  33. {
  34. if (_functions && [_functions count] > 0)
  35. {
  36. var i = 0,
  37. count = [_functions count];
  38. for (; i < count; i++)
  39. {
  40. var func = [_functions objectAtIndex:i];
  41. func();
  42. }
  43. }
  44. }
  45. - (id)init
  46. {
  47. self = [super init];
  48. if (self)
  49. {
  50. _functions = [];
  51. }
  52. return self;
  53. }
  54. /*!
  55. Adds the specified JS function to the receiver’s list of functions to perform.
  56. */
  57. - (void)addExecutionFunction:(JSObject)jsFunction
  58. {
  59. [_functions addObject:jsFunction];
  60. }
  61. /*!
  62. Returns an array containing the functions associated with the receiver.
  63. */
  64. - (CPArray)executionFunctions
  65. {
  66. return _functions;
  67. }
  68. /*!
  69. Creates and returns an CPFunctionOperation object and adds the specified function to it.
  70. */
  71. + (id)functionOperationWithFunction:(JSObject)jsFunction
  72. {
  73. functionOp = [[CPFunctionOperation alloc] init];
  74. [functionOp addExecutionFunction:jsFunction];
  75. return functionOp;
  76. }
  77. @end