Class for creating and formatting record id's. Normally these are just of
the form "<tablename>/<nnnnnn>"
Get the next ID for the specified table using
- p4 counter <table>
- 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
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
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
Format the sequence number for printing
# File P4table.rb, line 252
def seq_str
sprintf( "%06d", @seq )
end
String representation of an id
# File P4table.rb, line 259
def to_s
@table.name + "/" + seq_str()
end