Actual source code: prefix.c

petsc-3.7.3 2016-08-01
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: /*@C
 10:    PetscObjectSetOptions - Sets the options database used by the object

 12:    Collective on PetscObject

 14:    Input Parameters:
 15: +  obj - any PETSc object, for example a Vec, Mat or KSP.
 16: -  options - the options database, use NULL for default

 18:    Notes: if this is not called the object will use the default options database

 20:   Level: advanced

 22: .seealso: PetscOptionsCreate(), PetscOptionsDestroy()

 24: @*/
 25: PetscErrorCode  PetscObjectSetOptions(PetscObject obj,PetscOptions options)
 26: {
 29:   obj->options = options;
 30:   return(0);
 31: }

 35: /*
 36:    PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all
 37:    options of PetscObjectType in the database.

 39:    Collective on Object

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

 45:    Notes:
 46:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 47:    The first character of all runtime options is AUTOMATICALLY the
 48:    hyphen.

 50:    Concepts: prefix^setting

 52: */
 53: PetscErrorCode  PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
 54: {

 59:   if (!prefix) {
 60:     PetscFree(obj->prefix);
 61:   } else {
 62:     if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
 63:     PetscFree(obj->prefix);
 64:     PetscStrallocpy(prefix,&obj->prefix);
 65:   }
 66:   return(0);
 67: }

 71: /*
 72:    PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
 73:    options of PetscObjectType in the database.

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

 79:    Notes:
 80:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 81:    The first character of all runtime options is AUTOMATICALLY the
 82:    hyphen.

 84:    Concepts: prefix^setting

 86: */
 87: PetscErrorCode  PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
 88: {
 89:   char           *buf = obj->prefix;
 91:   size_t         len1,len2;

 95:   if (!prefix) return(0);
 96:   if (!buf) {
 97:     PetscObjectSetOptionsPrefix(obj,prefix);
 98:     return(0);
 99:   }
100:   if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

102:   PetscStrlen(prefix,&len1);
103:   PetscStrlen(buf,&len2);
104:   PetscMalloc1(1+len1+len2,&obj->prefix);
105:   PetscStrcpy(obj->prefix,buf);
106:   PetscStrcat(obj->prefix,prefix);
107:   PetscFree(buf);
108:   return(0);
109: }

113: /*
114:    PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.

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

119:    Output Parameters:
120: .  prefix - pointer to the prefix string used is returned

122:    Concepts: prefix^getting

124: */
125: PetscErrorCode  PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[])
126: {
130:   *prefix = obj->prefix;
131:   return(0);
132: }

136: /*
137:    PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
138:    options of PetscObjectType in the database.

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

144:    Notes:
145:    A hyphen (-) must NOT be given at the beginning of the prefix name.
146:    The first character of all runtime options is AUTOMATICALLY the
147:    hyphen.

149:    Concepts: prefix^setting

151: */
152: PetscErrorCode  PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
153: {
154:   char           *buf;
155:   size_t         len1,len2;

160:   buf = obj->prefix;
161:   if (!prefix) return(0);
162:   if (!buf) {
163:     PetscObjectSetOptionsPrefix(obj,prefix);
164:     return(0);
165:   }
166:   if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

168:   PetscStrlen(prefix,&len1);
169:   PetscStrlen(buf,&len2);
170:   PetscMalloc1(1+len1+len2,&obj->prefix);
171:   PetscStrcpy(obj->prefix,prefix);
172:   PetscStrcat(obj->prefix,buf);
173:   PetscFree(buf);
174:   return(0);
175: }