[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: cursor/stream/c++ iterator class?

Eric Mahurin

4/28/2005 8:22:00 PM

--- Simon Strandgaard <neoneye@gmail.com> wrote:
> On 4/28/05, Eric Mahurin <eric_mahurin@yahoo.com> wrote:
> > --- Simon Strandgaard <neoneye@gmail.com> wrote:
> [snip]
> > > Yeah, I don't have neither insert nor delete.
> > > I didn't needed it when I made the lib. I though about
> it,
> > > but couldn't decide how to approach this problem.
> >
> > So that the number of methods doesn't blow up, I decided to
> > have my "get" and "put" methods take a flags argument to
> > provide many functions:
> >
> > forward/reverse
> > move/hold
> > read(return original value)/ignore(return length)
> > scan or replace vs. delete or insert
> >
> > Last I counted, I have 12 get functions and 10 put
> functions
> > (all of which can operator on individual elements or a
> > string/array of them). The base class will base all of
> these
> > on 4 primitives (getdelete before/after and insert
> > before/after), but most classes will want to override most
> of
> > it.
>
> Watch out not putting too much behavior in a single function
> :-)

I know. I've been thinking about which way (many methods or a
few with flags) to go for a while. Both have their cons, but
I've decided on fewer methods with flags.

> Can you paste some of your code? I'd like to see it.


Let me give you the interface I have for now:

# flag bits
Reverse = 1 # go in reverse rather than forward
Hold = 2 # hold position instead of moving
Ignore = 4 # get: return length scanned rather than value
Read = 4 # put: return original value rather than length
Delete = 8 # get: delete value retrieved
Insert = 8 # put: insert rather than replace
Next = 0
Prev = Reverse
After = Hold # don't increment position like Next
Before = Reverse|Hold

def get(flags=0,length=nil)
# get(Next) # get next element (like getc)
# get(Next,2) # get next 2 elements (like read)
# get(After) # get an element after (like getc+ungetc)
# get(Next,"\n") # get next elements ending in "\n" (like gets)
# get(Next|Delete) # delete and return next element
# get(Next|Ignore,4) # skip next 4 elements (like seek)

def put(flags,value)
# put(Next,"X"[0]) # put next element (like putc)
# put(Next,"hello") # put next string of elements (like write)
# put(Next|Insert," world") # insert rather than replace
# put(Next|Read,"bye") # read what "bye" is replacing

def position(mark=true,&code)
# p = position() # get position for setting later
# p = position(false) # get position for observe only
# match = position { get(Next,5)=="hello" } # back if mismatch
# the above is great for parsing

def position=(p,mark=true)
# position=(p) # set position (you can still set to p later)
# position=(p,false) # set position and discard p

def unposition(p)
# unposition(p) # discard p

def position?(p=nil)
# position?(p) # is this a valid position to set to?
# position? # are there any valid positions to set to?


After looking at your stuff, I think I may add some other
routines:

def put_to(p,flags,value)
position { position=p; ret = put(flags,value); false }
ret
end

def get_from(p,flags,length)
position { position=p; ret = get(flags,value); false }
ret
end

def copy_from(p,gflags,pflags,length)
gflags &= ~Ignore
position { position=p; v = get(gflags,length); false }
put(pflags,v)
end

def copy_to(p,gflags,pflags,length)
gflags &= ~Ignore
v = get(gflags,length)
position { position=p; ret = put(pflags,v); false }
put(pflags,ret)
end

With the above routines, you can really see where having flags
rather than separate routines becomes very handy. Without it,
there would be too many variations.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail...


2 Answers

_ G O D _

6/8/2012 2:02:00 AM

0

"A Moose in Love" <parkstreetbooboo@gmail.com> wrote
news:11f86309-64b0-4d9c-86ec-8704724f1ff8@e20g2000vbm.googlegroups.com...
>
>> Brazil workers exploited as modern-day Amazon slaves....
>> Los Angeles
>> Meirelles was one of tens of thousands of Brazilians living in
>> what critics call modern slavery, mostly in the Amazon jungle,
>> where ranch owners are the law of the land. Promised work,
>> the victims are usually taken to remote, unfamiliar areas....
>> <http://www.latimes.com/news/nationworld/world/la-fg-brazil-slave-l...
>> See all stories on this topic:
>> <http://news.google.ca/news/story?ncl=http://www.latimes.com/news/n...
>>
> This is nothing new. I doubt that Brazil has ever gotten over the
> slave mentality that exists among the land owners, mine owners, etc.
> Years ago, I saw a documentary on Brazilian gold miners. My oh my.
> They were not technically slaves, as they were not bought and sold on
> a slave exchange. But they went of their own free will (because they
> had nothing to begin with) to the gold mines. Where they carry up
> sacks of mud which hopefully contains gold. Their pay is shit. Their
> camp is shit. They have it as bad as any slave anywhere.


If you think that it isn't fair even for people who
elected to overcome the difficulties they faced
after venturing on their own free will - then how
unfair it for the deliberately mistreated people,
who are being tortured not only against beliefs,
but clearly - for perverse sadistic satisfaction?....
--
_____________________________________________________
http://www.un.org/en/documents/udhr/i...
I intend to last long enough to put out of business all COck-suckers
and other beneficiaries of the institutionalized slavery and genocide.
------------------------------------------------------------------------------------------
"The army that will defeat terrorism doesn't wear uniforms, or drive
Humvees, or calls in air-strikes. It doesn't have a high command, or
high security, or a high budget. The army that can defeat terrorism
does battle quietly, clearing minefields and vaccinating children. It
undermines military dictatorships and military lobbyists. It subverts
sweatshops and special interests.Where people feel powerless, it
helps them organize for change, and where people are powerful, it
reminds them of their responsibility." ~~~~ Author Unknown ~~~~
___________________________________________________
--

The Peeler

6/8/2012 10:12:00 AM

0

On Thu, 7 Jun 2012 16:06:04 -0700 (PDT), A Moose in Love with Nazi Scum
wrote:

Moose in Love with Nazi Scum officially declaring on June 6th 2012 that he
will quit these groups:

"I'm going to stop posting here, and at other sites."
MID: <532392a3-2b78-42cb-beb9-99f292e18b4a@3g2000vbx.googlegroups.com>


Moose in Love with Nazi Scum officially declaring on May 5th 2012 that he
will quit alt.revisionism:

"I'm quitting altRev; there are excellent forums out there where spammers,
flamers, and trolls are not allowed.
peace"
MID: <627fdc9d-c01e-4eae-b196-bf9e9cc17652@z4g2000pbz.googlegroups.com>

Quite the disgusting hypocrite you are, eh, you notorious Nazicock sucker!
<BG>