Package com.stata.sfi
Class Macro
java.lang.Object
com.stata.sfi.Macro
This class provides access to Stata macros.
Example:
Local macros are a convenient tool for passing command options to Java.
public static int getOptions(String[] args) {
// options filename and level are passed through local macros
String fileName = Macro.getLocal("filename");
if (fileName == null) {
return (198);
}
int level = 95;
try {
level = Integer.parseInt(Macro.getLocalSafe("level"));
}
catch (NumberFormatException e) {}
SFIToolkit.displayln("filename: " + fileName);
SFIToolkit.displayln("level: " + level);
return 0;
}
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Get the contents of a global macro.static String
Get the contents of a global macro.static String
getGlobalSafe
(String name) Get the contents of a global macro without returning null.static String
getGlobalSafe
(String name, int type) Get the contents of a global macro without returning null.static String
Get the contents of a local macro.static String
getLocalSafe
(String name) Get the contents of a local macro without returning null.static int
Set the value of a global macro.static int
Set the value of a global macro.static int
Set the value of a global macro.static int
Set the value of a global macro.static int
Set the value of a local macro.
-
Field Details
-
TYPE_AUTOMATIC
public static final int TYPE_AUTOMATIC- See Also:
-
TYPE_CRETURN
public static final int TYPE_CRETURN- See Also:
-
TYPE_ERETURN
public static final int TYPE_ERETURN- See Also:
-
TYPE_GLOBAL
public static final int TYPE_GLOBAL- See Also:
-
TYPE_RETURN
public static final int TYPE_RETURN- See Also:
-
TYPE_RRETURN
public static final int TYPE_RRETURN- See Also:
-
TYPE_SRETURN
public static final int TYPE_SRETURN- See Also:
-
VTYPE_HIDDEN
public static final int VTYPE_HIDDEN- See Also:
-
VTYPE_HISTORICAL
public static final int VTYPE_HISTORICAL- See Also:
-
VTYPE_VISIBLE
public static final int VTYPE_VISIBLE- See Also:
-
-
Method Details
-
getGlobal
Get the contents of a global macro.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getGlobal
Get the contents of a global macro.- Parameters:
name
- Name of the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
,TYPE_CRETURN
, orTYPE_SRETURN
.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getGlobalSafe
Get the contents of a global macro without returning null.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
getGlobalSafe
Get the contents of a global macro without returning null.- Parameters:
name
- Name of the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
,TYPE_CRETURN
, orTYPE_SRETURN
.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
getLocal
Get the contents of a local macro.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getLocalSafe
Get the contents of a local macro without returning null.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
setGlobal
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.vtype
- If the macro is a type of return value, sets whether the return value isVTYPE_VISIBLE
,VTYPE_HIDDEN
, orVTYPE_HISTORICAL
. This parameter is ignored withTYPE_GLOBAL
andTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.version
- If the macro is a type of return value, sets the release number in the form #[#][.[#[#]]] for a return result. This parameter is ignored withTYPE_GLOBAL
andTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setLocal
Set the value of a local macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.- Returns:
- Return code from Stata; 0 if successful.
-