File: poopseq_ext.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (137 lines) | stat: -rw-r--r-- 3,992 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
   FALCON - The Falcon Programming Language.
   FILE: poopcomp_ext.cpp

   Prototype oop oriented sequence interface.
   -------------------------------------------------------------------
   Author: Giancarlo Niccolai
   Begin: Mon, 10 Aug 2009 11:19:09 +0200

   -------------------------------------------------------------------
   (C) Copyright 2009: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

/*#
   @beginmodule core
*/

#include <falcon/setup.h>
#include <falcon/module.h>
#include <falcon/coreobject.h>
#include <falcon/coredict.h>
#include <falcon/poopseq.h>
#include <falcon/garbagepointer.h>
#include "core_module.h"

namespace Falcon {
namespace core {

/*#
   @method comp Object
   @brief Appends elements to this object through a filter.
   @param source One sequence, range or callable generating items.
   @optparam filter A filtering function receiving one item at a time.
   @return This object.

   This method extracts one item at a time from the source, and calls repeatedly the
   @b append method of this object.

   Please, see the description of @a Sequence.comp.
   @see Sequence.comp
*/

FALCON_FUNC  Object_comp ( ::Falcon::VMachine *vm )
{
   if ( vm->param(0) == 0 )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
         .extra( "R|A|C|Sequence, [C]" ) );
   }

   // Save the parameters as the stack may change greatly.
   CoreObject* obj = vm->self().asObject();

   Item i_gen = *vm->param(0);
   Item i_check = vm->param(1) == 0 ? Item(): *vm->param(1);

   PoopSeq* seq = new PoopSeq( vm, Item(obj) );  // may throw
   vm->pushParam( new GarbagePointer( seq ) );
   seq->comprehension_start( vm, vm->self(), i_check );
   vm->pushParam( i_gen );
}

/*#
   @method mcomp Object
   @brief Appends elements to this object through a filter.
   @param ... One or more sequences, ranges or callables generating items.
   @return This object.

   This method sends the data generated from multiple comprehension,
   to the append method of this object.

   Please, see the description of @a Sequence.comp.
   @see Sequence.mcomp
*/

FALCON_FUNC  Object_mcomp ( ::Falcon::VMachine *vm )
{
   // Save the parameters as the stack may change greatly.
   CoreObject* obj = vm->self().asObject();
   StackFrame* current = vm->currentFrame();

   PoopSeq* seq = new PoopSeq( vm, Item(obj) );  // may throw
   vm->pushParam( new GarbagePointer( seq ) );
   seq->comprehension_start( vm, vm->self(), Item() );

   for( uint32 i = 0; i < current->m_param_count; ++i )
   {
      vm->pushParam( current->m_params[i] );
   }
}


/*#
   @method mfcomp Object
   @brief Appends elements to this object through a filter.
   @param filter A filter function receiving each element before its insertion, or nil.
   @param ... One or more sequences, ranges or callables generating items.
   @return This object.

   This method performs a filtered multiple comprehension and and calls repeatedly the
   @b append method of this object, passing the output of the filter function
   to it each time. If the filter function returns an oob(1), the step is skipped
   and the @b append method is not called.

   Please, see the description of @a Sequence.comp.
   @see Sequence.mfcomp
*/
FALCON_FUNC  Object_mfcomp ( ::Falcon::VMachine *vm )
{
   if ( vm->param(0) == 0 )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
         .extra( "C, ..." ) );
   }

   // Save the parameters as the stack may change greatly.
   CoreObject* obj = vm->self().asObject();
   StackFrame* current = vm->currentFrame();

   Item i_check = vm->param(0) == 0 ? Item(): *vm->param(0);

   PoopSeq* seq = new PoopSeq( vm, Item(obj) );  // may throw
   vm->pushParam( new GarbagePointer( seq ) );
   seq->comprehension_start( vm, vm->self(), i_check );

   for( uint32 i = 1; i < current->m_param_count; ++i )
   {
      vm->pushParam( current->m_params[i] );
   }
}

}
}

/* end of poopseq_ext.cpp */