comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Problems with Restore
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Problems with Restore [message #47868] Wed, 08 March 2006 11:07 Go to next message
vcarlos is currently offline  vcarlos
Messages: 21
Registered: February 2006
Junior Member
Hi all,

I am writing a class that I want add save and restore features to it.

My class is defined something like this:

<code>
pro OperatorLanguageMapping__define;

objectClass = $
{OperatorLanguageMapping, $
password : '', $ ; holds the password
name : '', $ ; holds the operator name
language : '' $; holds the language
}

end

OperatorLanguageMapping::Restore, fileName

restore, fileName, RESTORED_OBJECTS = temp
self.name = temp->GetName()
self.language = temp->GetLanguage()
self.password = temp->GetPassword()

end

OperatorLanguageMapping::Save, fileName

save, self, fileName

end
</code>

Obviously, the class has its getter and setter methods.

The problem is that when I do this:

<code>
o1 = obj_new("OperatorLanguageMapping")
o1->SetPassword, '123456'
o1->Save, '~/o1.sav'

o1->SetPassword, 'test'

o1->Restore, '~/o1.sav'
print, o1->GetPassword
</code>

What I got is: 'test' instead of '123456'

I tried to debug the software changing the method restore to look like
this:

<code>
OperatorLanguageMapping::Restore, fileName

restore, fileName, RESTORED_OBJECTS = temp
self.password = 'password'
print, self->GetPassword()

end
</code>

By now what I got is :

password
test

That is, after exiting the restore method of the object, the changes I
have made inside are not available outside the method(!!).

I keep trying to find out what was happening, and when I comment out
the line that call the restore procedure inside the Restore method of
the Class OperatorLanguageMapping, then, what I got was:

password
password

That is, changing the attribute inside the method restore worked.

I don't know if I was clear, my english is not that good and the
problem is not easy to explain too...

Does anyone have an idea of what could be wrong?

I have also tried to use IDL_SaveFile object, but the result was the
same...

Thanks all

Vinicius
Re: Problems with Restore [message #47977 is a reply to message #47868] Thu, 09 March 2006 07:36 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
vcarlos wrote:
> Hi all,
>
> I am writing a class that I want add save and restore features to it.


> OperatorLanguageMapping::Save, fileName
>
> save, self, fileName
>
> end
>

Hi,

It is that the self argument to SAVE that is the trickiest part. But
this modification should work.

OperatorLanguageMapping::Save, objRef, fileName

if n_elements(objRef) EQ 0 then objRef = self
save, objRef, fileName

end

Cheers,
Ben
Re: Problems with Restore [message #47983 is a reply to message #47868] Thu, 09 March 2006 04:38 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
vcarlos wrote:
> Hi Antonio,
>
> Thanks for explanation. It really worked with the changes proposed in
> the last post. And more than that, I understood what was happening :)

Yep, I have already understand what was happening. Correct a problem
without understand why is like to have a granade in your hands :)

Bye.

>
> Thanks
>
> Vinicius
>


--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
Re: Problems with Restore [message #47984 is a reply to message #47868] Thu, 09 March 2006 04:16 Go to previous message
vcarlos is currently offline  vcarlos
Messages: 21
Registered: February 2006
Junior Member
Hi Antonio,

Thanks for explanation. It really worked with the changes proposed in
the last post. And more than that, I understood what was happening :)

Thanks

Vinicius
Re: Problems with Restore [message #47988 is a reply to message #47868] Thu, 09 March 2006 01:11 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
Hello, other time. I think here is the final response to the problem:

The problem is in the SAVE and RESTORE methods:

(at method Save)
"save, self, FILENAME=filename"

saves the a variable with name 'self'

(at method restore)
"restore, fileName, RESTORED_OBJECTS = temp"

restores the 'self' named variable and also stores references of object
into the 'temp' array.
Here is the problem. Your 'self' object reference is replaced by the
previous 'self' variable stored with the save method.

At 'save' method change this:
PRO OperatorLanguageMapping::Save, fileName
a=self
save, a, FILENAME=fileName
END

Now when you make the restore, you are restoreing a named variable 'a'
that doesn't replace the 'self' reference.

Bye.


--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
Re: Problems with Restore [message #47989 is a reply to message #47868] Thu, 09 March 2006 01:05 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
Remember to OBJ_DESTROY the 'temp' reference into the Restore method.

Antonio Santiago wrote:
> Here is a partial response of your (our) problem, when you restoring the
> file, both 'self' and 'temp' references are the same, that is the 'self'
> reference changes.
>
>
> ------ Object code test --------
> FUNCTION OperatorLanguageMapping::Init
> RETURN, 1
> END
>
>
> PRO OperatorLanguageMapping::Restore, fileName
> print, 'Restoring'
> print, 'Before:'
> help, self ;; <----- Here is a reference
>
> restore, fileName, RESTORED_OBJECTS = temp
> print, 'After:'
> help, self, temp[0] ;; <----- Here 'self' reference has changed
> self.password = temp[0]->GetPassword()
> END
>
> PRO OperatorLanguageMapping::Save, fileName
> save, self, FILENAME=fileName
> END
>
>
> PRO OperatorLanguageMapping::SetPassword, pass
> self.password = pass
> END
>
>
> FUNCTION OperatorLanguageMapping::GetPassword
> RETURN, self.password
> END
>
>
> PRO OperatorLanguageMapping__define;
> objectClass = { OperatorLanguageMapping, $
> password : '' $ ; holds the password
> }
> END
> ------ Object code test --------
>
> ------ Test program --------
> PRO optest
> o1 = obj_new("OperatorLanguageMapping")
> o1->SetPassword, '123456'
> o1->Save, '~/o1.sav'
>
>
> o1->SetPassword, 'test'
>
> o1->Restore, '~/o1.sav'
>
> print, o1->GetPassword()
> END
> ------ Test program --------
>
>
> A possible solution maybe store the 'self' reference into a variable and
> after restoring the file reassign it:
>
> PRO OperatorLanguageMapping::Restore, fileName
> print, 'Restoring'
> print, 'Before:'
> help, self
>
> a=self ;; <--- Store 'self' reference'
> self=0 ;; <--- Changue it to a scaler, if not, a=self=temp.
> restore, fileName, RESTORED_OBJECTS = temp
> print, 'After:'
> help, self, temp[0]
>
> self=a ;; <---- Re-assing the initial reference.
> self.password = temp[0]->GetPassword()
> END
>
>
> Bye.
>


--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
Re: Problems with Restore [message #47990 is a reply to message #47868] Thu, 09 March 2006 01:02 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
Here is a partial response of your (our) problem, when you restoring the
file, both 'self' and 'temp' references are the same, that is the 'self'
reference changes.


------ Object code test --------
FUNCTION OperatorLanguageMapping::Init
RETURN, 1
END


PRO OperatorLanguageMapping::Restore, fileName
print, 'Restoring'
print, 'Before:'
help, self ;; <----- Here is a reference

restore, fileName, RESTORED_OBJECTS = temp
print, 'After:'
help, self, temp[0] ;; <----- Here 'self' reference has changed
self.password = temp[0]->GetPassword()
END

PRO OperatorLanguageMapping::Save, fileName
save, self, FILENAME=fileName
END


PRO OperatorLanguageMapping::SetPassword, pass
self.password = pass
END


FUNCTION OperatorLanguageMapping::GetPassword
RETURN, self.password
END


PRO OperatorLanguageMapping__define;
objectClass = { OperatorLanguageMapping, $
password : '' $ ; holds the password
}
END
------ Object code test --------

------ Test program --------
PRO optest
o1 = obj_new("OperatorLanguageMapping")
o1->SetPassword, '123456'
o1->Save, '~/o1.sav'


o1->SetPassword, 'test'

o1->Restore, '~/o1.sav'

print, o1->GetPassword()
END
------ Test program --------


A possible solution maybe store the 'self' reference into a variable and
after restoring the file reassign it:

PRO OperatorLanguageMapping::Restore, fileName
print, 'Restoring'
print, 'Before:'
help, self

a=self ;; <--- Store 'self' reference'
self=0 ;; <--- Changue it to a scaler, if not, a=self=temp.
restore, fileName, RESTORED_OBJECTS = temp
print, 'After:'
help, self, temp[0]

self=a ;; <---- Re-assing the initial reference.
self.password = temp[0]->GetPassword()
END


Bye.

--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: matching 2 grids
Next Topic: Re: Name Space Conflicts

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:37:17 PDT 2025

Total time taken to generate the page: 0.00821 seconds