<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_ModuleModel" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
REM === Full documentation is available on https://help.libreoffice.org/ ===
REM =======================================================================================================================
Option Compatible
Option ClassModule
'Option Private Module
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' ModuleModel (aka SF_Model)
''' ===========
''' Illustration of how the ScriptForge modules are structured
''' Copy and paste this code in an empty Basic module to start a new service
''' Comment in, comment out, erase what you want, but at the end respect the overall structure
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
REM ================================================================== EXCEPTIONS
''' FAKENEWSERROR
REM ============================================================= PRIVATE MEMBERS
Private [Me] As Object ' Should be initialized immediately after the New statement
' Dim obj As Object : Set obj = New SF_Model
' Set obj.[Me] = obj
Private [_Parent] As Object ' To keep trace of the instance having created a sub-instance
' Set obj._Parent = [Me]
Private ObjectType As String ' Must be UNIQUE
REM ============================================================ MODULE CONSTANTS
Private Const SOMECONSTANT = 1
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
REM -----------------------------------------------------------------------------
Private Sub Class_Initialize()
Set [Me] = Nothing
Set [_Parent] = Nothing
ObjectType = "MODEL"
End Sub ' ScriptForge.SF_Model Constructor
REM -----------------------------------------------------------------------------
Private Sub Class_Terminate()
Call Class_Initialize()
End Sub ' ScriptForge.SF_Model Destructor
REM -----------------------------------------------------------------------------
Public Function Dispose() As Variant
Call Class_Terminate()
Set Dispose = Nothing
End Function ' ScriptForge.SF_Model Explicit Destructor
REM ================================================================== PROPERTIES
REM -----------------------------------------------------------------------------
Property Get MyProperty() As Boolean
''' Returns True or False
''' Example:
''' myModel.MyProperty
MyProperty = _PropertyGet("MyProperty")
End Property ' ScriptForge.SF_Model.MyProperty
REM ===================================================================== METHODS
REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
''' Return the actual value of the given property
''' Args:
''' PropertyName: the name of the property as a string
''' Returns:
''' The actual value of the property
''' If the property does not exist, returns Null
''' Exceptions:
''' see the exceptions of the individual properties
''' Examples:
''' myModel.GetProperty("MyProperty")
Const cstThisSub = "Model.GetProperty"
Const cstSubArgs = ""
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
GetProperty = Null
Check:
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
End If
Try:
GetProperty = _PropertyGet(PropertyName)
Finally:
SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
End Function ' ScriptForge.SF_Model.GetProperty
REM -----------------------------------------------------------------------------
Public Function Methods() As Variant
''' Return the list of public methods of the Model service as an array
Methods = Array( _
"MyFunction" _
, "etc" _
)
End Function ' ScriptForge.SF_Model.Methods
REM -----------------------------------------------------------------------------
Public Function MyFunction(Optional ByVal Arg1 As Variant _
, Optional ByVal Arg2 As Variant _
) As Variant
''' Fictive function that concatenates Arg1 Arg2 times
''' Args:
''' Arg1 String Text
''' Arg2 Numeric Number of times (default = 2)
''' Returns:
''' The new string
''' Exceptions:
''' FAKENEWSERROR
''' Examples:
''' MyFunction("value1") returns "value1value1"
Dim sOutput As String ' Output buffer
Dim i As Integer
Const cstThisSub = "Model.myFunction"
Const cstSubArgs = "Arg1, [Arg2=2]"
' _ErrorHandling returns False when, for debugging, the standard error handling is preferred
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
myFunction = ""
Check:
If IsMissing(Arg2) Then Arg2 = 2
' _EnterFunction returns True when current method is invoked from a user script
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
' Check Arg1 is a string and Arg2 is a number.
' Validation rules for scalars and arrays are described in SF_Utils
If Not SF_Utils._Validate(Arg1, "Arg1", V_STRING) Then GoTo Finally
If Not SF_Utils._Validate(Arg2, "Arg2", V_NUMERIC) Then GoTo Finally
' Fatal error ?
If Arg2 < 0 Then GoTo CatchFake
End If
Try:
sOutput = ""
For i = 0 To Arg2
sOutput = sOutput & Arg1
Next i
myFunction = sOutput
Finally:
' _ExitFunction manages internal (On Local) errors
SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
CatchFake:
SF_Exception.RaiseFatal("FAKENEWSERROR", cstThisSub)
GoTo Finally
End Function ' ScriptForge.SF_Model.myFunction
REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
''' Return the list or properties of the Model class as an array
Properties = Array( _
"MyProperty" _
, "etc" _
)
End Function ' ScriptForge.SF_Model.Properties
REM =========================================================== PRIVATE FUNCTIONS
REM -----------------------------------------------------------------------------
Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
''' Return the value of the named property
''' Args:
''' psProperty: the name of the property
Dim cstThisSub As String
Const cstSubArgs = ""
cstThisSub = "SF_Model.get" & psProperty
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
Select Case psProperty
Case "MyProperty"
_PropertyGet = TBD
Case Else
_PropertyGet = Null
End Select
Finally:
SF_Utils._ExitFunction(cstThisSub)
Exit Function
End Function ' ScriptForge.SF_Model._PropertyGet
REM -----------------------------------------------------------------------------
Private Function _Repr() As String
''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
''' Args:
''' Return:
''' "[MODEL]: A readable string"
_Repr = "[MODEL]: A readable string"
End Function ' ScriptForge.SF_Model._Repr
REM ============================================ END OF SCRIPTFORGE.SF_MODEL
</script:module>