Class P4RecId
In: P4table.rb
Parent: Object

Class for creating and formatting record id's. Normally these are just of the form "<tablename>/<nnnnnn>"

Methods
new    new_from_job    next    seq_str    to_s   
Attributes
:seq  [RW] 
:table  [RW] 
Public Class methods
next( table )

Get the next ID for the specified table using

  1. p4 counter <table>
  2. p4 counter <table> = <n+1>

Yes, this has a race condition, but there's no atomic get and set operation for Perforce counters.

# File P4table.rb, line 210
    def P4RecId.next( table )
	p4 = P4Global.tagged
	val = p4.run_counter( table.name ).shift.to_i
	val += 1
	p4.run_counter( table.name, val )
	P4RecId.new( table, val )
    end
new_from_job( job )

Instantiate a new P4RecID from the job name ( "<table>/<id>" ). Used to load existing records.

# File P4table.rb, line 222
    def P4RecId.new_from_job( job )
	( table, seq ) = job.split( "/" )
	P4RecId.new( P4Table.new( table ), seq )
    end
new( table, seq )

Construct a new RecID for the given table name and sequence number

# File P4table.rb, line 230
    def initialize( table, seq )
	@table = table
	if ( seq.kind_of?( String ) )
	    if ( seq =~ /^0*([1-9]\d+)$/ )
		@seq = $1.to_i
	    else
		@seq = seq.to_i
	    end
	else
	    @seq = seq
	end
    end
Public Instance methods
seq_str()

Format the sequence number for printing

# File P4table.rb, line 252
    def seq_str
	sprintf( "%06d", @seq )
    end
to_s()

String representation of an id

# File P4table.rb, line 259
    def to_s
	@table.name + "/" + seq_str()
    end