Actual source code: gcookie.c
1: /*
2: Provides utility routines for manulating any type of PETSc object.
3: */
4: #include petsc.h
8: /*@C
9: PetscObjectGetCookie - Gets the cookie for any PetscObject,
11: Not Collective
12:
13: Input Parameter:
14: . obj - any PETSc object, for example a Vec, Mat or KSP.
15: Thus must be cast with a (PetscObject), for example,
16: PetscObjectGetCookie((PetscObject)mat,&cookie);
18: Output Parameter:
19: . cookie - the cookie
21: Level: developer
23: @*/
24: PetscErrorCode PetscObjectGetCookie(PetscObject obj,int *cookie)
25: {
27: if (!obj) SETERRQ(PETSC_ERR_ARG_CORRUPT,"Null object");
28: *cookie = obj->cookie;
29: return(0);
30: }
34: /*@
35: PetscObjectExists - Determines whether a PETSc object has been destroyed.
37: Not Collective
39: Input Parameter:
40: . obj - any PETSc object, for example a Vec, Mat or KSP.
41: Thus must be cast with a (PetscObject), for example,
42: PetscObjectGetCookie((PetscObject)mat,&exists);
44: Output Parameter:
45: . exists - PETSC_FALSE if object does not exist; PETSC_TRUE if object does exist.
47: Level: developer
49: @*/
50: PetscErrorCode PetscObjectExists(PetscObject obj,PetscTruth *exists)
51: {
53: *exists = PETSC_FALSE;
54: if (!obj) return(0);
55: if (obj->cookie >= PETSC_COOKIE && obj->cookie <= PETSC_LARGEST_COOKIE) *exists = PETSC_TRUE;
56: return(0);
57: }