Actual source code: prefix.c

petsc-3.6.4 2016-04-12
Report Typos and Errors
  2: /*
  3:      Provides utility routines for manulating any type of PETSc object.
  4: */
  5: #include <petsc/private/petscimpl.h>  /*I   "petscsys.h"    I*/

  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:     PetscFree(obj->prefix);
 33:   } else {
 34:     if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
 35:     PetscFree(obj->prefix);
 36:     PetscStrallocpy(prefix,&obj->prefix);
 37:   }
 38:   return(0);
 39: }

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

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

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

 56:    Concepts: prefix^setting

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

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

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

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

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

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

 94:    Concepts: prefix^getting

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

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

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

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

121:    Concepts: prefix^setting

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

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

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