summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/util/iipdigit.h
blob: e43a976e8ae76811b3d94df6fabe00fba1f4216c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/util/iipdigit.h $                    */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1993,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef IIPDIGIT_H
#define IIPDIGIT_H

/* Module Description *************************************************/
/*                                                                    */
/*  Name:  iipdigit.h                                                 */
/*                                                                    */
/*  Description:  This module provides the Digit String class
                  hierarchy definition.                               */
/*                                                                    */
/* End Module Description *********************************************/

/* Change Log *********************************************************/
/*                                                                    */
/*  Flag  PTR/DCR#  Userid    Date      Description                   */
/*  ----  --------  --------  --------  -----------                   */
/*                  JST       06/04/93  Initial Creation              */
/*        D24694.3  JST       06/13/94  I1 Review changes             */
/*                                                                    */
/* End Change Log *****************************************************/

/*--------------------------------------------------------------------*/
/* Reference the virtual function tables and inline function
   defintions in another translation unit.                            */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  Includes                                                          */
/*--------------------------------------------------------------------*/

#include <prdf_types.h>
namespace PRDF
{
/*--------------------------------------------------------------------*/
/*  Forward References                                                */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  User Types                                                        */
/*--------------------------------------------------------------------*/

// Type Specification //////////////////////////////////////////////////
//
// Title:  CPU_WORD
//
// Purpose:  This type is used to take advantage of the most efficient
//           memory reference size for a specific CPU architecture.
//           This type defintion is provided only to handle the case
//           where no previous defintions exists.
//
// End Type Specification //////////////////////////////////////////////

#ifndef CPU_WORD

typedef uint32_t CPU_WORD;

#endif

/*--------------------------------------------------------------------*/
/*  Constants                                                         */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  Macros                                                            */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  Global Variables                                                  */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  Function Prototypes                                               */
/*--------------------------------------------------------------------*/

/* Class Specification ************************************************/
/*                                                                    */
/*  Name:  DIGIT_STRING_CLASS                                         */
/*                                                                    */
/*  Title:  Digit String                                              */
/*                                                                    */
/*  Purpose:  DIGIT_STRING_CLASS provides the representation and
              access to a sequence of digits in a specified range.    */
/*                                                                    */
/*  Usage:  This is an abstract base class.                           */
/*                                                                    */
/*  Side-effects:  None.                                              */
/*                                                                    */
/*  Dependencies:  Access operations must specify position less than
                   the length.                                        */
/*                                                                    */
/*  Notes:  The Digit String maintains a sequence of digits in the
            range of 0 to maximum_digit_value.  If a value that is
            being written is is larger than the maximum_digit_value,
            then the digit is set to the maximum_digit_value.  A
            length of 0 is allowed, but no digits can be accessed.  If
            length is greater than 0, then the Digit positions are
            specified 0 to (length - 1) from left to right.

            0 1 2 3 .... (length - 1)

            D D D D ....      D                                       */
/*                                                                    */
/*  Cardinality:  0                                                   */
/*                                                                    */
/*  Space Complexity:  Constant                                       */
/*                                                                    */
/* End Class Specification ********************************************/

class DIGIT_STRING_CLASS
  {
  public:

    // Function Specification //////////////////////////////////////////
    //
    // Title:  ~DIGIT_STRING_CLASS (Virtual destructor)
    //
    // Purpose:  This function performs no special action.
    //
    // Side-effects:  This instance is no longer valid.
    //
    // Dependencies:  None.
    //
    // Notes:  This function performs the same action as a default
    //         defintion.  It is included because the virtual
    //         declaration is required for this base class.
    //
    // End Function Specification //////////////////////////////////////

    virtual ~DIGIT_STRING_CLASS
      (
         void
         /*!i No paramters                                            */
      )
         /*!o No value returned                                       */
      {
      }

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Assingment operator
    //
    // Purpose:  This function assigns the data members with the values
    //           from the Digit String reference.
    //
    // Side-effects:  Data members are modified.
    //
    // Dependencies:  None.
    //
    // Notes:  This function performs the same action as a default
    //         defintion.  It is included here to emphasize the actions
    //         performed and the need for an explicit definition in each
    //         derived class.
    //
    // End Function Specification //////////////////////////////////////

    DIGIT_STRING_CLASS & operator=
      (
         const DIGIT_STRING_CLASS & string
         /*!i Digit string instance to assign from                    */
      )
         /*!o Reference to this Digit String instance                 */
      {
      // No check for assignment to self is required

      maximum_digit_value = string.maximum_digit_value;
      length = string.length;

      return(*this);
      }

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Get Value (Pure virtual)
    //
    // Purpose:  This function returns the value of a digit at the
    //           specified position.
    //
    // Side-effects:  None.
    //
    // Dependencies:  Position must be in the string.
    //
    // Notes:  This function has no definition.
    //
    // End Function Specification //////////////////////////////////////

    virtual uint32_t GetValue
      (
         uint32_t position
         /*!i Digit position                                          */
      ) const = 0;
         /*!o Digit value                                             */

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Set Value (Pure virtual)
    //
    // Purpose:  This function sets the value of the digit at the
    //           specified position.  No other digits are affected.
    //
    // Side-effects:  A digit in the string is modified.
    //
    // Dependencies:  Position must be in the string.
    //
    // Notes:  This function has no definition.
    //
    // End Function Specification //////////////////////////////////////

    virtual void SetValue
      (
         uint32_t position,
         /*!i Digit position                                          */
         uint32_t value
         /*!i Digit value to set                                      */
      ) = 0;
         /*!o No value returned                                       */

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Fill
    //
    // Purpose:  This function sets the value of each digit in the
    //           string with the same specified value.
    //
    // Side-effects:  All digits in the string is modified.
    //
    // Dependencies:  None.
    //
    // Time Complexity:  O(m) where m is the length
    //
    // End Function Specification //////////////////////////////////////

    void Fill
      (
         uint32_t value
         /*!i Digit value for each position                           */
      );
         /*!o No value returned                                       */

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Equality operator
    //
    // Purpose:  This function determines if the specified string is
    //           equal two this one.  If the lengths are equal and the
    //           corresponding values at every position are equal, then
    //           the Digit strings are equal.
    //
    // Side-effects:  None.
    //
    // Dependencies:  None.
    //
    // Time Complexity:  O(m) where m is the length
    //
    // End Function Specification //////////////////////////////////////

    bool operator==
      (
         const DIGIT_STRING_CLASS & string
         /*!i Digit string instance to compare                        */
      ) const;
         /*!o Non-zero if digit strings are equal, otherwise zero     */

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Get Maximum Digit Value
    //
    // Purpose:  This function returns the maximum digit value.
    //
    // Side-effects:  None.
    //
    // Dependencies:  None.
    //
    // End Function Specification //////////////////////////////////////

    uint32_t GetMaximumDigitValue
      (
         void
         /*!i No parameters                                           */
      ) const
         /*!o Maximum allowable digit value in the string             */
      {
      return(maximum_digit_value);
      }

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Get Length
    //
    // Purpose:  This function returns the length.
    //
    // Side-effects:  None.
    //
    // Dependencies:  None.
    //
    // End Function Specification //////////////////////////////////////

    uint32_t GetLength
      (
         void
         /*!i No parameters                                           */
      ) const
         /*!o Digit string length                                     */
      {
      return(length);
      }

  protected:

    // Function Specification //////////////////////////////////////////
    //
    // Title:  DIGIT_STRING_CLASS (Constructor)
    //
    // Purpose:  This function initializes the data members.
    //
    // Side-effects:  This instance is initialized.
    //
    // Dependencies:  None.
    //
    // End Function Specification //////////////////////////////////////

    DIGIT_STRING_CLASS
      (
         uint32_t mdv,
         /*!i Maximum digit value                                     */
         uint32_t le
         /*!i Digit length                                            */
      ) :
         /*!o No value returned                                       */
      maximum_digit_value(mdv),
      length(le)
      {
      }

    // Function Specification //////////////////////////////////////////
    //
    // Title:  DIGIT_STRING_CLASS (Copy constructor)
    //
    // Purpose:  This function initializes the data members from the
    //           Digit String reference.
    //
    // Side-effects:  This instance is initialized.
    //
    // Dependencies:  None.
    //
    // Notes:  This function performs the same action as a default
    //         defintion.  It is included here to emphasize the actions
    //         performed and the need for an explicit definition in each
    //         derived class.
    //
    // End Function Specification //////////////////////////////////////

    DIGIT_STRING_CLASS
      (
         const DIGIT_STRING_CLASS & string
         /*!i Digit string reference to copy                          */
      ) :
         /*!o No value returned                                       */
      maximum_digit_value(string.maximum_digit_value),
      length(string.length)
      {
      }

    // Function Specification ///////////////////////////////////////////
    //
    // Title:  Set String (Pure virtual)
    //
    // Purpose:  This function performs any required representation
    //           actions.
    //
    // Side-effects:  The Digit String is valid.
    //
    // Dependencies:  This function must be called at least once prior
    //                to the first DIgit read or write.
    //
    // Notes:  This function has no definition.
    //
    // End Function Specification //////////////////////////////////////

    virtual void SetString
      (
         void
         /*!i No parameters                                           */
      ) = 0;
         /*!o No value returned                                       */

    // Function Specification ///////////////////////////////////////////
    //
    // Title:  Set String
    //
    // Purpose:  This function assigns the data members and calls
    //           SetString() to perform any required representation
    //           actions.
    //
    // Side-effects:  The Digit String is valid.
    //
    // Dependencies:  None.
    //
    // End Function Specification //////////////////////////////////////

    void SetString
      (
         uint32_t mdv,
         /*!i Maximum digit value                                     */
         uint32_t le
         /*!i Digit length                                            */
      )
         /*!o No value returned                                       */
      {
      maximum_digit_value = mdv;
      length = le;

      SetString();
      }

    // Function Specification //////////////////////////////////////////
    //
    // Title:  Set Values
    //
    // Purpose:  This function sets the values of the string at
    //                 corresponding positions.  If one of the Digit Strings
    //                 is larger, than the extra digits are ignored.  If a
    //                 value from the string is larger than the
    //                 maximum_digit_value, then the digit is set to the
    //                 maximum_digit_value.
    //
    // Side-effects:  Digits in string are modified.
    //
    // Dependencies:  None.
    //
    // Time Complexity:  O(m) where m is the length
    //
    // End Function Specification //////////////////////////////////////

    virtual void SetValues
      (
         const DIGIT_STRING_CLASS & string
         /*!i Reference to Digit string set set values from           */
      );
         /*!o No value returned                                       */

  private:

    // Data Specification //////////////////////////////////////////////
    //
    // Purpose:  This data is used to maintain the Digit String.
    //
    // End Data Specification //////////////////////////////////////////

    uint32_t                      maximum_digit_value;
    uint32_t                      length;

  };

} //End namespace PRDF
#endif
OpenPOWER on IntegriCloud