This file is indexed.

/usr/include/corelinux/Assertion.hpp is in libcorelinux-dev 0.4.32-7.4ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#if !defined (__ASSERTION_HPP)
#define __ASSERTION_HPP

/*
  CoreLinux++ 
  Copyright (C) 1999 CoreLinux Consortium
  
   The CoreLinux++ Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The CoreLinux++ Library Library is distributed in the hope that it will 
   be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  
*/   


/*
Assertion is the exception created when an assertion fails.  It contains
type information so that clients may filter the types of assertion
violations that they catch.  There are several types of assertion:

     ASSERT( bool )   Enabled by #define ALL_ASSERTIONS.  It is only used
                      inside the INVARIANT clause of a class declaration.

     REQUIRE( bool )  Enabled by #define ALL_ASSERTIONS or
                      #define ASSERT_REQUIRE.  This macro is used to
                      check precondtions for a function.  If disabled
                      the macro is compiled away.

     ENSURE( bool )   Enabled by #define ALL_ASSERTIONS or
                      #define ASSERT_ENSURE.  This macro is used to check
                      postconditions.  If disabled the macro is compiled
                      away.

     CHECK( bool )    Enabled by #define ALL_ASSERTIONS or
                      #define ASSERT_CHECK.  This macro is used to check
                      assumptions or to check calls to external functions
                      in the OS.  Unlike REQUIRE and ENSURE when disabled
                      this macro expands to:  if( !( exp )) {;} else
                      This expansion allows calls such as:
                         CHECK( DosSubAllocMem( ... ) == 0 );
                      to not be compiled away.

     CHECK_INVARIANT  Enabled by #define ALL_ASSERTIONS.  This macro is
                      used to validate that the class INVARIANT still
                      holds.  The INVARIANT must hold after construction
                      and at the end of any public member function.  In
                      order to use this assertion the class must have an
                      INVARIANT ... END_INVARIANT section in the class
                      definition.  If ALL_ASSERTIONS is not defined then
                      this macro expands to nothing.

     NEVER_GET_HERE   This macro is always enabled and throws an assertion
                      if it is ever executed.  It should be used to make
                      explicit to the reader that all cases have been
                      accounted for in a switch or if ... else if ... else
                      block.

Typically the programmer defines ALL_ASSERTIONS during development and
reduces assertion levels to ASSERT_REQUIRE at beta and even into release.

In addition to the assertions there are several helper macros that allow
for class INVARIANTs and the logic predicates "for all" and "there exists".
There is also the USES_OLD macro which allows changes in a class to be
checked against the original version of the class.

BASE_INVARIANT( BaseClass ) Can only be used in the INVARIANT clause
                      of a class definition.  This expands to call the
                      INVARIANT of one of the base classes in the
                      current class.  Expands to:  BaseClass::INVARIANT()

INVARIANT             Can only be used inside a class definition.  This
                      should be the last thing in the class and should
                      state the conditions that hold when the class is
                      correct.  The only statements allowed in the
                      INVARIANT are BASE_INVARIANT and ASSERT.
                      For example an ordered array class may
                      look like:

                         class OrderedArray<T> : public Vector
                         {
                         public:
                                  Array( int size ) :
                                      Vector(),
                                      theSize( size ),
                                      theArray( new T[ size ] );
                                  {
                                       orderTheArray();

                                       CHECK_INVARIANT;
                                  }

                                  virtual !Array();

                                  // other operations.

                         private:
                                 int theSize;
                                 T * theArray;

                         INVARIANT
                             BASE_INVARIANT( Vector );

                             // Array is sorted in ascending order.
                             ASSERT( FORALL(( int i = 1; i < theSize; i++ ),
                                         theArray[i-1] <= theArray[i] ));
                         END_INVARIANT
                         };  // end class OrderedArray<T>


END_INVARIANT         Used to terminate the INVARIANT clause in a class
                      definition.

USES_OLD( Type )      Creates a copy of the current object called old
                      which can then be used in assertions to check
                      those attributes between the new object and old.
                      Any function which needs old must declare this
                      at the start of the function.  The object must
                      be able to copy itself deeply for this to work
                      correctly.  Only creates old if ALL_ASSERTIONS or
                      ASSERT_ENSURE is defined.
                      WARNING:  old should only be used by the ENSURE
                      macro.

 old                  variable created by the USES_OLD macro.  A typical
                      use would be:

                            void List::addItem( item )
                            {
                                ...
                                ENSURE( size() == old.size() + 1 );
                            }

bool FORALL(( for-specification ), condition )

                 Only expands if ALL_ASSERITONS is defined, and can only
                 be used in assertions.  If ALL_ASSERTIONS is not defined
                 it becomes the value True.  If expanded it becomes
                 equivalent to:

                 REQUIRE( FORALL(( int i = 0; i < 10; i++ ), x[i] <= x[0] ));

                 REQUIRE( tempForAll() );

                 bool tempForAll()
                 {
                     bool result = True;
                     for( int i = 0; i < 10; i++ )
                         if( !( x[i] <= x[0] ))
                            {
                            result = False;
                            break;
                            }
                     return result;
                 }

                 Be very carefull using this macro since errors
                 in the for specification or condition can be very difficult
                 to find.  Also note that the condition can be another
                 FORALL or an EXISTS.

bool EXISTS((for-specification), condition )

                 Only expands if ALL_ASSERTIONS is defined,  otherwise
                 becomes the value True.  Returns True as soon as the
                 condition is met.  If all iterations fail then the
                 macro fails.  When expanded it becomes equivalent to:

                 ENSURE( EXISTS((int i = 0; i<10; i++), x[i] == old.x[i] ));
                 ENSURE( tempExists() );

                 bool tempExists()
                 {
                     bool result;
                     for( int i = 0; i < 10; i++ )
                        if( x[i] == old.x[i] )
                            {
                            result = True;
                            break;
                            }
                      return result;
                 }


The assertion mechanism also supports two functions;  assertionFailed()
and assertLoopDebugFunction().  The first is called when an assertion
fails and after the assertion exception has been built.  The second
one is called if FORALL or EXISTS fail.  These functions are a handy
place to set breakpoints during debugging.  They are implemented in
Assertion.cpp

               See also:  Object Oriented Software Construction
                          Bertrand Meyer.
                          Prentice Hall, Englewood Cliffs NJ., 1988.

                          C/C++ Users Journal October 1994 pages 21 - 37

*/

#if !defined IN_COMMON_HPP
   #error Assertion.hpp is included by Common.hpp only.
#endif

namespace   corelinux
{
   // Standard class Declarations

   DECLARE_CLASS( Assertion );

   // These macros are called when an assertion fails or a FORALL or EXISTS
   // test fails respectively.  They provide a convienent place to set a
   // breakpoint during debugging.
   //

   Long assertionFailed( AssertionCref rAssertion );
   void assertLoopDebugFunction( void );

   //
   // Static variables needed by the assertion macros.
   //

   static Long asstInvert   = 0;
   static Long asstResult   = 0;
   static Long asstEval     = 0;
   static Long asstShortCut = 0;
   static Long asstZero     = 0;

   static struct AssertCt
   {
      AssertCt( void )
      {
         asstInvert = asstResult = asstEval = asstShortCut = asstZero = 0;
      }
      // empty
   } asstCt;


   //
   // Typedefs and Macros
   //


   #define paste(a,b) a##b
   #define paste3(a,b,c) a##b##c


   #if defined  ALL_ASSERTIONS || defined ASSERT_REQUIRE
      #define REQUIRE( exp )                                               \
         IGNORE_RETURN (                                                   \
            asstResult = asstZero || exp,                                  \
            asstResult || assertionFailed( Assertion( Assertion::REQUIRE,  \
                                       TEXT( #exp ),                       \
                                      LOCATION                             \
                                      )) )

   #else
      #define REQUIRE( exp )
   #endif  // defined ALL_ASSERTIONS || ASSERT_REQUIRE

   #if defined  ALL_ASSERTIONS || defined ASSERT_ENSURE
      #define ENSURE( exp )                                                \
         IGNORE_RETURN (                                                   \
            asstResult = asstZero || exp,                                  \
            asstResult || assertionFailed( Assertion( Assertion::ENSURE,   \
                                       TEXT( #exp ),                       \
                                      LOCATION                             \
                                   )) )

   #else
      #define ENSURE( exp )
   #endif  // defined ALL_ASSERTIONS || ASSERT_ENSURE

   #if defined  ALL_ASSERTIONS || defined ASSERT_CHECK
      #define CHECK( exp )                                                 \
         IGNORE_RETURN (                                                   \
            asstResult = asstZero || exp,                                  \
            asstResult || assertionFailed( Assertion( Assertion::CHECK,    \
                                      paste3(                              \
                                             TEXT("CHECK( "),              \
                                             TEXT( #exp ),                 \
                                             TEXT(" )")                    \
                                            ),                             \
                                                 LOCATION )) )

   #else
      #define CHECK( exp )
   #endif  // defined ALL_ASSERTIONS || ASSERT_CHECK


   #define NEVER_GET_HERE                                               \
      assertionFailed( Assertion( Assertion::NEVERGETHERE,              \
                                TEXT("NEVER_GET_HERE"),                 \
                                LOCATION ))

//
// Macros that support class INVARIANTs.
//

   #if defined ALL_ASSERTIONS
      #define INVARIANT                                                 \
   protected:                                                           \
      virtual void invariant(void) const { Short executingInvariant = 1;
      #define END_INVARIANT }
      #define CHECK_INVARIANT  invariant()
   #else
      #define INVARIANT      paste(/, *)
      #define END_INVARIANT
      #define CHECK_INVARIANT
   #endif

/*                                 
                          paste3(                                       \
                                 TEXT("STDASSERT( "),                   \
                                 TEXT( #exp ),                          \
                                 TEXT(" )")                             \
                                ),                                      \
*/                                

   #if defined ALL_ASSERTIONS
      #define STDASSERT( exp )                                          \
      if( executingInvariant )                                          \
      {                                                                 \
         asstResult = asstZero || exp,                                  \
         asstResult ||                                                  \
            assertionFailed( Assertion( Assertion::ASSERT,              \
                                 TEXT( #exp ),                          \
                          LOCATION ));                                  \
      }                                                                 \
      else                                                              \
      {                                                                 \
         throw Exception(                                               \
            TEXT("STDASSERT used outside of INVARIANT"), LOCATION );    \
      }
   #else
      #define STDASSERT( exp )
   #endif  // defined ALL_ASSERTIONS

   #if defined ALL_ASSERTIONS
      #define BASE_INVARIANT( ClassType )                               \
      if( executingInvariant )                                          \
      {                                                                 \
         ClassType::invariant();                                        \
      }                                                                 \
      else                                                              \
      {                                                                 \
         throw Exception(                                               \
            TEXT("BASE_INVARIANT used outside of an INVARIANT"),        \
            LOCATION,                                                   \
            Exception::ProcessTerminate);                               \
      }

   #else
      #define BASE_INVARIANT( ClassType )
   #endif

//
// Macro that defines "old".
//

   #if defined ALL_ASSERTIONS || defined ASSERT_ENSURE
      #define USES_OLD( Type )   Type old( clself )
   #else
      #define USES_OLD( Type )
   #endif

//
// Macros for FORALL and EXISTS
//

   #define ASSERT_LOOP( asstFor, asstAll, asstCond )                    \
      anAssertCt();                                                     \
      {                                                                 \
         volatile x = 0;                                                \
         Long asstShortCut;                                             \
         if( asstDoEval( asstShortCut ))                                \
         {                                                              \
            Long asstInvert = ::asstInvert;                             \
            asstResult = asstAll;                                       \
            for asstFor                                                 \
            {                                                           \
               asstResult = x || asstCond;                              \
               if( asstResult != asstAll ) break;                       \
            }                                                           \
            if(asstInvert) asstResult = !asstResult;                    \
         }                                                              \
             ::asstShortCut = asstShortCut;                             \
             if( asstResult == 0 ) assertLoopDebugFunction();           \
      }                                                                 \
      asstResult = ::asstShortCut ? asstResult : asstResult

   #if defined ALL_ASSERTIONS
      #define FORALL(asstFor, asstCond ) ASSERT_LOOP( asstFor, 1, asstCond )
      #define EXISTS(asstFor, asstCond ) ASSERT_LOOP( asstFor, 0, asstCond )
   #else
      #define FORALL(asstFor, asstCond ) True
      #define EXISTS(asstFor, asstCond ) True
   #endif

//
// Constants
//


//
// Helper Classes (including exceptions).
//

   /**
   Assertion is-a Exception created when an assertion fails.  It contains
   type information so that clients may filter the types of assertion
   violations that they catch.  There are several types of assertion macros
   defined. Refer to the comments at the top of Assertion.hpp for details.
   */

   class Assertion : public Exception
   {
      //
      // Note that a private default constructor is not needed
      // beause Exception's default constructor is private.
      //

   public:

      /// Assertion Types enum

      enum Type
      {
         REQUIRE,       /// REQUIRE pre-condition state
         ENSURE,        /// ENSURE post-condition state
         CHECK,         /// CHECK invariant state
         ASSERT,        /// ASSERT invariant state
         NEVERGETHERE   /// NEVERGETHERE logic state
      };

   public:

      /**
      Assertion Constructor
      @param Type Specifies the state condition for the assertion
      @param Reason Text describing the assertion
      @param File The source module the assertion was thrown from
      @param Line The throw point line in the source module
      */

                  Assertion
                     ( 
                        Type aType,
                        CharPtr aReason,
                        CharPtr aFile,
                        LineNum aLine 
                     );

      /**
      Assertion copy constructor
      @param Assertion const reference
      */

                  Assertion( AssertionCref rExcept );

      /// Virtual Destructor

      virtual     ~Assertion( void );

      //
      // Operator overloads
      //

      /**
      Assignment operator overload
      @param  Assertion const reference
      @return Assertion reference to self
      */

      AssertionRef   operator=( AssertionCref );

      /**
      Comparisson operator overload
      @param Assertion const reference
      @return true if equal, false otherwise
      */

      bool           operator==( AssertionCref );

      //
      // Accessors
      //

      /**
      Accessor 
      @return The Type which caused the assertion
      */

      Assertion::Type getType( void ) const;

   private:

      Assertion::Type theType;
   };

//
// Inline Functions
//

   inline AssertCt & anAssertCt( void )
   {
      asstInvert = 0;
      asstEval   = 1;
      return asstCt;
   };

   inline Long asstDoEval( Long & asstShortCut )
   {
      Long result = asstEval;

      asstShortCut = !asstEval && asstResult;

      asstEval = 0;

      return result;
   }

   inline const AssertCt & operator !( const AssertCt & a )
   {
      asstInvert = !asstInvert;
      return a;
   }

   inline Long operator &&( Long left, const AssertCt & )
   {
      asstEval = left;
      return left;
   }

   inline Long operator ||( int left, const AssertCt & )
   {
      asstEval = !left;
      return left;
   }

}

#endif // !defined ASSERT_HPP

/*
   Common rcs information do not modify
   $Author: prudhomm $
   $Revision: 1.1 $
   $Date: 2000/04/23 20:43:13 $
   $Locker:  $
*/