1#if !defined( OBJECT_INCLUDED )  /* Include this file only once */
2#define OBJECT_INCLUDED
3/*
4*++
5*  Name:
6*     object.h
7
8*  Type:
9*     C include file.
10
11*  Purpose:
12*     Define the interface to the Object class.
13
14*  Invocation:
15*     #include "object.h"
16
17*  Description:
18*     This include file defines the interface to the Object class and
19*     provides the type definitions, function prototypes and macros,
20*     etc.  needed to use this class.
21
22*     The Object class is the base class from which all other classes
23*     in the AST library are derived. This class provides all the
24*     basic Object behaviour and Object manipulation facilities
25*     required throughout the library. There is no Object constructor,
26*     however, as Objects on their own are not of much use.
27
28*  Inheritance:
29*     The Object base class does not inherit from any other class.
30
31*  Attributes Over-Ridden:
32*     None.
33
34*  New Attributes Defined:
35*     Class (string)
36*        This is a read-only attribute containing the name of the
37*        class to which an Object belongs.
38*     ID (string)
39*        An identification string which may be used to identify the
40*        Object (e.g.) in debugging output, or when stored in an
41*        external medium such as a data file. There is no restriction
42*        on the string's contents. The default is an empty string.
43*     Ident (string)
44*        Like ID, this is an identification string which may be used
45*        to identify the Object. Unlike ID, Ident is transferred when an
46*        Object is copied.
47*     UseDefs (int)
48*        Should default values be used for unset attributes?
49*     Nobject (integer)
50*        This is a read-only attribute which gives the total number of
51*        Objects currently in existence in the same class as the
52*        Object given. It does not include Objects which belong to
53*        derived (more specialised) classes. This value is mainly
54*        intended for debugging, as it can be used to show whether
55*        Objects which should have been deleted have, in fact, been
56*        deleted.
57*     ObjSize (int)
58*        The in-memory size of the Object in bytes.
59*     RefCount (integer)
60*        This is a read-only Attribute which gives the "reference
61*        count" (the number of active pointers) associated with an
62*        Object. It is modified whenever pointers are created or
63*        annulled (by astClone or astAnnul/astEnd for example) and
64*        includes the initial pointer issued when the Object was
65*        created. If the reference count for an Object falls to zero
66*        as the result of annulling a pointer to it, then the Object
67*        will be deleted.
68
69*  Methods Over-Ridden:
70*     None.
71
72*  New Methods Defined:
73*     Public:
74*        astAnnul
75*           Annul a pointer to an Object.
76*        astClear
77*           Clear attribute values for an Object.
78*        astClone
79*           Clone a pointer to an Object.
80*        astCopy
81*           Copy an Object.
82*        astDelete
83*           Delete an Object.
84*        astExempt
85*           Exempt an Object pointer from AST context handling
86*        astExport
87*           Export an Object pointer to an outer context.
88*        astGet<X>, where <X> = C, D, F, I, L
89*           Get an attribute value for an Object.
90*        astImport
91*           Import an Object pointer into the current context.
92*        astSame
93*           Return true if two pointers refer to the same object.
94*        astSet
95*           Set attribute values for an Object.
96*        astSet<X>, where <X> = C, D, F, I, L
97*           Set an attribute value for an Object.
98*        astShow
99*           Display a textual representation of an Object on standard output.
100*        astTest
101*           Test if an attribute value is set for an Object.
102*        astTune
103*           Get or set the value of a global AST tuning parameter.
104*
105*     Protected:
106*        astAnnulId
107*           Annul an external ID for an Object (for use from protected code
108*           which must handle external IDs).
109*        astClearAttrib
110*           Clear the value of a specified attribute for an Object.
111*        astClearID
112*           Clear the value of the ID attribute for an Object.
113*        astClearIdent
114*           Clear the value of the Ident attribute for an Object.
115*        astCast
116*           Return a deep copy of an object, cast into an instance of a
117*           parent class.
118*        astDump
119*           Write an Object to a Channel.
120*        astEqual
121*           Are two Objects equivalent?
122*        astGetAttrib
123*           Get the value of a specified attribute for an Object.
124*        astGetClass (deprecated synonym astClass)
125*           Obtain the value of the Class attribute for an Object.
126*        astGetID
127*           Obtain the value of the ID attribute for an Object.
128*        astGetIdent
129*           Obtain the value of the Ident attribute for an Object.
130*        astGetNobject
131*           Obtain the value of the Nobject attribute for an Object.
132*        astGetRefCount
133*           Obtain the value of the RefCount attribute for an Object.
134*        astSetAttrib
135*           Set the value of a specified attribute for an Object.
136*        astSetCopy
137*           Declare a copy constructor for an Object.
138*        astSetDelete
139*           Declare a destructor for an Object.
140*        astSetDump
141*           Declare a dump function for an Object.
142*        astSetVtab
143*           Chaneg the virtual function table associated with an Object.
144*        astSetID
145*           Set the value of the ID attribute for an Object.
146*        astSetIdent
147*           Set the value of the Ident attribute for an Object.
148*        astTestAttrib
149*           Test if a specified attribute value is set for an Object.
150*        astTestID
151*           Test whether the ID attribute for an Object is set.
152*        astTestIdent
153*           Test whether the Ident attribute for an Object is set.
154*        astVSet
155*           Set values for an Object's attributes.
156
157*  Other Class Functions:
158*     Public:
159*        astBegin
160*           Begin a new AST context.
161*        astEnd
162*           End an AST context.
163*        astIsAObject
164*           Test class membership.
165*        astVersion
166*           Returns the AST library version number.
167*        astEscapes
168*           Remove escape sequences from returned text strings?
169*        astP2I
170*           Retrieve an int from a pointer.
171*        astI2P
172*           Pack an int into a pointer.
173*
174*     Protected:
175*        astCheckObject
176*           Validate class membership.
177*        astInitObject
178*           Initialise an Object.
179*        astInitObjectVtab
180*           Initialise the virtual function table for the Object class.
181*        astLoadObject
182*           Load an Object.
183*        astMakeId
184*           Issue an identifier for an Object.
185*        astMakePointer
186*           Obtain a true C pointer from an Object identifier.
187
188*  Macros:
189*     Public:
190*        AST__NULL
191*           Null Object pointer value.
192*        AST__VMAJOR
193*           The AST library major version number.
194*        AST__VMINOR
195*           The AST library minor version number.
196*        AST__RELEASE
197*           The AST library release number.
198*
199*     Protected:
200*        astEQUAL
201*           Compare two doubles for equality.
202*        astMAX
203*           Return maximum of two values.
204*        astMIN
205*           Return minimum of two values.
206*        astMAKE_CHECK
207*           Implement the astCheck<Class>_ function for a class.
208*        astMAKE_CLEAR
209*           Implement a method to clear an attribute value for a class.
210*        astMAKE_GET
211*           Implement a method to get an attribute value for a class.
212*        astMAKE_ISA
213*           Implement the astIsA<Class>_ function for a class.
214*        astMAKE_SET
215*           Implement a method to set an attribute value for a class.
216*        astMAKE_TEST
217*           Implement a method to test if an attribute has been set for a
218*           class.
219*        astMEMBER
220*           Locate a member function.
221
222*  Type Definitions:
223*     Public:
224*        AstObject
225*           Object type.
226*
227*     Protected:
228*        AstObjectVtab
229*           Object virtual function table type.
230
231*  Feature Test Macros:
232*     AST_CHECK_CLASS
233*        If the AST_CHECK_CLASS macro is defined, then Object class
234*        checking is enabled for all internal function invocations
235*        within the AST library. Otherwise, this checking is
236*        omitted. This macro should normally be defined as a compiler
237*        option during library development and debugging, but left
238*        undefined for software releases, so as to improve
239*        peformance. Class checking by the AST public interface is not
240*        affected by this macro.
241*     astCLASS
242*        If the astCLASS macro is undefined, only public symbols are
243*        made available, otherwise protected symbols (for use in other
244*        class implementations) are defined. This macro also affects
245*        the reporting of error context information, which is only
246*        provided for external calls to the AST library.
247*     astFORTRAN77
248*        If the astFORTRAN77 macro is defined, reporting of error
249*        context information is suppressed. This is necessary when
250*        implementing foreign language interfaces to the AST library, as
251*        otherwise the file names and line numbers given would refer
252*        to the interface implementation rather than the user's own
253*        code.
254
255*  Copyright:
256*     Copyright (C) 1997-2006 Council for the Central Laboratory of the
257*     Research Councils
258*     Copyright (C) 2010 Science & Technology Facilities Council.
259*     All Rights Reserved.
260
261*  Licence:
262*     This program is free software: you can redistribute it and/or
263*     modify it under the terms of the GNU Lesser General Public
264*     License as published by the Free Software Foundation, either
265*     version 3 of the License, or (at your option) any later
266*     version.
267*
268*     This program is distributed in the hope that it will be useful,
269*     but WITHOUT ANY WARRANTY; without even the implied warranty of
270*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
271*     GNU Lesser General Public License for more details.
272*
273*     You should have received a copy of the GNU Lesser General
274*     License along with this program.  If not, see
275*     <http://www.gnu.org/licenses/>.
276
277*  Authors:
278*     RFWS: R.F. Warren-Smith (Starlink)
279*     DSB: David S. Berry (Starlink)
280
281*  History:
282*     30-JAN-1996 (RFWS):
283*        Original version.
284*     19-APR-1996 (RFWS):
285*        Added macros for implementing attribute access methods.
286*     3-JUL-1996 (RFWS):
287*        Added new definitions to support the external interface.
288*     10-SEP-1996 (RFWS):
289*        Added loader and related facilities.
290*     30-MAY-1997 (RFWS):
291*        Add the ID attribute.
292*     14-JUL-1997 (RFWS):
293*        Add astExempt function.
294*     20-JAN-1998 (RFWS):
295*        Make the astClear and astVSet methods virtual.
296*     15-SEP-1999 (RFWS):
297*        Made the astAnnulId function accessible to protected code.
298*     3-APR-2001 (DSB):
299*        Added Ident attribute.
300*     8-JAN-2003 (DSB):
301*        Added protected astInitObjectVtab method.
302*     30-APR-2003 (DSB):
303*        Added macros AST__VMAJOR, AST__VMINOR and AST__RELEASE.
304*        Added astVersion function.
305*     7-FEB-2004 (DSB):
306*        Added astEscapes function.
307*     11-MAR-2005 (DSB):
308*        Added UseDefs attribute.
309*     7-FEB-2006 (DSB):
310*        Added astTune function.
311*     14-FEB-2006 (DSB):
312*        Added ObjSize attribute.
313*     23-FEB-2006 (DSB):
314*        Moved AST__TUNULL from this file to memory.h.
315*     10-MAY-2006 (DSB):
316*        Added astEQUAL, astMAX and astMIN.
317*     26-MAY-2006 (DSB):
318*        Make all system includes unconditional, so that makeh is not
319*        confused when creating ast.h.
320*     22-JUN-2007 (DSB):
321*        - Make astVSet return a pointer to dynamic memory holding the
322*        expanded setting string.
323*        - Add ast astSetVtab and astCast.
324*     22-APR-2008 (DSB):
325*        Added astSame.
326*     7-APR-2010 (DSB):
327*        Added astHasAttribute.
328*--
329*/
330
331/* Include files. */
332/* ============== */
333/* Configuration results. */
334/* ---------------------- */
335#if HAVE_CONFIG_H
336#include <config.h>
337#endif
338
339/* Interface definitions. */
340/* ---------------------- */
341#include "error.h"               /* Error reporting facilities */
342#include "version.h"             /* Version number macros */
343
344/* C header files. */
345/* --------------- */
346#include <stddef.h>
347#include <stdarg.h>
348#include <float.h>
349#include <stdio.h>
350
351#if defined(THREAD_SAFE)
352#include <pthread.h>
353#endif
354
355/* Macros. */
356/* ======= */
357#if defined(astCLASS) || defined(astFORTRAN77)
358#define STATUS_PTR status
359#else
360#define STATUS_PTR astGetStatusPtr
361#endif
362
363/* Define a dummy __attribute__ macro for use on non-GNU compilers. */
364#ifndef __GNUC__
365#  define  __attribute__(x)  /*NOTHING*/
366#endif
367
368/* Set to "1" (yes) or "0" (no) to indicate if AST was build with threads
369   support. */
370#define AST__THREADSAFE @THREADS@
371
372#if defined(astCLASS )
373#define AST__GETATTRIB_BUFF_LEN 50 /* Length of string returned by GetAttrib. */
374#define AST__ASTGETC_MAX_STRINGS 50 /* Number of string values to buffer within astGetC */
375
376/* Values supplied to astManageLock */
377#define AST__LOCK 1      /* Lock the object */
378#define AST__UNLOCK 2    /* Unlock the object */
379#define AST__CHECKLOCK 3 /* Check if the object is locked */
380
381/* Values returned by astThread */
382#define AST__UNLOCKED 1  /* Object is unlocked */
383#define AST__RUNNING 2   /* Object is locked by the running thread */
384#define AST__OTHER 3     /* Object is locked by another thread */
385
386#endif
387
388/* Value that indicates that two classes are not in direct line from each
389   other. */
390#if defined(astCLASS )
391#define AST__COUSIN -1000000
392#endif
393
394/*
395*+
396*  Name:
397*     astINVOKE
398
399*  Type:
400*     Protected macro.
401
402*  Purpose:
403*     Invoke an AST function.
404
405*  Synopsis:
406*     #include "object.h"
407*     astINVOKE(rettype,function)
408
409*  Class Membership:
410*     Defined by the Object class.
411
412*  Description:
413*     This macro expands to an invocation of an AST function, together
414*     with any additional actions required to support it.  The actual
415*     expansion depends on whether the macro is expanded in internal
416*     code (astCLASS defined) or external code (astCLASS undefined)
417*     and it therefore hides the differences between these two
418*     interfaces.
419
420*  Parameters:
421*     rettype
422*        A character to indicate the type of result returned by the function:
423*
424*        V
425*           The function returns a value (including void or a pointer
426*           value, but excluding an Object pointer). astINVOKE will
427*           return the value unchanged.
428*        O
429*           The function returns an Object pointer. astINVOKE will
430*           convert it to an Object identifier if necessary.
431*        F
432*           The function returns a function pointer. astINVOKE will
433*           return it unchanged. This is typically used when the
434*           function has a variable argument list. In this case the
435*           function name is passed to astINVOKE without its argument
436*           list and a pointer to the function is returned which can
437*           then be supplied with an argument list. This avoids the
438*           need to define a macro with a variable number of arguments
439*           (which isn't allowed).
440*     function
441*        A normal invocation of the function returning the required
442*        result.  In the case of a variable argument list, the
443*        argument list should be omitted so that the function is not
444*        invoked but a function pointer is returned that may then be
445*        used to invoke it.
446
447*  Examples:
448*     #define astGetNobject(this) \
449*             astINVOKE(V,astGetNobject_(astCheckObject(this)))
450*        Defines a macro to invoke the astGetNobject_ function which
451*        returns an int.
452*     #define astClone(this) \
453*             astINVOKE(O,astClone_(astCheckObject(this)))
454*        Defines a macro to invoke the astClone_ function which
455*        returns an Object pointer.
456*     #define astSet astINVOKE(F,astSet_)
457*        Defines a macro to invoke the astSet_ function which has a
458*        variable argument list and returns void. The macro result is
459*        a pointer to the astSet_ function. This function must perform
460*        its own argument validation, as (e.g) astCheckObject cannot
461*        be invoked on its arguments via a macro.
462
463*  Notes:
464*     - To avoid problems with some compilers, you should not leave
465*     any white space around the macro arguments.
466*-
467*/
468
469/* Define astINVOKE, which records the current file and line number
470   (in case of error) using astAt, and then invokes the function
471   supplied as an argument of the astRetV_, astRetO_ or astRetF_
472   macro.
473
474   Suppress reporting of the file and line number from internal code
475   and from foreign language interfaces by not using astAt in these
476   cases. */
477#if defined(astCLASS) || defined(astFORTRAN77)
478#define astINVOKE(rettype,function) astRet##rettype##_(function)
479#else
480#define astINVOKE(rettype,function) \
481astERROR_INVOKE(astRet##rettype##_(function))
482#endif
483
484/* astRetF_ and astRetV_ currently do nothing. */
485#define astRetF_(x) (x)
486#define astRetV_(x) (x)
487
488/* However, astRetO_ converts a pointer to an ID if necessary. */
489#if defined(astCLASS)
490#define astRetO_(x) ((void *)(x))
491#else
492#define astRetO_(x) ((void *)astMakeId_((AstObject *)(x),STATUS_PTR))
493#endif
494
495/*
496*+
497*  Name:
498*     astINVOKE_CHECK
499*     astINVOKE_ISA
500
501*  Type:
502*     Protected macros.
503
504*  Purpose:
505*     Invoke the astCheck<Class>_ and astIsA<Class>_ functions.
506
507*  Synopsis:
508*     #include "object.h"
509*     astINVOKE_CHECK(class,this,force)
510*     astINVOKE_ISA(class,this)
511
512*  Class Membership:
513*     Defined by the Object class.
514
515*  Description:
516*     These macros expand to invocations of the standard
517*     astCheck<Class>_ and astIsA<Class>_ functions for a class.
518
519*  Parameters:
520*     class
521*        The name (not the type) of the class for which the function
522*        is to be invoked.
523*     this
524*        The "this" argument (the Object pointer) to be passed to the
525*        function.
526*     force
527*        Type checking takes time, and so can be disabled within the
528*        protected context in order to save time. Setting "force" to
529*        zero causes the astINVOKE_CHECK macro to skip the class check
530*        in a protected context (it assumes that AST "knows what it is
531*        doing"). Setting "force" to a non-zero value forces the class
532*        check even in a protected context.
533
534*  Notes:
535*     - To avoid problems with some compilers, you should not leave
536*     any white space around the macro arguments.
537*-
538*/
539
540/* For the public interface (and also internally if AST_CHECK_CLASS is
541   defined), define astINVOKE_CHECK to invoke the astCheck<Class>
542   function. */
543#if !defined(astCLASS) || defined(AST_CHECK_CLASS)
544#define astINVOKE_CHECK(class,this,force) \
545astCheck##class##_((Ast##class *)astEnsurePointer_(this),astGetStatusPtr)
546
547/* For the internal interface, astINVOKE_CHECK omits the
548   astCheck<class> function (unless AST_CHECK_CLASS is defined). */
549#else
550
551#define astINVOKE_CHECK(class,this,force) ( (force) ? \
552   ( astCheck##class##_((Ast##class *)astEnsurePointer_(this),astGetStatusPtr) ) : \
553   ( (Ast##class *) astEnsurePointer_(this) ) )
554
555#endif
556
557/* Define astINVOKE_ISA to invoke the astIsA<Class> function. */
558#if defined(astCLASS)            /* Protected */
559#define astINVOKE_ISA(class,this) \
560astIsA##class##_((const Ast##class *)(this),status)
561#else                            /* Public */
562#define astINVOKE_ISA(class,this) \
563astINVOKE(V,astIsA##class##_((const Ast##class *)astEnsurePointer_(this),astGetStatusPtr))
564#endif
565
566/* The astEnsurePointer_ macro ensures a true C pointer, converting
567   from an ID if necessary. */
568#if defined(astCLASS)            /* Protected */
569#define astEnsurePointer_(x) ((void *)(x))
570#else                            /* Public */
571#define astEnsurePointer_(x) ((void *)astCheckLock_(astMakePointer_((AstObject *)(x),STATUS_PTR),STATUS_PTR))
572#endif
573
574#if defined(astCLASS)            /* Protected */
575/*
576*+
577*  Name:
578*     astMAKE_CHECK
579
580*  Type:
581*     Protected macro.
582
583*  Purpose:
584*     Implement the astCheck<Class>_ function for a class.
585
586*  Synopsis:
587*     #include "object.h"
588*     astMAKE_CHECK(class)
589
590*  Class Membership:
591*     Defined by the Object class.
592
593*  Description:
594*     This macro expands to an implementation of the public astCheck<Class>_
595*     function (q.v.) which validates membership of a specified class.
596
597*  Parameters:
598*     class
599*        The name (not the type) of the class whose membership is to be
600*        validated.
601
602*  Notes:
603*     -  This macro is provided so that class definitions can easiy
604*     implement the astCheck<Class>_ function, which is essentially the same
605*     for each class apart for a change of name.
606*     -  To avoid problems with some compilers, you should not leave any white
607*     space around the macro arguments.
608*-
609*/
610
611#ifndef MEM_DEBUG
612
613/* Define the macro. */
614#define astMAKE_CHECK(class) \
615\
616/* Declare the function (see the object.c file for a prologue). */ \
617Ast##class *astCheck##class##_( Ast##class *this, int *status ) { \
618\
619/* Check the inherited error status. */ \
620   if ( !astOK ) return this; \
621\
622/* Check if the object is a class member. */ \
623   if ( !astIsA##class( this ) ) { \
624\
625/* If not, but the pointer was valid (which means it identifies an Object \
626   of some sort), then report more information about why this Object is \
627   unsuitable. */ \
628      if ( astOK ) { \
629         astError( AST__OBJIN, "Pointer to " #class " required, but pointer " \
630                   "to %s given.", status, astGetClass( this ) ); \
631      } \
632   } \
633\
634/* Return the pointer value supplied. */ \
635   return this; \
636}
637
638/* Define the macro with memory debugging facilities. */
639#else
640
641#define astMAKE_CHECK(class) \
642\
643/* Declare the function (see the object.c file for a prologue). */ \
644Ast##class *astCheck##class##_( Ast##class *this, int *status ) { \
645\
646   char buf[100]; \
647\
648/* Check the inherited error status. */ \
649   if ( !astOK ) return this; \
650\
651/* Check if the object is a class member. */ \
652   if ( !astIsA##class( this ) ) { \
653\
654/* If not, but the pointer was valid (which means it identifies an Object \
655   of some sort), then report more information about why this Object is \
656   unsuitable. */ \
657      if ( astOK ) { \
658         astError( AST__OBJIN, "Pointer to " #class " required, but pointer " \
659                   "to %s given.", status, astGetClass( this ) ); \
660      }\
661\
662   } else { \
663\
664/* Call the astMemoryUse function to report it if the memory block is \
665   being watched. */ \
666      sprintf( buf, "checked (refcnt: %d)", astGetRefCount_( (AstObject *) this, status ) ); \
667      astMemoryUse( this, buf ); \
668   } \
669\
670/* Return the pointer value supplied. */ \
671   return this; \
672}
673#endif
674#endif
675
676#if defined(astCLASS)            /* Protected */
677/*
678*+
679*  Name:
680*     astMAKE_CLEAR
681
682*  Purpose:
683*     Implement a method to clear an attribute value for a class.
684
685*  Type:
686*     Protected macro.
687
688*  Synopsis:
689*     #include "object.h"
690*     astMAKE_CLEAR(class,attribute,component,assign)
691
692*  Class Membership:
693*     Defined by the Object class.
694
695*  Description:
696*     This macro expands to an implementation of a private member function of
697*     the form:
698*
699*        static void Clear<Attribute>( Ast<Class> *this )
700*
701*     and an external interface function of the form:
702*
703*        void astClear<Attribute>_( Ast<Class> *this )
704*
705*     which implement a method for clearing a specified attribute value for
706*     a class.
707
708*  Parameters:
709*     class
710*        The name (not the type) of the class to which the attribute belongs.
711*     attribute
712*        The name of the attribute to be cleared, as it appears in the function
713*        name (e.g. Label in "astClearLabel").
714*     component
715*        The name of the class structure component that holds the attribute
716*        value.
717*     assign
718*        An expression that evaluates to the value to assign to the component
719*        to clear its value.
720
721*  Examples:
722*     astMAKE_CLEAR(MyStuff,Flag,flag,-1)
723*        Implements the astClearFlag method for the MyStuff class which
724*        operates by setting the "flag" structure component to -1 to indicate
725*        that it has no value.
726
727*  Notes:
728*     -  To avoid problems with some compilers, you should not leave any white
729*     space around the macro arguments.
730*-
731*/
732
733/* Define the macro. */
734#define astMAKE_CLEAR(class,attribute,component,assign) \
735\
736/* Private member function. */ \
737/* ------------------------ */ \
738static void Clear##attribute( Ast##class *this, int *status ) { \
739\
740/* Check the inherited error status. */ \
741   if ( !astOK ) return; \
742\
743/* Assign the "clear" value. */ \
744   this->component = (assign); \
745} \
746\
747/* External interface. */ \
748/* ------------------- */ \
749void astClear##attribute##_( Ast##class *this, int *status ) { \
750\
751/* Check the inherited error status. */ \
752   if ( !astOK ) return; \
753\
754/* Invoke the required method via the virtual function table. */ \
755   (**astMEMBER(this,class,Clear##attribute))( this, status ); \
756}
757#endif
758
759#if defined(astCLASS)            /* Protected */
760/*
761*+
762*  Name:
763*     astMAKE_GET
764
765*  Purpose:
766*     Implement a method to get an attribute value for a class.
767
768*  Type:
769*     Protected macro.
770
771*  Synopsis:
772*     #include "object.h"
773*     astMAKE_GET(class,attribute,type,bad_value,assign)
774
775*  Class Membership:
776*     Defined by the Object class.
777
778*  Description:
779*     This macro expands to an implementation of a private member function of
780*     the form:
781*
782*        static <Type> Get<Attribute>( Ast<Class> *this )
783*
784*     and an external interface function of the form:
785*
786*        <Type> astGet<Attribute>_( Ast<Class> *this )
787*
788*     which implement a method for getting a specified attribute value for a
789*     class.
790
791*  Parameters:
792*     class
793*        The name (not the type) of the class to which the attribute belongs.
794*     attribute
795*        The name of the attribute whose value is to be obtained, as it
796*        appears in the function name (e.g. Label in "astGetLabel").
797*     type
798*        The C type of the attribute.
799*     bad_value
800*        A constant value to return if the inherited error status is set, or if
801*        the function fails.
802*     assign
803*        An expression that evaluates to the value to be returned.
804
805*  Examples:
806*     astMAKE_GET(MyStuff,Flag,int,0,( this->flag == 1 ))
807*        Implements the astGetFlag method for the MyStuff class which operates
808*        by examining the integer "flag" structure component and comparing it
809*        with the value 1 to see if it is set. A value of 0 is returned if the
810*        method fails to complete successfully.
811
812*  Notes:
813*     -  To avoid problems with some compilers, you should not leave any white
814*     space around the macro arguments.
815*-
816*/
817
818/* Define the macro. */
819#define astMAKE_GET(class,attribute,type,bad_value,assign) \
820\
821/* Private member function. */ \
822/* ------------------------ */ \
823static type Get##attribute( Ast##class *this, int *status ) { \
824   type result;                  /* Result to be returned */ \
825\
826/* Check the inherited error status. */ \
827   if ( !astOK ) return (bad_value); \
828\
829/* Assign the result value. */ \
830   result = (assign); \
831\
832/* Check for errors and clear the result if necessary. */ \
833   if ( !astOK ) result = (bad_value); \
834\
835/* Return the result. */ \
836   return result; \
837} \
838/* External interface. */ \
839/* ------------------- */  \
840type astGet##attribute##_( Ast##class *this, int *status ) { \
841\
842/* Check the inherited error status. */ \
843   if ( !astOK ) return (bad_value); \
844\
845/* Invoke the required method via the virtual function table. */ \
846   return (**astMEMBER(this,class,Get##attribute))( this, status ); \
847}
848#endif
849
850#if defined(astCLASS)            /* Protected */
851/*
852*+
853*  Name:
854*     astMAKE_ISA
855
856*  Type:
857*     Protected macro.
858
859*  Purpose:
860*     Implement the astIsA<Class>_ function for a class.
861
862*  Synopsis:
863*     #include "object.h"
864*     astMAKE_ISA(class,parent)
865
866*  Class Membership:
867*     Defined by the Object class.
868
869*  Description:
870*     This macro expands to an implementation of the public
871*     astIsA<Class>_ function (q.v.) which checks membership of a
872*     specified class.
873
874*  Parameters:
875*     class
876*        The name (not the type) of the class whose membership is to be
877*        tested.
878*     parent
879*        The name of the parent class.
880
881*  Notes:
882*     - This macro is provided so that class definitions can easiy
883*     implement the astIsA<Class>_ function, which is essentially the
884*     same for each class apart for a change of name.
885*     - To avoid problems with some compilers, you should not leave
886*     any white space around the macro arguments.
887*-
888*/
889
890/* Define the macro. */
891#define astMAKE_ISA(class,parent) \
892\
893/* Declare the function (see the object.c file for a prologue). */ \
894int astIsA##class##_( const Ast##class *this, int *status ) { \
895\
896/* Local Variables: */ \
897   int isa = 0;                  /* Is object a member? */ \
898\
899/* To test if the object is correctly constructed, we first test if it is a \
900   member of the parent class. This improves the security of the test by \
901   checking the object structure from the base Object class downwards \
902   (without this, the "magic numbers" that identify classes might be \
903   encountered by accident or we might address parts of the Object which \
904   don't exist). */ \
905   if ( astIsA##parent( this ) ) { \
906\
907/* Obtain the Object's size and check it is adequate for an object of the \
908   proposed type (this avoids any attempt to access derived class data that \
909   doesn't exist and therefore lies outside the memory allocated for the \
910   object). */ \
911      if ( ( (AstObject *) this )->size >= sizeof( Ast##class ) ) { \
912\
913/* If OK, see whether the check component in the object's virtual function \
914   table matches the expected "magic" value. */ \
915         isa = ( *astMEMBER(this,class,id.check) == &class_check ); \
916      } \
917   } \
918\
919/* Return the result. */ \
920   return isa; \
921}
922#endif
923
924#if defined(astCLASS)            /* Protected */
925/*
926*+
927*  Name:
928*     astMAKE_SET
929
930*  Purpose:
931*     Implement a method to set an attribute value for a class.
932
933*  Type:
934*     Protected macro.
935
936*  Synopsis:
937*     #include "object.h"
938*     astMAKE_SET(class,attribute,type,component,assign)
939
940*  Class Membership:
941*     Defined by the Object class.
942
943*  Description:
944*     This macro expands to an implementation of a private member function of
945*     the form:
946*
947*        static void Set<Attribute>( Ast<Class> *this, <Type> value )
948*
949*     and an external interface function of the form:
950*
951*        void astSet<Attribute>_( Ast<Class> *this, <Type> value )
952*
953*     which implement a method for setting a specified attribute value for a
954*     class.
955
956*  Parameters:
957*      class
958*         The name (not the type) of the class to which the attribute belongs.
959*      attribute
960*         The name of the attribute to be set, as it appears in the function
961*         name (e.g. Label in "astSetLabel").
962*      type
963*         The C type of the attribute.
964*      component
965*         The name of the class structure component that holds the attribute
966*         value.
967*      assign
968*         An expression that evaluates to the value to be assigned to the
969*         component.
970
971*  Examples:
972*     astMAKE_SET(MyStuff,Flag,int,flag,( value != 0 ))
973*        Implements the astSetFlag method for the MyStuff class which operates
974*        by setting the "flag" structure component to 0 or 1 depending on
975*        whether the "value" parameter is non-zero or not.
976
977*  Notes:
978*     - To avoid problems with some compilers, you should not leave
979*     any white space around the macro arguments.
980*-
981*/
982
983/* Define the macro. */
984#define astMAKE_SET(class,attribute,type,component,assign) \
985\
986/* Private member function. */ \
987/* ------------------------ */ \
988static void Set##attribute( Ast##class *this, type value, int *status ) { \
989\
990/* Check the inherited error status. */ \
991   if ( !astOK ) return; \
992\
993/* Store the new value in the structure component. */ \
994   this->component = (assign); \
995} \
996\
997/* External interface. */ \
998/* ------------------- */ \
999void astSet##attribute##_( Ast##class *this, type value, int *status ) { \
1000\
1001/* Check the inherited error status. */ \
1002   if ( !astOK ) return; \
1003\
1004/* Invoke the required method via the virtual function table. */ \
1005   (**astMEMBER(this,class,Set##attribute))( this, value, status ); \
1006}
1007#endif
1008
1009#if defined(astCLASS)            /* Protected */
1010/*
1011*+
1012*  Name:
1013*     astMAKE_TEST
1014
1015*  Purpose:
1016*     Implement a method to test if an attribute has been set for a class.
1017
1018*  Type:
1019*     Protected macro.
1020
1021*  Synopsis:
1022*     #include "object.h"
1023*     astMAKE_TEST(class,attribute,assign)
1024
1025*  Class Membership:
1026*     Defined by the Object class.
1027
1028*  Description:
1029*     This macro expands to an implementation of a private member function of
1030*     the form:
1031*
1032*        static int Test<Attribute>( Ast<Class> *this )
1033*
1034*     and an external interface function of the form:
1035*
1036*        int astTest<Attribute>_( Ast<Class> *this )
1037*
1038*     which implement a method for testing if a specified attribute has been
1039*     set for a class.
1040
1041*  Parameters:
1042*      class
1043*         The name (not the type) of the class to which the attribute belongs.
1044*      attribute
1045*         The name of the attribute to be tested, as it appears in the function
1046*         name (e.g. Label in "astTestLabel").
1047*      assign
1048*         An expression that evaluates to 0 or 1, to be used as the returned
1049*         value.
1050
1051*  Examples:
1052*     astMAKE_TEST(MyStuff,Flag,( this->flag != -1 ))
1053*        Implements the astTestFlag method for the MyStuff class which operates
1054*        by testing the "flag" structure component to see if it is set to a
1055*        value other than -1.
1056
1057*  Notes:
1058*     -  To avoid problems with some compilers, you should not leave any white
1059*     space around the macro arguments.
1060*-
1061*/
1062
1063/* Define the macro. */
1064#define astMAKE_TEST(class,attribute,assign) \
1065\
1066/* Private member function. */ \
1067/* ------------------------ */ \
1068static int Test##attribute( Ast##class *this, int *status ) { \
1069   int result;                   /* Value to return */ \
1070\
1071/* Check the inherited error status. */ \
1072   if ( !astOK ) return 0; \
1073\
1074/* Assign the result value. */ \
1075   result = (assign); \
1076\
1077/* Check for errors and clear the result if necessary. */ \
1078   if ( !astOK ) result = 0; \
1079\
1080/* Return the result. */ \
1081   return result; \
1082} \
1083/* External interface. */ \
1084/* ------------------- */ \
1085int astTest##attribute##_( Ast##class *this, int *status ) { \
1086\
1087/* Check the inherited error status. */ \
1088   if ( !astOK ) return 0; \
1089\
1090/* Invoke the required method via the virtual function table. */ \
1091   return (**astMEMBER(this,class,Test##attribute))( this, status ); \
1092}
1093#endif
1094
1095#if defined(astCLASS)            /* Protected */
1096/*
1097*+
1098*  Name:
1099*     astMEMBER
1100
1101*  Purpose:
1102*     Locate a member function.
1103
1104*  Type:
1105*     Protected macro.
1106
1107*  Synopsis:
1108*     #include "object.h"
1109*     astMEMBER(this,class,method)
1110
1111*  Class Membership:
1112*     Defined by the Object class.
1113
1114*  Description:
1115*     This macro evaluates to the address where the pointer to a
1116*     specified Object member function is stored. Typically, this will
1117*     be used to obtain a pointer to the member function so that it
1118*     can be invoked. It may also be used to assign a new function
1119*     pointer so that a derived class can re-define a virtual function
1120*     and hence over-ride an inherited method.
1121
1122*  Parameters:
1123*     this
1124*        Pointer to an Object belonging to the class for which the
1125*        virtual function is required. This must either be the class
1126*        that originally defined the method, or one derived from it.
1127*     class
1128*        Name of the class that originally defined the method. This
1129*        may differ from (i.e. be an ancestor of) the class to which
1130*        "this" belongs.
1131*     method
1132*        Name of the method whose member function is to be located.
1133
1134*  Returned Value:
1135*     The address where the member function pointer is stored (the
1136*     type of the result is determined by the type of the member
1137*     function itself).
1138
1139*  Examples:
1140*     astMEMBER(this,Gnome,astFish)
1141*        Returns the address where the pointer to the function that
1142*        implements the astFish method for the "this" object is
1143*        stored. The Gnome class should be where the astFish method
1144*        was first defined (i.e. from where it was inherited by
1145*        "this").
1146*     (**astMEMBER(this,Gnome,astFish))( this, arg1, arg2 );
1147*        Invokes the virtual function that implements the astFish
1148*        method for object "this" and passes it additional arguments
1149*        "arg2" and "arg2".  Again, Gnome should be the class that
1150*        originally defined the astFish method.
1151*     *astMEMBER(this,Gnome,astFish) = myFish;
1152*        Stores a pointer to the myFish function so that it replaces
1153*        the virtual function that previously implemented the astFish
1154*        method for the "this" object. Note that all objects in the
1155*        same class as "this" are affected, but objects in class
1156*        "class" are not affected (unless it happens to be the class
1157*        to which "this" belongs).
1158
1159*  Notes:
1160*     - To avoid problems with some compilers, you should not leave
1161*     any white space around the macro arguments.
1162*-
1163*/
1164
1165/* A subsiduary macro that returns a pointer to the vtab of an object,
1166   cast to an AstObjectVtab. */
1167#define astVTAB(this) (((AstObject*)(this))->vtab)
1168
1169/* Define the macro. This functions by (a) casting the Object pointer
1170   to type (AstObject *) and locating the Object's virtual function
1171   table (b) casting the table pointer to the correct type
1172   (AstClassVtab *) for the class in which the method pointer resides,
1173   (c) locating the component holding the member function pointer, and
1174   (d) taking its address. */
1175#define astMEMBER(this,class,method) \
1176(&((Ast##class##Vtab*)astVTAB(this))->method)
1177
1178#endif
1179
1180/*
1181*+
1182*  Name:
1183*     astPROTO_CHECK
1184*     astPROTO_ISA
1185
1186*  Type:
1187*     Protected macros.
1188
1189*  Purpose:
1190*     Prototype the astCheck<Class>_ and astIsA<Class>_ functions.
1191
1192*  Synopsis:
1193*     #include "object.h"
1194*     astPROTO_CHECK(class)
1195*     astPROTO_ISA(class)
1196
1197*  Class Membership:
1198*     Defined by the Object class.
1199
1200*  Description:
1201*     These macros expands to function prototypes for the
1202*     astCheck<Class>_ and astIsA<Class>_ functions (q.v.) which
1203*     validate and test for membership of a specified class.
1204
1205*  Parameters:
1206*     class
1207*        The name (not the type) of the class whose membership is to
1208*        be validated.
1209
1210*  Notes:
1211*     - To avoid problems with some compilers, you should not leave
1212*     any white space around the macro arguments.
1213*-
1214*/
1215
1216/* Define the macros. */
1217#define astPROTO_CHECK(class) Ast##class *astCheck##class##_( Ast##class *, int * );
1218#define astPROTO_ISA(class) int astIsA##class##_( const Ast##class *, int * );
1219
1220/* Macros which return the maximum and minimum of two values. */
1221#define astMAX(aa,bb) ((aa)>(bb)?(aa):(bb))
1222#define astMIN(aa,bb) ((aa)<(bb)?(aa):(bb))
1223
1224/* Check for equality of floating point values. We cannot compare bad values
1225   directly because of the danger of floating point exceptions, so bad
1226   values are dealt with explicitly. */
1227#define astEQUAL(aa,bb) (((aa)==AST__BAD)?(((bb)==AST__BAD)?1:0):(((bb)==AST__BAD)?0:(fabs((aa)-(bb))<=1.0E5*astMAX((fabs(aa)+fabs(bb))*DBL_EPSILON,DBL_MIN))))
1228
1229/* AST__NULL. */
1230/* ---------- */
1231/* Define the AST__NULL macro, which evaluates to a null Object
1232   pointer. */
1233#define AST__NULL (astI2P(0))
1234
1235
1236#if defined(astCLASS)            /* Protected */
1237
1238/* Test the validy of an attribute value  */
1239/* -------------------------------------  */
1240/* If the set attribute value is invalid, clear it. These macros should
1241   be used in a context in which error reporting has been deferred by
1242   calling astReporting( 0 ). */
1243
1244#define astCLEAN_ATTRIB(attr) \
1245   if( astTest##attr(this) ) { \
1246      astSet##attr( this, astGet##attr( this ) ); \
1247      if( !astOK ) { \
1248         astClearStatus; \
1249         astClear##attr( this ); \
1250      } \
1251   }
1252
1253#define astCLEAN_INDEXED_ATTRIB(attr,index) \
1254   if( astTest##attr(this,index) ) { \
1255      astSet##attr( this, index, astGet##attr( this, index ) ); \
1256      if( !astOK ) { \
1257         astClearStatus; \
1258         astClear##attr( this, index ); \
1259      } \
1260   }
1261
1262#endif
1263
1264
1265#if defined(astCLASS)            /* Protected */
1266#define astSetVtabClassIdentifier(vtab,id_ptr) \
1267   ((AstObjectVtab *)(vtab))->top_id = (id_ptr)
1268#endif
1269
1270/* Type Definitions. */
1271/* ================= */
1272
1273/* Object structure. */
1274/* ----------------- */
1275/* This structure contains all information that is unique to each object in
1276   the class (e.g. its instance variables). */
1277typedef struct AstObject {
1278
1279/* Attributes specific to objects in this class. */
1280   unsigned long check;          /* Check value to identify Objects */
1281   size_t size;                  /* Amount of memory used by Object */
1282   struct AstObjectVtab *vtab;   /* Pointer to virtual function table */
1283   char dynamic;                 /* Memory allocated dynamically? */
1284   int ref_count;                /* Number of active pointers to the Object */
1285   char *id;                     /* Pointer to ID string */
1286   char *ident;                  /* Pointer to Ident string */
1287   char usedefs;                 /* Use default attribute values? */
1288   int iref;                     /* Object index (unique within class) */
1289   void *proxy;                  /* A pointer to an external object that
1290                                    acts as a foreign language proxy for the
1291                                    AST object */
1292#if defined(THREAD_SAFE)
1293   int locker;                   /* Thread that has locked this Object */
1294   pthread_mutex_t mutex1;       /* Guards access to all elements of the
1295                                    Object except for the "locker" and
1296                                    "ref_count" components */
1297   pthread_mutex_t mutex2;       /* Guards access to the "locker" and
1298                                    "ref_count" components */
1299   struct AstGlobals *globals;   /* Pointer to thread-specific global data */
1300#endif
1301
1302} AstObject;
1303
1304/* Class identifier structure */
1305typedef struct AstClassIdentifier {
1306   int *check;
1307   struct AstClassIdentifier *parent;
1308} AstClassIdentifier;
1309
1310/* Virtual function table. */
1311/* ----------------------- */
1312/* The virtual function table makes a forward reference to the
1313   AstChannel structure which is not defined until "channel.h" is
1314   included (below). Hence make a preliminary definition available
1315   now. */
1316struct AstChannel;
1317
1318/* This table contains all information that is the same for all
1319   objects in the class (e.g. pointers to its virtual functions). */
1320#if defined(astCLASS)            /* Protected */
1321typedef struct AstObjectVtab {
1322
1323/* A unique identifier for this class. */
1324   AstClassIdentifier id;
1325
1326/* Pointer to the structure that identifies the top-level class described
1327   by the whole vtab (of which the AstObjectVtab is just the first,
1328   lowest-level, component). */
1329   AstClassIdentifier *top_id;
1330
1331/* Pointer to a dynamically allocated string holding the default
1332   attribute values to use when creating new objects. These are read from
1333   environment variables of the form "<CLASSNAME>_OPTIONS". */
1334   const char *defaults;
1335
1336/* Properties specific to this class. */
1337   void ( *CleanAttribs )( AstObject *, int * );
1338   AstObject *( *Cast )( AstObject *, AstObject *, int * );
1339   const char *( *GetID )( AstObject *, int * );
1340   const char *( *GetIdent )( AstObject *, int * );
1341   const char *(* GetAttrib)( AstObject *, const char *, int * );
1342   int (* TestAttrib)( AstObject *, const char *, int * );
1343   int (* TestID)( AstObject *, int * );
1344   int (* Same)( AstObject *, AstObject *, int * );
1345   int (* HasAttribute)( AstObject *, const char *, int * );
1346   int (* TestIdent)( AstObject *, int * );
1347   void (* Clear)( AstObject *, const char *, int * );
1348   void (* ClearAttrib)( AstObject *, const char *, int * );
1349   void (* ClearID)( AstObject *, int * );
1350   void (* ClearIdent)( AstObject *, int * );
1351   void (* Dump)( AstObject *, struct AstChannel *, int * );
1352   int (* Equal)( AstObject *, AstObject *, int * );
1353   void (* SetAttrib)( AstObject *, const char *, int * );
1354   void (* SetID)( AstObject *, const char *, int * );
1355   void (* SetIdent)( AstObject *, const char *, int * );
1356   void (* Show)( AstObject *, int * );
1357   void (* VSet)( AstObject *, const char *, char **, va_list, int * );
1358   void (* EnvSet)( AstObject *, int * );
1359
1360   void *(* GetProxy)( AstObject *, int * );
1361   void (* SetProxy)( AstObject *, void *, int * );
1362
1363   int (* GetObjSize)( AstObject *, int * );
1364
1365   int (* TestUseDefs)( AstObject *, int * );
1366   int (* GetUseDefs)( AstObject *, int * );
1367   void (* SetUseDefs)( AstObject *, int, int * );
1368   void (* ClearUseDefs)( AstObject *, int * );
1369
1370   const char *class;            /* Pointer to class name string */
1371   void (** delete)( AstObject *, int * ); /* Pointer to array of destructors */
1372   void (** copy)( const AstObject *, AstObject *, int * ); /* Copy constructors */
1373   void (** dump)( AstObject *, struct AstChannel *, int * ); /* Dump functions */
1374   const char **dump_class;      /* Dump function class string pointers */
1375   const char **dump_comment;    /* Dump function comment string pointers */
1376   int ndelete;                  /* Number of destructors */
1377   int ncopy;                    /* Number of copy constructors */
1378   int ndump;                    /* Number of dump functions */
1379   int nobject;                  /* Number of active objects in the class */
1380   int nfree;                    /* No. of entries in "free_list" */
1381   AstObject **free_list;        /* List of pointers for freed Objects */
1382
1383#if defined(THREAD_SAFE)
1384   int (* ManageLock)( AstObject *, int, int, AstObject **, int * );
1385#endif
1386
1387} AstObjectVtab;
1388#endif
1389
1390#if defined(THREAD_SAFE) && defined(astCLASS)
1391
1392/* Define a structure holding all data items that are global within the
1393   object.c file. */
1394
1395typedef struct AstObjectGlobals {
1396   AstObjectVtab Class_Vtab;
1397   int Class_Init;
1398   int Retain_Esc;
1399   int Context_Level;
1400   int *Active_Handles;
1401   char GetAttrib_Buff[ AST__GETATTRIB_BUFF_LEN + 1 ];
1402   char *AstGetC_Strings[ AST__ASTGETC_MAX_STRINGS ];
1403   int AstGetC_Istr;
1404   int AstGetC_Init;
1405   int Nvtab;
1406   AstObjectVtab **Known_Vtabs;
1407} AstObjectGlobals;
1408
1409#endif
1410
1411/* More include files. */
1412/* =================== */
1413/* The interface to the Channel class must be included here (after the
1414   type definitions for the Object class) because "channel.h" itself
1415   includes this file ("object.h"), although "object.h" refers to the
1416   AstChannel structure above. This seems a little strange at first,
1417   but is simply analogous to making a forward reference to a
1418   structure type when recursively defining a normal C structure
1419   (except that here the definitions happen to be in separate include
1420   files). */
1421#include "channel.h"
1422
1423/* Function prototypes. */
1424/* ==================== */
1425/* Prototypes for standard class functions. */
1426/* ---------------------------------------- */
1427astPROTO_CHECK(Object)           /* Validate class membership */
1428astPROTO_ISA(Object)             /* Test class membership */
1429
1430/* NB. There is no constructor function for this class. */
1431
1432#if defined(astCLASS)            /* Protected */
1433
1434/* Initialiser. */
1435AstObject *astInitObject_( void *, size_t, int, AstObjectVtab *,
1436                           const char *, int * );
1437
1438/* Vtab Initialiser. */
1439void astInitObjectVtab_( AstObjectVtab *, const char *, int * );
1440
1441/* Loader. */
1442AstObject *astLoadObject_( void *, size_t, AstObjectVtab *,
1443                           const char *, AstChannel *channel, int * );
1444
1445#if defined(THREAD_SAFE)
1446void astInitObjectGlobals_( AstObjectGlobals * );
1447#endif
1448
1449#endif
1450
1451/* Prototypes for other class functions. */
1452/* ------------------------------------- */
1453#if !defined(astCLASS)           /* Public */
1454void astBegin_( void );
1455void astEnd_( int * );
1456#endif
1457
1458AstObject *astI2P_( int, int * );
1459AstObject *astMakeId_( AstObject *, int * );
1460AstObject *astMakePointer_( AstObject *, int * );
1461AstObject *astMakePointer_NoLockCheck_( AstObject *, int * );
1462int astP2I_( AstObject *, int * );
1463int astVersion_( int * );
1464int astEscapes_( int, int * );
1465int astTune_( const char *, int, int * );
1466void astTuneC_( const char *, const char *, char *, int, int * );
1467
1468/* Prototypes for member functions. */
1469/* -------------------------------- */
1470#if defined(astCLASS)            /* Protected */
1471AstObject *astAnnul_( AstObject *, int * );
1472AstObject *astDelete_( AstObject *, int * );
1473void astSet_( void *, const char *, int *, ... );
1474
1475#else                            /* Public */
1476AstObject *astDeleteId_( AstObject *, int * );
1477int astThreadId_( AstObject *, int, int * );
1478void astExportId_( AstObject *, int * );
1479void astImportId_( AstObject *, int * );
1480void astSetId_( void *, const char *, ... )__attribute__((format(printf,2,3)));
1481#endif
1482
1483AstObject *astAnnulId_( AstObject *, int * );
1484AstObject *astCheckLock_( AstObject *, int * );
1485AstObject *astClone_( AstObject *, int * );
1486AstObject *astCopy_( const AstObject *, int * );
1487AstObject *astFromString_( const char *, int * );
1488char *astToString_( AstObject *, int * );
1489const char *astGetC_( AstObject *, const char *, int * );
1490double astGetD_( AstObject *, const char *, int * );
1491float astGetF_( AstObject *, const char *, int * );
1492int astEqual_( AstObject *, AstObject *, int * );
1493int astGetI_( AstObject *, const char *, int * );
1494int astHasAttribute_( AstObject *, const char *, int * );
1495int astSame_( AstObject *, AstObject *, int * );
1496int astTest_( AstObject *, const char *, int * );
1497long astGetL_( AstObject *, const char *, int * );
1498void *astGetProxy_( AstObject *, int * );
1499void astClear_( AstObject *, const char *, int * );
1500void astExemptId_( AstObject *, int * );
1501void astLockId_( AstObject *, int, int * );
1502void astSetC_( AstObject *, const char *, const char *, int * );
1503void astSetD_( AstObject *, const char *, double, int * );
1504void astSetF_( AstObject *, const char *, float, int * );
1505void astSetI_( AstObject *, const char *, int, int * );
1506void astSetL_( AstObject *, const char *, long, int * );
1507void astSetProxy_( AstObject *, void *, int * );
1508void astShow_( AstObject *, int * );
1509void astUnlockId_( AstObject *, int, int * );
1510
1511#if defined(astCLASS)            /* Protected */
1512
1513void astCleanAttribs_( AstObject *, int * );
1514AstObject *astCast_( AstObject *, AstObject *, int * );
1515AstObject *astCastCopy_( AstObject *, AstObject *, int * );
1516
1517#if defined(THREAD_SAFE)
1518int astManageLock_( AstObject *, int, int, AstObject **, int * );
1519#endif
1520
1521int astGetObjSize_( AstObject *, int * );
1522
1523int astTestUseDefs_( AstObject *, int * );
1524int astGetUseDefs_( AstObject *, int * );
1525void astSetUseDefs_( AstObject *, int, int * );
1526void astClearUseDefs_( AstObject *, int * );
1527
1528const char *astGetAttrib_( AstObject *, const char *, int * );
1529const char *astGetClass_( const AstObject *, int * );
1530const char *astGetID_( AstObject *, int * );
1531const char *astGetIdent_( AstObject *, int * );
1532int astClassCompare_( AstObjectVtab *, AstObjectVtab *, int * );
1533int astGetNobject_( const AstObject *, int * );
1534int astGetRefCount_( AstObject *, int * );
1535int astTestAttrib_( AstObject *, const char *, int * );
1536int astTestID_( AstObject *, int * );
1537int astTestIdent_( AstObject *, int * );
1538void astClearAttrib_( AstObject *, const char *, int * );
1539void astClearID_( AstObject *, int * );
1540void astClearIdent_( AstObject *, int * );
1541void astDump_( AstObject *, AstChannel *, int * );
1542void astSetAttrib_( AstObject *, const char *, int * );
1543void astSetCopy_( AstObjectVtab *, void (*)( const AstObject *, AstObject *, int * ), int * );
1544void astSetDelete_( AstObjectVtab *, void (*)( AstObject *, int * ), int * );
1545void astSetDump_( AstObjectVtab *, void (*)( AstObject *, AstChannel *, int * ), const char *, const char *, int * );
1546void astSetVtab_( AstObject *, AstObjectVtab *, int * );
1547void astSetID_( AstObject *, const char *, int * );
1548void astSetIdent_( AstObject *, const char *, int * );
1549void astEnvSet_( AstObject *, int * );
1550void astVSet_( AstObject *, const char *, char **, va_list, int * );
1551
1552#endif
1553
1554
1555/* Function interfaces. */
1556/* ==================== */
1557/* These macros are wrap-ups for the functions defined by this class
1558   to make them easier to invoke (e.g. to avoid type mis-matches when
1559   passing pointers to objects from derived classes). */
1560
1561/* Interfaces to standard class functions. */
1562/* --------------------------------------- */
1563/* Check class membership. */
1564#define astCheckObject(this) astINVOKE_CHECK(Object,this,0)
1565#define astVerifyObject(this) astINVOKE_CHECK(Object,this,1)
1566
1567/* Test class membership. */
1568#define astIsAObject(this) astINVOKE_ISA(Object,this)
1569
1570/* NB. There is no constructor function for this class. */
1571
1572#if defined(astCLASS)            /* Protected */
1573
1574/* Initialiser. */
1575#define astInitObject(mem,size,init,vtab,name) \
1576astINVOKE(O,astInitObject_(mem,size,init,vtab,name,STATUS_PTR))
1577
1578/* Vtab Initialiser. */
1579#define astInitObjectVtab(vtab,name) astINVOKE(V,astInitObjectVtab_(vtab,name,STATUS_PTR))
1580
1581/* Loader. */
1582#define astLoadObject(mem,size,vtab,name,channel) \
1583astINVOKE(O,astLoadObject_(mem,size,vtab,name,astCheckChannel(channel),STATUS_PTR))
1584#endif
1585
1586/* Interfaces to other class functions. */
1587/* ------------------------------------ */
1588#if !defined(astCLASS)           /* Public */
1589#define astBegin astBegin_()
1590#define astEnd astINVOKE(V,astEnd_(STATUS_PTR))
1591#else                            /* Protected */
1592#define astMakePointer_NoLockCheck(id) ((void *)astMakePointer_NoLockCheck_((AstObject *)(id),STATUS_PTR))
1593#endif
1594
1595#define astVersion astVersion_(STATUS_PTR)
1596#define astEscapes(int) astEscapes_(int,STATUS_PTR)
1597#define astTune(name,val) astTune_(name,val,STATUS_PTR)
1598#define astTuneC(name,value,buff,bufflen) astTuneC_(name,value,buff,bufflen,STATUS_PTR)
1599#define astI2P(integer) ((void *)astI2P_(integer,STATUS_PTR))
1600#define astMakeId(pointer) ((void *)astMakeId_((AstObject *)(pointer),STATUS_PTR))
1601#define astP2I(pointer) astP2I_((AstObject *)(pointer),STATUS_PTR)
1602#define astMakePointer(id) ((void *)astCheckLock_(astMakePointer_((AstObject *)(id),STATUS_PTR),STATUS_PTR))
1603#define astToString(this) astINVOKE(V,astToString_(astCheckObject(this),STATUS_PTR))
1604#define astFromString(string) astINVOKE(O,astFromString_(string,STATUS_PTR))
1605
1606/* Interfaces to member functions. */
1607/* ------------------------------- */
1608/* Here we make use of astCheckObject (et al.) to validate Object
1609   pointers before use. This provides a contextual error report if a
1610   pointer to the wrong sort of object is supplied. In the case of an
1611   external caller, it also performs the required conversion from an
1612   Object identifier to a true C pointer. */
1613
1614/* These functions require special treatment for external use because
1615   they handle Object identifiers and their resources explicitly, and
1616   must therefore be passed identifier values without conversion to C
1617   pointers. */
1618
1619#if defined(astCLASS) || defined(astFORTRAN77) /* Protected or Fotran interface */
1620#define astAnnulId(this) astINVOKE(O,astAnnulId_((AstObject *)(this),STATUS_PTR))
1621#endif
1622
1623#if defined(astCLASS)                      /* Protected only */
1624#define astAnnul(this) astINVOKE(O,astAnnul_(astCheckObject(this),STATUS_PTR))
1625#define astDelete(this) astINVOKE(O,astDelete_(astCheckObject(this),STATUS_PTR))
1626#define astSet astINVOKE(F,astSet_)
1627
1628#else                                          /* Public only */
1629#define astAnnul(this) astINVOKE(O,astAnnulId_((AstObject *)(this),STATUS_PTR))
1630#define astDelete(this) astINVOKE(O,astDeleteId_((AstObject *)(this),STATUS_PTR))
1631#define astExport(this) astINVOKE(V,astExportId_((AstObject *)(this),STATUS_PTR))
1632#define astImport(this) astINVOKE(V,astImportId_((AstObject *)(this),STATUS_PTR))
1633#define astSet astINVOKE(F,astSetId_)
1634#define astThread(this,ptr) astINVOKE(V,astThreadId_((AstObject *)(this),ptr,STATUS_PTR))
1635#endif
1636
1637/* Both.... */
1638#define astLock(this,wait) astINVOKE(V,astLockId_((AstObject *)(this),wait,STATUS_PTR))
1639#define astUnlock(this,report) astINVOKE(V,astUnlockId_((AstObject *)(this),report,STATUS_PTR))
1640#define astEqual(this,that) astINVOKE(V,(((AstObject*)this==(AstObject*)that)||astEqual_(astCheckObject(this),astCheckObject(that),STATUS_PTR)))
1641#define astExempt(this) astINVOKE(V,astExemptId_((AstObject *)(this),STATUS_PTR))
1642#define astClear(this,attrib) astINVOKE(V,astClear_(astCheckObject(this),attrib,STATUS_PTR))
1643#define astClone(this) astINVOKE(O,astClone_(astCheckObject(this),STATUS_PTR))
1644#define astCopy(this) astINVOKE(O,astCopy_(astCheckObject(this),STATUS_PTR))
1645#define astGetC(this,attrib) astINVOKE(V,astGetC_(astCheckObject(this),attrib,STATUS_PTR))
1646#define astGetD(this,attrib) astINVOKE(V,astGetD_(astCheckObject(this),attrib,STATUS_PTR))
1647#define astGetF(this,attrib) astINVOKE(V,astGetF_(astCheckObject(this),attrib,STATUS_PTR))
1648#define astGetI(this,attrib) \
1649astINVOKE(V,astGetI_(astCheckObject(this),attrib,STATUS_PTR))
1650#define astGetL(this,attrib) \
1651astINVOKE(V,astGetL_(astCheckObject(this),attrib,STATUS_PTR))
1652#define astSetC(this,attrib,value) \
1653astINVOKE(V,astSetC_(astCheckObject(this),attrib,value,STATUS_PTR))
1654#define astSetD(this,attrib,value) \
1655astINVOKE(V,astSetD_(astCheckObject(this),attrib,value,STATUS_PTR))
1656#define astSetF(this,attrib,value) \
1657astINVOKE(V,astSetF_(astCheckObject(this),attrib,value,STATUS_PTR))
1658#define astSetI(this,attrib,value) \
1659astINVOKE(V,astSetI_(astCheckObject(this),attrib,value,STATUS_PTR))
1660#define astSetL(this,attrib,value) \
1661astINVOKE(V,astSetL_(astCheckObject(this),attrib,value,STATUS_PTR))
1662#define astShow(this) \
1663astINVOKE(V,astShow_(astCheckObject(this),STATUS_PTR))
1664#define astTest(this,attrib) \
1665astINVOKE(V,astTest_(astCheckObject(this),attrib,STATUS_PTR))
1666#define astSame(this,that) \
1667astINVOKE(V,astSame_(astCheckObject(this),astCheckObject(that),STATUS_PTR))
1668#define astHasAttribute(this,attrib) \
1669astINVOKE(V,astHasAttribute_(astCheckObject(this),attrib,STATUS_PTR))
1670#define astGetProxy(this) \
1671astINVOKE(V,astGetProxy_(astCheckObject(this),STATUS_PTR))
1672#define astSetProxy(this,proxy) \
1673astINVOKE(V,astSetProxy_(astCheckObject(this),proxy,STATUS_PTR))
1674
1675
1676#if defined(astCLASS)            /* Protected */
1677
1678#if defined(THREAD_SAFE)
1679#define astManageLock(this,mode,extra,fail) \
1680astINVOKE(V,astManageLock_(astCheckObject(this),mode, extra,fail,STATUS_PTR))
1681#else
1682#define astManageLock(this,mode,extra,fail)
1683#endif
1684
1685#define astCleanAttribs(this) astINVOKE(V,astCleanAttribs_(astCheckObject(this),STATUS_PTR))
1686#define astGetObjSize(this) astINVOKE(V,astGetObjSize_(astCheckObject(this),STATUS_PTR))
1687#define astCast(this,obj) astINVOKE(O,astCast_(astCheckObject(this),astCheckObject(obj),STATUS_PTR))
1688#define astCastCopy(this,obj) astCastCopy_((AstObject*)this,(AstObject*)obj,STATUS_PTR)
1689
1690#define astClearUseDefs(this) astINVOKE(V,astClearUseDefs_(astCheckObject(this),STATUS_PTR))
1691#define astTestUseDefs(this) astINVOKE(V,astTestUseDefs_(astCheckObject(this),STATUS_PTR))
1692#define astGetUseDefs(this) astINVOKE(V,astGetUseDefs_(astCheckObject(this),STATUS_PTR))
1693#define astSetUseDefs(this,val) astINVOKE(V,astSetUseDefs_(astCheckObject(this),val,STATUS_PTR))
1694
1695#define astClearAttrib(this,attrib) \
1696astINVOKE(V,astClearAttrib_(astCheckObject(this),attrib,STATUS_PTR))
1697#define astClearID(this) astINVOKE(V,astClearID_(astCheckObject(this),STATUS_PTR))
1698#define astClearIdent(this) astINVOKE(V,astClearIdent_(astCheckObject(this),STATUS_PTR))
1699#define astDump(this,channel) \
1700astINVOKE(V,astDump_(astCheckObject(this),astCheckChannel(channel),STATUS_PTR))
1701
1702#define astGetAttrib(this,attrib) \
1703astINVOKE(V,astGetAttrib_(astCheckObject(this),attrib,STATUS_PTR))
1704#define astGetClass(this) astINVOKE(V,astGetClass_((const AstObject *)(this),STATUS_PTR))
1705#define astGetID(this) astINVOKE(V,astGetID_(astCheckObject(this),STATUS_PTR))
1706#define astGetIdent(this) astINVOKE(V,astGetIdent_(astCheckObject(this),STATUS_PTR))
1707#define astGetNobject(this) astINVOKE(V,astGetNobject_(astCheckObject(this),STATUS_PTR))
1708#define astClassCompare(class1,class2) astClassCompare_(class1,class2,STATUS_PTR)
1709#define astGetRefCount(this) astINVOKE(V,astGetRefCount_(astCheckObject(this),STATUS_PTR))
1710#define astSetAttrib(this,setting) \
1711astINVOKE(V,astSetAttrib_(astCheckObject(this),setting,STATUS_PTR))
1712#define astSetCopy(vtab,copy) \
1713astINVOKE(V,astSetCopy_((AstObjectVtab *)(vtab),copy,STATUS_PTR))
1714#define astSetDelete(vtab,delete) \
1715astINVOKE(V,astSetDelete_((AstObjectVtab *)(vtab),delete,STATUS_PTR))
1716#define astSetDump(vtab,dump,class,comment) \
1717astINVOKE(V,astSetDump_((AstObjectVtab *)(vtab),dump,class,comment,STATUS_PTR))
1718#define astSetVtab(object,vtab) \
1719astINVOKE(V,astSetVtab_((AstObject *)object,(AstObjectVtab *)(vtab),STATUS_PTR))
1720#define astSetID(this,id) astINVOKE(V,astSetID_(astCheckObject(this),id,STATUS_PTR))
1721#define astSetIdent(this,id) astINVOKE(V,astSetIdent_(astCheckObject(this),id,STATUS_PTR))
1722#define astVSet(this,settings,text,args) \
1723astINVOKE(V,astVSet_(astCheckObject(this),settings,text,args,STATUS_PTR))
1724#define astEnvSet(this) \
1725astINVOKE(V,astEnvSet_(astCheckObject(this),STATUS_PTR))
1726#define astTestAttrib(this,attrib) \
1727astINVOKE(V,astTestAttrib_(astCheckObject(this),attrib,STATUS_PTR))
1728#define astTestID(this) astINVOKE(V,astTestID_(astCheckObject(this),STATUS_PTR))
1729#define astTestIdent(this) astINVOKE(V,astTestIdent_(astCheckObject(this),STATUS_PTR))
1730
1731/* Deprecated synonym. */
1732#define astClass(this) astGetClass(this)
1733#endif
1734
1735/* Extra stuff for debuging probnlems with object handles and memory usage */
1736#ifdef MEM_DEBUG
1737
1738void astWatchHandle_( int );
1739void astHandleUse_( int, const char *, ... );
1740void astHandleAlarm_( const char *, va_list );
1741
1742#define astWatchHandle astWatchHandle_
1743#define astHandleUse astHandleUse_
1744#define astHandleAlarm astHandleAlarm_
1745
1746#else
1747
1748#define astWatchHandle
1749#define astHandleUse
1750#define astHandleAlarm
1751
1752#endif
1753
1754#endif
1755
1756