Actual source code: prefix.c

  1: #define PETSC_DLL
  2: /*
  3:      Provides utility routines for manulating any type of PETSc object.
  4: */
 5:  #include petsc.h

  9: /*
 10:    PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all 
 11:    options of PetscObjectType in the database. 

 13:    Input Parameters:
 14: .  obj - any PETSc object, for example a Vec, Mat or KSP.
 15: .  prefix - the prefix string to prepend to option requests of the object.

 17:    Notes: 
 18:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 19:    The first character of all runtime options is AUTOMATICALLY the
 20:    hyphen.

 22:    Concepts: prefix^setting

 24: */
 25: PetscErrorCode  PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
 26: {

 31:   if (!prefix) {
 32:     PetscStrfree(obj->prefix);
 33:     obj->prefix = PETSC_NULL;
 34:   } else {
 35:     if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
 36:     PetscStrfree(obj->prefix);
 37:     PetscStrallocpy(prefix,&obj->prefix);
 38:   }
 39:   return(0);
 40: }

 44: /*
 45:    PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all 
 46:    options of PetscObjectType in the database. 

 48:    Input Parameters:
 49: .  obj - any PETSc object, for example a Vec, Mat or KSP.
 50: .  prefix - the prefix string to prepend to option requests of the object.

 52:    Notes: 
 53:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 54:    The first character of all runtime options is AUTOMATICALLY the
 55:    hyphen.

 57:    Concepts: prefix^setting

 59: */
 60: PetscErrorCode  PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
 61: {
 62:   char   *buf = obj->prefix;
 64:   size_t len1,len2;

 68:   if (!prefix) {return(0);}
 69:   if (!buf) {
 70:     PetscObjectSetOptionsPrefix(obj,prefix);
 71:     return(0);
 72:   }
 73:   if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

 75:   PetscStrlen(prefix,&len1);
 76:   PetscStrlen(buf,&len2);
 77:   PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
 78:   PetscStrcpy(obj->prefix,buf);
 79:   PetscStrcat(obj->prefix,prefix);
 80:   PetscFree(buf);
 81:   return(0);
 82: }

 86: /*
 87:    PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.

 89:    Input Parameters:
 90: .  obj - any PETSc object, for example a Vec, Mat or KSP.

 92:    Output Parameters:
 93: .  prefix - pointer to the prefix string used is returned

 95:    Concepts: prefix^getting

 97: */
 98: PetscErrorCode  PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[])
 99: {
103:   *prefix = obj->prefix;
104:   return(0);
105: }

109: /*
110:    PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all 
111:    options of PetscObjectType in the database. 

113:    Input Parameters:
114: .  obj - any PETSc object, for example a Vec, Mat or KSP.
115: .  prefix - the prefix string to prepend to option requests of the object.

117:    Notes: 
118:    A hyphen (-) must NOT be given at the beginning of the prefix name.
119:    The first character of all runtime options is AUTOMATICALLY the
120:    hyphen.

122:    Concepts: prefix^setting

124: */
125: PetscErrorCode  PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
126: {
127:   char           *buf;
128:   size_t         len1,len2;

133:   buf = obj->prefix;
134:   if (!prefix) {return(0);}
135:   if (!buf) {
136:     PetscObjectSetOptionsPrefix(obj,prefix);
137:     return(0);
138:   }
139:   if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

141:   PetscStrlen(prefix,&len1);
142:   PetscStrlen(buf,&len2);
143:   PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
144:   PetscStrcpy(obj->prefix,prefix);
145:   PetscStrcat(obj->prefix,buf);
146:   PetscFree(buf);
147:   return(0);
148: }