Pointer to objects

Hello,

Is it possible to create a pointer to an object so that one can change its attributes; if so what is the syntax because currently I get a compile error? Thank you.

-Jim
SystemAdmin - Tue Aug 14 13:34:46 EDT 2012

Re: Pointer to objects
llandale - Tue Aug 14 14:02:18 EDT 2012

You mean an "Object" handle. Here are some ways to get handles:
Object o
  • o = current
  • o = next(o)
  • o = previous(o)
  • for o in (current Module) do
then ...
  • string Text = o."Object Text"
  • o."Object Text" = "Put new requirement here"

-Louie

Re: Pointer to objects
SystemAdmin - Tue Aug 14 14:13:26 EDT 2012

llandale - Tue Aug 14 14:02:18 EDT 2012
You mean an "Object" handle. Here are some ways to get handles:
Object o

  • o = current
  • o = next(o)
  • o = previous(o)
  • for o in (current Module) do
then ...
  • string Text = o."Object Text"
  • o."Object Text" = "Put new requirement here"

-Louie

Hello,

I mean like in c/c++ you can have a pointer to a struck and change data via the pointer.
 

/*
 * Basic structs.
 */
#include <stdio.h>
#include <string.h>
 
/* Struct is like a class w/o methods. */
struct fred {
        int m;
        char str[40];
        double d;
};
/* Notice the semicolon above. */
 
/* Print a fred, preceded by a message. */
void pfred(char *t, struct fred *fr)
{
        printf("%s: [ m = %d, str = %s, d = %f ]\n",
               t, fr->m, fr->str, fr->d);
}
 
int main()
{
        /* This declares a variable f1 which is a fred, and initializes it
           to the values indicated. */
        struct fred f1 = { 40, "Howdy", 5.498 };
 
        /* This declares two variables, an uninitialized fred and a pointer
           to a fred object. */
        struct fred f2, *fp;
 
        f2 = f1;
        pfred("f1", &f1);
        pfred("f2", &f2);
 
        f2.m += 10;
        strcat(f2.str, " there");
        f2.d = 16.0001;
        pfred("AA", &f2);
 
        fp = &f1;
        fp->m = -55;
        fp->str[3] = '\0';
        fp->d = 111.111;
        pfred("ZZ", &f1);
}

Re: Pointer to objects
llandale - Tue Aug 14 14:45:48 EDT 2012

SystemAdmin - Tue Aug 14 14:13:26 EDT 2012

Hello,

I mean like in c/c++ you can have a pointer to a struck and change data via the pointer.
 

/*
 * Basic structs.
 */
#include <stdio.h>
#include <string.h>
 
/* Struct is like a class w/o methods. */
struct fred {
        int m;
        char str[40];
        double d;
};
/* Notice the semicolon above. */
 
/* Print a fred, preceded by a message. */
void pfred(char *t, struct fred *fr)
{
        printf("%s: [ m = %d, str = %s, d = %f ]\n",
               t, fr->m, fr->str, fr->d);
}
 
int main()
{
        /* This declares a variable f1 which is a fred, and initializes it
           to the values indicated. */
        struct fred f1 = { 40, "Howdy", 5.498 };
 
        /* This declares two variables, an uninitialized fred and a pointer
           to a fred object. */
        struct fred f2, *fp;
 
        f2 = f1;
        pfred("f1", &f1);
        pfred("f2", &f2);
 
        f2.m += 10;
        strcat(f2.str, " there");
        f2.d = 16.0001;
        pfred("AA", &f2);
 
        fp = &f1;
        fp->m = -55;
        fp->str[3] = '\0';
        fp->d = 111.111;
        pfred("ZZ", &f1);
}

First off, "DXL" is "C--"'s idiot half cousin. Don't get your hopes up.

Well they have "DxlObjects" which are not in the manual.

Syntax in doors.exe:
void        ::=(DxlObjectLHS lhs,_x newValue)   setFieldValue
DxlObjectLHS    ::->(DxlObject obj,string fieldName) getFieldLHS
_x              ::->(DxlObject obj,string fieldName) getFieldValue
void            delete(DxlObject theObject)             deleteDxlObject
DxlObject       automatic()                             autoDxlObject
DxlObject       new()                                   newDxlObject
 
struct  DxlObjectLHS{}; struct DxlObject{};


DxlObject dxlo = new() // don't know what "automatic()" does
dxlo->"m" = 10
dxlo->"s' = "Hello"
dxlo->"r" = 1.99
{code}
Someone else needs to help you with clever data types.

-Louie

Re: Pointer to objects
Mathias Mamsch - Tue Aug 14 15:52:04 EDT 2012

SystemAdmin - Tue Aug 14 14:13:26 EDT 2012

Hello,

I mean like in c/c++ you can have a pointer to a struck and change data via the pointer.
 

/*
 * Basic structs.
 */
#include <stdio.h>
#include <string.h>
 
/* Struct is like a class w/o methods. */
struct fred {
        int m;
        char str[40];
        double d;
};
/* Notice the semicolon above. */
 
/* Print a fred, preceded by a message. */
void pfred(char *t, struct fred *fr)
{
        printf("%s: [ m = %d, str = %s, d = %f ]\n",
               t, fr->m, fr->str, fr->d);
}
 
int main()
{
        /* This declares a variable f1 which is a fred, and initializes it
           to the values indicated. */
        struct fred f1 = { 40, "Howdy", 5.498 };
 
        /* This declares two variables, an uninitialized fred and a pointer
           to a fred object. */
        struct fred f2, *fp;
 
        f2 = f1;
        pfred("f1", &f1);
        pfred("f2", &f2);
 
        f2.m += 10;
        strcat(f2.str, " there");
        f2.d = 16.0001;
        pfred("AA", &f2);
 
        fp = &f1;
        fp->m = -55;
        fp->str[3] = '\0';
        fp->d = 111.111;
        pfred("ZZ", &f1);
}

Translating to DXL this would be:
 

/* Struct is like a class w/o methods. */
struct fred {} // DXL does not support member declaration inside the struct 
 
// Helper Function to make property functions nicer
DxlObject DxlObjectOf (fred f) { return ((addr_ f) DxlObject) }
 
// so we manually declare property functions for our type 
 
int  get_m (fred f) { return ((DxlObjectOf f)->"x") int }
void set_m (fred f, int val) { ((DxlObjectOf f)->"x") = val }
 
string get_str (fred f) { return ((DxlObjectOf f)->"str") string }
void   set_str (fred f, string val) { ((DxlObjectOf f)->"str") = val }
 
// notice how all property functions have exactly the same structure!
// Note that real in DXL is equivalent to double
real get_d (fred f) { return ((DxlObjectOf f)->"d") real }
void set_d (fred f, real val) { ((DxlObjectOf f)->"d") = val }
 
fred create_fred (int m, string s, real d) {
    DxlObject dx = new() 
    fred f = addr_ dx  
 
    set_m(f, m) 
    set_str(f, s) 
    set_d(f, d) 
    return f
}
 
 
/* Print a fred, preceded by a message. */
void pfred(string t, fred gr)
{
        print t ": [ m = " (get_m gr) ", str = " (get_str gr) ", d = " (get_d gr) " ]\n"
}
 
int main()
{
        /* This declares a variable f1 which is a fred, and initializes it
           to the values indicated. */
        fred f1 = create_fred( 40, "Howdy", 5.498 )
 
        /* This declares two variables, an uninitialized fred and a pointer
           to a fred object. */
        fred f2, *fp;
 
        f2 = f1;
        pfred("f1", f1);
        pfred("f2", f2);
 
        set_m(f2, get_m f2 + 10);
        set_str(f2, (get_str f2) " there");
        set_d(f2, 16.0001);
        pfred("AA", f2);
 
        fp = &f1;
        set_m(*fp, -55);
        set_str(*fp, (get_str (*fp))[0:2])
        set_d(*fp, 111.111);
        pfred("ZZ", f1);
 
        return 0
}
 
main()

 


Maybe this helps, regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS