P4RecId.html #1

  • //
  • guest/
  • tony_smith/
  • perforce/
  • utils/
  • doc/
  • classes/
  • P4RecId.html
  • View
  • Commits
  • Open Download .zip Download (6 KB)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html><head>
  <title>Class: P4RecId</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel=StyleSheet href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript" language="JavaScript">
  <!--
  function popCode(url) {
    window.open(url, "Code", 
          "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }
  //-->
  </script>
</head>

<body bgcolor="white">

<table summary="Information on class" width="100%" border="0" cellspacing="0">
 <tr class="title-row">
 <td class="big-title-font">
   <sup><font color="aqua">Class</font></sup> P4RecId
 </td>
 <td align="right">
   <table summary="layout" cellspacing="0" cellpadding="2">
     <tr valign="top">
      <td class="small-title-font">In:</td>
      <td class="small-title-font">
        <a href="../files/P4table_rb.html" class="aqua">
P4table.rb
         </a>
<br />
      </td>
     </tr>
     <tr>
      <td class="small-title-font">Parent:</td>
      <td class="small-title-font">
Object
      </td>
     </tr>
   </table>
  </td>
  </tr>
</table>
  <!-- banner header -->



<div class="description"><p>
Class for creating and formatting record id's. Normally these are just of
the form &quot;&lt;tablename&gt;/&lt;nnnnnn&gt;&quot;
</p>
</div>


<table summary="Methods" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table>
<div class="name-list">
<a href="#M000003">new</a>&nbsp; &nbsp;
<a href="#M000002">new_from_job</a>&nbsp; &nbsp;
<a href="#M000001">next</a>&nbsp; &nbsp;
<a href="#M000004">seq_str</a>&nbsp; &nbsp;
<a href="#M000005">to_s</a>&nbsp; &nbsp;
</div>

<table summary="Attributes" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Attributes</td></tr>
</table>
<table summary="Attribute details" cellspacing="5">
     <tr valign="top">
       <td class="attr-name">:seq</td>
       <td align="center" class="attr-rw">&nbsp;[RW]&nbsp;</td>
       <td></td>
     </tr>
     <tr valign="top">
       <td class="attr-name">:table</td>
       <td align="center" class="attr-rw">&nbsp;[RW]&nbsp;</td>
       <td></td>
     </tr>
</table>



<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Class methods</td></tr>
</table>
<table summary="method"  width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000001"></a>
<b>next</b>( table )
</td></tr>
</table>
<div class="description">
<p>
Get the next ID for the specified table using
</p>
<ol>
<li>p4 counter &lt;table&gt;

</li>
<li>p4 counter &lt;table&gt; = &lt;n+1&gt;

</li>
</ol>
<p>
Yes, this has a race condition, but there's no atomic get and set operation
for Perforce counters.
</p>
</div>
<pre class="source">
<span class="cmt"># File P4table.rb, line 210</span>
    <span class="kw">def</span> P4RecId.<span class="kw">next</span>( 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 )
    <span class="kw">end</span>
</pre>
<table summary="method"  width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000002"></a>
<b>new_from_job</b>( job )
</td></tr>
</table>
<div class="description">
<p>
Instantiate a new P4RecID from the job name (
&quot;&lt;table&gt;/&lt;id&gt;&quot; ). Used to load existing records.
</p>
</div>
<pre class="source">
<span class="cmt"># File P4table.rb, line 222</span>
    <span class="kw">def</span> P4RecId.new_from_job( job )
	( table, seq ) = job.split( <span class="str">&quot;/&quot;</span> )
	P4RecId.new( P4Table.new( table ), seq )
    <span class="kw">end</span>
</pre>
<table summary="method"  width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000003"></a>
<b>new</b>( table, seq )
</td></tr>
</table>
<div class="description">
<p>
Construct a new RecID for the given table name and sequence number
</p>
</div>
<pre class="source">
<span class="cmt"># File P4table.rb, line 230</span>
    <span class="kw">def</span> initialize( table, seq )
	@table = table
	<span class="kw">if</span> ( seq.kind_of?( String ) )
	    <span class="kw">if</span> ( seq =~ <span class="re">/^0*([1-9]\d+)$/</span> )
		@seq = $1.to_i
	    <span class="kw">else</span>
		@seq = seq.to_i
	    <span class="kw">end</span>
	<span class="kw">else</span>
	    @seq = seq
	<span class="kw">end</span>
    <span class="kw">end</span>
</pre>
<table summary="Method list" cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Public Instance methods</td></tr>
</table>
<table summary="method"  width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000004"></a>
<b>seq_str</b>()
</td></tr>
</table>
<div class="description">
<p>
Format the sequence number for printing
</p>
</div>
<pre class="source">
<span class="cmt"># File P4table.rb, line 252</span>
    <span class="kw">def</span> seq_str
	sprintf( <span class="str">&quot;%06d&quot;</span>, @seq )
    <span class="kw">end</span>
</pre>
<table summary="method"  width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="M000005"></a>
<b>to_s</b>()
</td></tr>
</table>
<div class="description">
<p>
String representation of an id
</p>
</div>
<pre class="source">
<span class="cmt"># File P4table.rb, line 259</span>
    <span class="kw">def</span> to_s
	@table.name + <span class="str">&quot;/&quot;</span> + seq_str()
    <span class="kw">end</span>
</pre>

</body>
# Change User Description Committed
#2 3093 Tony Smith Move docs for P4Table in preparation for upcoming docs for
specsaver.rb
#1 2396 Tony Smith Add RDoc documentation for P4Table.rb.
Very pretty.