Print, Audit, and Trace methods for user objects: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
m (misc cleanup)
 
(One intermediate revision by the same user not shown)
Line 31: Line 31:
==Syntax==
==Syntax==
The syntax for the <var>Print</var>, <var>Audit</var>, and <var>Trace</var> methods is the same for each; the syntax for <var>Print</var> follows:
The syntax for the <var>Print</var>, <var>Audit</var>, and <var>Trace</var> methods is the same for each; the syntax for <var>Print</var> follows:
<p class="syntax"><span class="term">object</span><span class="literal">:Print( </span><span class="squareb">[</span><span class="literal">Name= </span><span class="term">string</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Truncate= </span><span class="term">number</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Indent= </span><span class="term">number</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">MaxDepth= </span><span class="term">number</span><span class="squareb">]</span><span class="literal"> )</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Prefix= </span><span class="term">string</span><span class="squareb">]</span><span class="literal"> )</span> </p>
<p class="syntax"><span class="term">object</span><span class="literal">:Print(</span><span class="squareb">[</span><span class="literal">Name=</span><span class="term">string</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Truncate=</span><span class="term">num</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Indent=</span><span class="term">num</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">MaxDepth=</span><span class="term">num</span><span class="squareb">]</span><span class="literal">, </span><span class="squareb">[</span><span class="literal">Prefix=</span><span class="term">string</span><span class="squareb">]</span><span class="literal">)</span> </p>


===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table>
<tr><th>object</th>
<tr><th>object</th>
<td>An object variable or expression that belongs to a user-defined class. </td></tr>
<td>An object variable or expression that belongs to a user-defined class. </td></tr>
<tr><th><var>Name</var></th>
<tr><th><var>Name</var></th>
<td>The optional <var>Name</var> argument ([[Notation conventions for methods#Named parameters|name required]]) is a string  that is the name to be used in the object display in place of the placeholder asterisk (<tt>*</tt>) in the [[#objInfo|object-identifying information]].</td></tr>
<td>The optional <var>Name</var> argument ([[Notation conventions for methods#Named parameters|name required]]) is a string  that is the name to be used in the object display in place of the placeholder asterisk (<tt>*</tt>) in the [[#objInfo|object-identifying information]].</td></tr>
<tr><th><var>Truncate</var></th>
<tr><th><var>Truncate</var></th>
<td>The optional <var>Truncate</var> argument (name required) is the numeric value of the length limit for string values of member Variables in the object output display. The maximum allowed is 255, and the default length is 64.  
<td>The optional <var>Truncate</var> argument (name required) is the numeric value of the length limit for string values of member Variables in the object output display. The maximum allowed is 255, and the default length is 64.  
<p>
<p class="note">'''Note:''' For <var>Unicode</var> strings, the truncated length is the length in characters ''before'' character-entity substitution. See the example [[#unicode|below]]. </p></td></tr>
'''Note:''' For <var>Unicode</var> strings, the truncated length is the length in characters  
''before'' character-entity substitution. See the example [[#unicode|below]]. </p></td></tr>


<tr><th><var>Indent</var></th>
<tr><th><var>Indent</var></th>
<td>The optional <var>Indent</var> argument (name required) is a numeric value that specifies the number of blank characters that precede the values of the class variables at each level in the output display. Its default is 1. For example, specifying <code>%foo:print(indent=10)</code> for the <code>Test</code> object in the introduction, above, produces:  
<td>The optional <var>Indent</var> argument (name required) is a numeric value that specifies the number of blank characters that precede the values of the class variables at each level in the output display. Its default is 1. For example, specifying <code>%foo:print(indent=10)</code> for the <code>Test</code> object in the introduction, above, produces:  
<p class="code">\* = Object Test, id=26                                                                
<p class="code">\* = Object Test, id=26  
           a = 1.4142135623731                                                        
           a = 1.4142135623731  
           b = "A bold fusilier came marching back through Rochester"                    
           b = "A bold fusilier came marching back through Rochester"
           c = False                                                                  
           c = False
           d = Object System:Stringlist, id=27
           d = Object System:Stringlist, id=27
/* = Object Test, id=26   </p>
/* = Object Test, id=26 </p></td></tr>
                                                                                         
 
</td></tr>
<tr><th><var>MaxDepth</var></th>
<tr><th><var>MaxDepth</var></th>
<td>The optional <var>MaxDepth</var> argument (name required) is an integer that specifies the maximum number of levels of object-expansion in the output display. If 2, for example, the contents of an object contained within the method object is expanded in a second level of the output display, but if that contained object itself contains an object, the latter is not expanded.  
<td>The optional <var>MaxDepth</var> argument (name required) is an integer that specifies the maximum number of levels of object-expansion in the output display. If 2, for example, the contents of an object contained within the method object is expanded in a second level of the output display, but if that contained object itself contains an object, the latter is not expanded.  
<p>Objects already expanded are not expanded a second time, regardless of the <var>MaxDepth</var> value. </p>
<p>
Objects already expanded are not expanded a second time, regardless of the <var>MaxDepth</var> value. </p>
<p>
<p>
The default maximum level of nesting is 1, that is, objects contained within the method object are not expanded. </p></td></tr>
The default maximum level of nesting is 1, that is, objects contained within the method object are not expanded. </p></td></tr>
Line 69: Line 69:
<div id="objInfo"></div><dt>\* = Object Test, id=26
<div id="objInfo"></div><dt>\* = Object Test, id=26
<dd>
<dd>
<ul><li>Since objects can be nested within objects, each nesting level begins with   
<ul>
a backslash (<tt>\</tt>) in the object's start column and closes with a forward slash (<tt>/</tt>) in the same column. The closing of a nesting level repeats the object-identifying information at the start.  
<li>Since objects can be nested within objects, each nesting level begins with   
a backslash (<tt>\</tt>) in the object's start column and closes with a forward slash (<tt>/</tt>) in the same column. The closing of a nesting level repeats the object-identifying information at the start. </li>
 
<li>The asterisk (<tt>*</tt>) in the object-identifying information that follows the slashes is a placeholder for
<li>The asterisk (<tt>*</tt>) in the object-identifying information that follows the slashes is a placeholder for
the object variable being printed or for the expression that produced the object being printed.
the object variable being printed or for the expression that produced the object being printed.
 
<p>
You can replace this asterisk with a value you specify using the method's <var>Name</var> parameter. For example: If you specify <code>%test:print(name='%test')</code>, the first line of the output display would be:
You can replace this asterisk with a value you specify using the method's <var>Name</var> parameter. For example: If you specify <code>%test:print(name='%test')</code>, the first line of the output display would be: </p>
<p class="code">\%test = Object Test, id=26 </p>
<p class="code">\%test = Object Test, id=26 </p>
<p>
If you specify <code>%test:print(name="%foo (iteration " %i ")")</code>, the first line might be:
If you specify <code>%test:print(name="%foo (iteration " %i ")")</code>, the first line might be:
<p class="code">\%test (iteration 3) = Object Test, id=26  </p>
<p class="code">\%test (iteration 3) = Object Test, id=26  </p></li>
<li>The object description (<code>Object Foo</code>) is present to reveal the real class of the object if it is an      
 
extended object.  
<li>The object description (<code>Object Foo</code>) is present to reveal the real class of the object if it is an extended object. </li>
<li>The <code>id</code> value is the unique internal ID given to every object.
 
<li>The <code>id</code> value is the unique internal ID given to every object. </li>
</ul>
</ul>
<dt>a = 1.4142135623731  
<dt>a = 1.4142135623731  
<dd>Numerical values are displayed as is.  
<dd>Numerical values are displayed as is.  
Line 87: Line 92:
<dd>String values are enclosed within double-quotation marks. If the current value of variable <code>b</code> is <code>He said "Yesterday is history"</code>, its value in the output display is:
<dd>String values are enclosed within double-quotation marks. If the current value of variable <code>b</code> is <code>He said "Yesterday is history"</code>, its value in the output display is:
<p class="code"> b = "He said ""Yesterday is history""" </p>
<p class="code"> b = "He said ""Yesterday is history""" </p>
 
<p>
The maximum string length displayed is 255, and the default is 64.  
The maximum string length displayed is 255, and the default is 64.  
You set the maximum string length with the <var>Truncate</var> parameter:                                                     
You set the maximum string length with the <var>Truncate</var> parameter: </p>                                                    
<p class="code">%test:print(truncate=20) </p>                                                        
<p class="code">%test:print(truncate=20) </p>                                                                     <p>
                                                                                     
If a string is truncated, its value is followed by an ellipsis ''after'' a close quote: </p>
If a string is truncated, its value is followed by an ellipsis ''after'' a close quote:
<p class="code">\* = Object Test, id=26
<p class="code">\* = Object Test, id=26
  a = 1.4142135623731
  a = 1.4142135623731
Line 100: Line 104:
/* = Object Test, id=26 </p>
/* = Object Test, id=26 </p>


<div id="unicode"></div>'''Note:''' For <var>Unicode</var> strings, the truncated length is the length in characters ''before'' character-entity substitution. If variable <code>b</code> above is declared as <var>Unicode</var>, and its value in the program is:  
<div id="unicode"></div>
<p class="note">'''Note:''' For <var>Unicode</var> strings, the truncated length is the length in characters ''before'' character-entity substitution. If variable <code>b</code> above is declared as <var>Unicode</var>, and its value in the program is: </p>
<p class="code">%test:b = 'I think I had too much &amp;pi; for dessert':u </p>  
<p class="code">%test:b = 'I think I had too much &amp;pi; for dessert':u </p>  
<p>
The output after specifying <code>%test:print(truncate=30)</code> is: </p>
<p class="code">b = "I think I had too much &amp;#x03C0; for d":u... </p>


The output after specifying <code>%test:print(truncate=30)</code> is:
<p class="code">b = "I think I had too much &amp;#x03C0; for d":u... </p>
<dt>c = False  
<dt>c = False  
<dd>Enumeration values are displayed as is.  
<dd>Enumeration values are displayed as is.  
Line 110: Line 116:
<dd>
<dd>
<ul>
<ul>
<li>The system-class specific <var>Print</var> methods (for example, the <var>Stringlist</var> <var>[[Print (Stringlist function)|Print]]</var> function) are <strong>not</strong> invoked inside a generic object Print expansion.  
<li>The system-class specific <var>Print</var> methods (for example, the <var>Stringlist</var> <var>[[Print (Stringlist function)|Print]]</var> function) are <strong>not</strong> invoked inside a generic object <var>Print</var> expansion. </li>
 
<li>A Null object is indicated as such:
<li>A Null object is indicated as such:
<p class="code">d = Object System:Stringlist, null </p>
<p class="code">d = Object System:Stringlist, null </p>
In this case the object type is the object type of the object variable.                                      
In this case the object type is the object type of the object variable. </li>
                                   
<li>If an object contains an instance of itself, the generic Print display of the object does not contain a repeated expansion of the object. For example, if variable <code>d</code> is declared in the class <code>Test</code> definition as an object of class <code>Test</code>, and the request contains a sequence like this:
<li>If an object contains an instance of itself, the generic Print display of the object does not contain a repeated expansion of the object. For example, if variable <code>d</code> is declared in the class <code>Test</code> definition as an object of class <code>Test</code>, and the request contains a sequence like this:
<p class="code">%test is object test
<p class="code">%test is object test
Line 124: Line 132:
  c = False
  c = False
  d = Object Test, id=26 (already displayed)
  d = Object Test, id=26 (already displayed)
/* = Object Test, id=26  </p>  
/* = Object Test, id=26  </p></li>
</ul>
</ul>
</dl>
</dl>
Line 131: Line 139:
<ul>
<ul>
<li>If you have defined your own Print method for a class (or define a local Print method),       
<li>If you have defined your own Print method for a class (or define a local Print method),       
your methods will hide the generic Print method, and there is no workaround for this.    
your methods will hide the generic Print method, and there is no workaround for this. </li>
<li>These generic output methods display a class's public and private variables but not shared variables.        
 
<li>These generic output methods display a class's public and private variables but not shared variables. </li>


<li>You can use the generic Print, Audit, and Trace methods in <var class="product">User Language</var> programs, but they are likely to be of more value in the <var class="product">[http://www.sirius-software.com/maint/download/factr.pdf SirFact]</var> dump reader, where you can do something like this to display the object contents:
<li>You can use the generic Print, Audit, and Trace methods in <var class="product">User Language</var> programs, but they are likely to be of more value in the <var class="product">[[SirFact]]</var> dump reader, where you can do something like this to display the object contents:
<p class="code">d %myObject:print(maxDepth=2)  </p>                 
<p class="code">d %myObject:print(maxDepth=2)  </p>                 
 
<p>
Or, if you don't need any special <var>Print</var> method parameters:
Or, if you don't need any special <var>Print</var> method parameters: </p>
<p class="code">d %myObject  </p>       
<p class="code">d %myObject  </p></li>       


<div id="prefix"></div><li>For the generic <var>Audit</var> and <var>Trace</var> methods especially, you may want output values to be preceded by something to make the values stand out in, say, the audit trail. The <var>Prefix</var> parameter causes each output line to be preceded by some arbitrary text. For example:
<div id="prefix"></div><li>For the generic <var>Audit</var> and <var>Trace</var> methods especially, you may want output values to be preceded by something to make the values stand out in, say, the audit trail. The <var>Prefix</var> parameter causes each output line to be preceded by some arbitrary text. For example:
<p class="output">%test:trace(prefix='>>>') </p>  
<p class="output">%test:trace(prefix='>>>') </p>  
                                                                                           
<p>
Using the Test class data from above, this statement displays:                              
Using the <code>Test</code> class data from above, this statement displays: </p>                             
<p class="output">>>>\* = Object Test, id=26       
<p class="output">>>>\* = Object Test, id=26       
>>> a = 1.4142135623731  
>>> a = 1.4142135623731  
Line 149: Line 158:
>>> c = False  
>>> c = False  
>>> d = Object System:Stringlist, id=27  
>>> d = Object System:Stringlist, id=27  
>>>/* = Object Test, id=26  </p>
>>>/* = Object Test, id=26  </p></li>
</ul>
</ul>


==See also==
==See also==
<ul>
<ul>
<li>[[Janus SOAP ULI essentials]]
<li>[[Object oriented programming in SOUL]]
</ul>
</ul>


[[Category:SOUL object-oriented programming topics]]
[[Category:SOUL object-oriented programming topics]]

Latest revision as of 20:17, 12 September 2016

Available only for non-system User Language objects, the Print, Audit, and Trace methods output a display of the current values of the Variable members of the method object. Introduced in Sirius Mods Version 8.0, these methods are intended as programmer debugging and auditing tools and are not intended to be a core part of applications.

As an example, to view the content of the %test object variable of your simple user class Test, you issue %test:Print:

class test public variable a is float variable b is string len 32 variable c is enumeration boolean variable d is object stringlist end public end class .... %test:Print

The result is output like this:

\* = Object Test, id=26 a = 1.4142135623731 b = "A bold fusilier came marching back through Rochester" c = False d = Object System:Stringlist, id=27 /* = Object Test, id=26

The particulars of this output format are described below.

The Print, Audit, and Trace methods are not themselves members of a particular class and are sometimes referred to as generic object methods.

Syntax

The syntax for the Print, Audit, and Trace methods is the same for each; the syntax for Print follows:

object:Print([Name=string], [Truncate=num], [Indent=num], [MaxDepth=num], [Prefix=string])

Syntax terms

object An object variable or expression that belongs to a user-defined class.
Name The optional Name argument (name required) is a string that is the name to be used in the object display in place of the placeholder asterisk (*) in the object-identifying information.
Truncate The optional Truncate argument (name required) is the numeric value of the length limit for string values of member Variables in the object output display. The maximum allowed is 255, and the default length is 64.

Note: For Unicode strings, the truncated length is the length in characters before character-entity substitution. See the example below.

Indent The optional Indent argument (name required) is a numeric value that specifies the number of blank characters that precede the values of the class variables at each level in the output display. Its default is 1. For example, specifying %foo:print(indent=10) for the Test object in the introduction, above, produces:

\* = Object Test, id=26 a = 1.4142135623731 b = "A bold fusilier came marching back through Rochester" c = False d = Object System:Stringlist, id=27 /* = Object Test, id=26

MaxDepth The optional MaxDepth argument (name required) is an integer that specifies the maximum number of levels of object-expansion in the output display. If 2, for example, the contents of an object contained within the method object is expanded in a second level of the output display, but if that contained object itself contains an object, the latter is not expanded.

Objects already expanded are not expanded a second time, regardless of the MaxDepth value.

The default maximum level of nesting is 1, that is, objects contained within the method object are not expanded.

Prefix The optional Prefix argument (name required) is the string value of the arbitrary characters that precede the lines in the object output display. See below for an example.

Output display

Note the following about the object output display:

\* = Object Test, id=26
  • Since objects can be nested within objects, each nesting level begins with a backslash (\) in the object's start column and closes with a forward slash (/) in the same column. The closing of a nesting level repeats the object-identifying information at the start.
  • The asterisk (*) in the object-identifying information that follows the slashes is a placeholder for the object variable being printed or for the expression that produced the object being printed.

    You can replace this asterisk with a value you specify using the method's Name parameter. For example: If you specify %test:print(name='%test'), the first line of the output display would be:

    \%test = Object Test, id=26

    If you specify %test:print(name="%foo (iteration " %i ")"), the first line might be:

    \%test (iteration 3) = Object Test, id=26

  • The object description (Object Foo) is present to reveal the real class of the object if it is an extended object.
  • The id value is the unique internal ID given to every object.
a = 1.4142135623731
Numerical values are displayed as is.
b = "A bold fusilier came marching back through Rochester"
String values are enclosed within double-quotation marks. If the current value of variable b is He said "Yesterday is history", its value in the output display is:

b = "He said ""Yesterday is history"""

The maximum string length displayed is 255, and the default is 64. You set the maximum string length with the Truncate parameter:

%test:print(truncate=20)

If a string is truncated, its value is followed by an ellipsis after a close quote:

\* = Object Test, id=26 a = 1.4142135623731 b = "A bold fusilier came"... c = False d = Object System:Stringlist, id=27 /* = Object Test, id=26

Note: For Unicode strings, the truncated length is the length in characters before character-entity substitution. If variable b above is declared as Unicode, and its value in the program is:

%test:b = 'I think I had too much &pi; for dessert':u

The output after specifying %test:print(truncate=30) is:

b = "I think I had too much &#x03C0; for d":u...

c = False
Enumeration values are displayed as is.
d = Object System:Stringlist, id=27
  • The system-class specific Print methods (for example, the Stringlist Print function) are not invoked inside a generic object Print expansion.
  • A Null object is indicated as such:

    d = Object System:Stringlist, null

    In this case the object type is the object type of the object variable.
  • If an object contains an instance of itself, the generic Print display of the object does not contain a repeated expansion of the object. For example, if variable d is declared in the class Test definition as an object of class Test, and the request contains a sequence like this:

    %test is object test ... %test:d = %test

    The %test:print output display might be:

    \* = Object Test, id=26 a = 1.4142135623731 b = "A bold fusilier came marching back through Rochester" c = False d = Object Test, id=26 (already displayed) /* = Object Test, id=26

Usage notes

  • If you have defined your own Print method for a class (or define a local Print method), your methods will hide the generic Print method, and there is no workaround for this.
  • These generic output methods display a class's public and private variables but not shared variables.
  • You can use the generic Print, Audit, and Trace methods in User Language programs, but they are likely to be of more value in the SirFact dump reader, where you can do something like this to display the object contents:

    d %myObject:print(maxDepth=2)

    Or, if you don't need any special Print method parameters:

    d %myObject

  • For the generic Audit and Trace methods especially, you may want output values to be preceded by something to make the values stand out in, say, the audit trail. The Prefix parameter causes each output line to be preceded by some arbitrary text. For example:

    %test:trace(prefix='>>>')

    Using the Test class data from above, this statement displays:

    >>>\* = Object Test, id=26 >>> a = 1.4142135623731 >>> b = "A bold fusilier came marching back through Rochester" >>> c = False >>> d = Object System:Stringlist, id=27 >>>/* = Object Test, id=26

See also