Viewing contents of file '../idllib/contrib/mallozzi/generic__get.pro'
;
; Generic method to return instance data from any object.  
;
; By default, object internal pointers are dereferenced and returned 
; since returning a pointer into an object breaks encapsulation.  Set 
; the keyword RETURN_POINTERS to override this behavior.  This might 
; be desired, for example, to avoid copying large datasets on return.  
; In this case, one should ensure that the data to which the pointer 
; refers is not altered.
;
; Returns instance_data on success, or 0 on error.
;
; Based on a routine written by D. Fanning, with some improvements.
; Robert.Mallozzi@msfc.nasa.gov, 1998 May
;
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FUNCTION generic::get, instance_data, RETURN_POINTERS = return_pointers


    ; Ensure request is a string variable
    ;
    s = SIZE (instance_data)
    IF (s[s[0]+1] NE 7) THEN BEGIN
       MESSAGE, /CONTINUE, 'Argument must be of type STRING: ' + $
           STRTRIM (instance_data, 2)
       RETURN, 0
    ENDIF

    returnPointers = KEYWORD_SET (return_pointers)

    ; Get the name of the object class
    ;
    thisClass = OBJ_CLASS (self)

    ; Create a local structure of this type
    ;
    IF (NOT EXECUTE ('thisStruct = {' + thisClass + '}')) THEN BEGIN
       MESSAGE, /CONTINUE, 'EXECUTE failed.'
       RETURN, 0
    ENDIF

    ; Find the field identifier (index) in the local structure
    ;
    structFields = TAG_NAMES (thisStruct)
    index = WHERE (structFields EQ STRUPCASE (instance_data), count)

    ; Extract and return the field if it is found
    ;
    IF (count EQ 1) THEN BEGIN

       IF (EXECUTE ('retVal = self.' + structFields[index[0]])) THEN BEGIN

          ; Don't return a pointer into an object
          ;
          IF ((PTR_VALID (retVal[0])) AND (NOT returnPointers)) THEN BEGIN

             RETURN, *retVal

          ENDIF ELSE BEGIN   

	     ; Case of an invalid pointer: issue warning, and return 0   
	     ;
	     s = SIZE (retVal)
	     IF (s[s[0] + 1] EQ 10) THEN BEGIN
		MESSAGE, /CONTINUE, $
                    'Request for invalid pointer: ' + instance_data
        	retVal = 0
	     ENDIF   

             RETURN, retVal

          ENDELSE

       ENDIF

       MESSAGE, /CONTINUE, 'EXECUTE failed.'

    ENDIF ELSE BEGIN

       MESSAGE, /CONTINUE, 'Invalid request for object ' + $
           OBJ_CLASS (self) + ': ' + instance_data

    ENDELSE


    RETURN, 0

END