Actual source code: pname.c

      1: #define PETSC_DLL

     3:  #include petsc.h

      7: /*@C
      8:    PetscObjectSetName - Sets a string name associated with a PETSc object.

     10:    Not Collective

     12:    Input Parameters:
     13: +  obj - the Petsc variable
     14:          Thus must be cast with a (PetscObject), for example,
     15:          PetscObjectSetName((PetscObject)mat,name);
     16: -  name - the name to give obj

     18:    Level: advanced

     20:    Concepts: object name^setting

     22: .seealso: PetscObjectGetName()
     23: @*/
     24: PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject obj,const char name[])
     25: {

     29:   if (!obj) SETERRQ(PETSC_ERR_ARG_CORRUPT,"Null object");
     30:   PetscStrfree(obj->name);
     31:   PetscStrallocpy(name,&obj->name);
     32:   return(0);
     33: }

     37: /*@C
     38:    PetscObjectName - Gives an object a name if it does not have one

     40:    Not Collective

     42:    Input Parameters:
     43: .  obj - the Petsc variable
     44:          Thus must be cast with a (PetscObject), for example,
     45:          PetscObjectSetName((PetscObject)mat,name);

     47:    Level: advanced

     49:    Concepts: object name^setting default

     51: .seealso: PetscObjectGetName(), PetscObjectSetName()
     52: @*/
     53: PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject obj)
     54: {
     56:   char       name[64];
     57:   static int counter = 0;

     60:   if (!obj->name) {
     61:     sprintf(name,"%s_%d",obj->class_name,counter++);
     62:     PetscStrallocpy(name,&obj->name);
     63:   }
     64:   return(0);
     65: }

     69: /*@C
     70:    PetscObjectPublish - Publish an object

     72:    Collective on PetscObject

     74:    Input Parameters:
     75: .  obj - the Petsc variable
     76:          Thus must be cast with a (PetscObject), for example,
     77:          PetscObjectSetName((PetscObject)mat,name);

     79:    Level: advanced

     81:    Concepts: publishing object

     83:    Notes: Not currently used

     85: .seealso: PetscObjectSetName()

     87: @*/
     88: PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject obj)
     89: {

     94:   if (obj->bops->publish) {
     95:     (*obj->bops->publish)(obj);
     96:   }
     97:   return(0);
     98: }

    102: PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject obj,const char type_name[])
    103: {

    107:   PetscObjectTakeAccess(obj);
    108:   PetscStrfree(obj->type_name);
    109:   PetscStrallocpy(type_name,&obj->type_name);
    110:   PetscObjectGrantAccess(obj);
    111:   return(0);
    112: }