Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access instance, class, or function "own" identifiers within the .class file

    In class programming, is there a way to access an instance's, class's or member function's own identifier programmatically from within a class or function definition? The current use case is to display a generalized error message within a member function, as in .import below, but getting an identifier seems like a general problem that may have other applications.
    dataSource.class:

    Code:
    class dataSource {
        repositoryURL  = ""
        version             = ""
        filelist               = ""
        localDir            = ""
    }
    
    ...
    program .download
        //Default provided here
        ...
    end
    
    program .unpack
        //Default is do nothing; override if necessary
    end
    
    program .import
        di as err "Classes that inherit from .dataSource MUST override .import"
        exit 4050
    end
    but I would like the text ".dataSource" and ".import" added to the error message automatically based on the fact that the currently executing (or compiling?) function is .dataSource.import. Is that possible in Stata?
    Last edited by Michael Harris differentiated; 02 Nov 2019, 09:51. Reason: Fixed typo

  • #2
    It has occurred to me that I could do something like
    Code:
    local cname dataSource
    class `cname' {
        repositoryURL  = ""
        version             = ""
        filelist               = ""
        localDir            = ""
    }
    
    ...
    program .download
        //Default provided here
        ...
    end
    
    program .unpack
        //Default is do nothing; override if necessary
    end
    
    local fname .import
    program `fname'
        di as err "Classes that inherit from .`cname' MUST override `fname'"
        exit 4050
    end
    but I would welcome a solution that gets the identifiers more directly from the class itself.
    Last edited by Michael Harris differentiated; 02 Nov 2019, 10:01.

    Comment

    Working...
    X