Actual source code: prefix.c
1: /*
2: Provides utility routines for manulating any type of PETSc object.
3: */
4: #include petsc.h
8: /*
9: PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all
10: options of PetscObjectType in the database.
12: Input Parameters:
13: . obj - any PETSc object, for example a Vec, Mat or KSP.
14: . prefix - the prefix string to prepend to option requests of the object.
16: Notes:
17: A hyphen (-) must NOT be given at the beginning of the prefix name.
18: The first character of all runtime options is AUTOMATICALLY the
19: hyphen.
21: Concepts: prefix^setting
23: */
24: PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
25: {
29: PetscStrfree(obj->prefix);
30: if (!prefix) {
31: obj->prefix = PETSC_NULL;
32: } else {
33: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
34: PetscStrallocpy(prefix,&obj->prefix);
35: }
36: return(0);
37: }
41: /*
42: PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
43: options of PetscObjectType in the database.
45: Input Parameters:
46: . obj - any PETSc object, for example a Vec, Mat or KSP.
47: . prefix - the prefix string to prepend to option requests of the object.
49: Notes:
50: A hyphen (-) must NOT be given at the beginning of the prefix name.
51: The first character of all runtime options is AUTOMATICALLY the
52: hyphen.
54: Concepts: prefix^setting
56: */
57: PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
58: {
59: char *buf = obj->prefix;
61: size_t len1,len2;
64: if (!prefix) {return(0);}
65: if (!buf) {
66: PetscObjectSetOptionsPrefix(obj,prefix);
67: return(0);
68: }
69: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
71: PetscStrlen(prefix,&len1);
72: PetscStrlen(buf,&len2);
73: PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
74: PetscStrcpy(obj->prefix,buf);
75: PetscStrcat(obj->prefix,prefix);
76: PetscFree(buf);
77: return(0);
78: }
82: /*
83: PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.
85: Input Parameters:
86: . obj - any PETSc object, for example a Vec, Mat or KSP.
88: Output Parameters:
89: . prefix - pointer to the prefix string used is returned
91: Concepts: prefix^getting
93: */
94: PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject obj,char *prefix[])
95: {
97: *prefix = obj->prefix;
98: return(0);
99: }
103: /*
104: PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
105: options of PetscObjectType in the database.
107: Input Parameters:
108: . obj - any PETSc object, for example a Vec, Mat or KSP.
109: . prefix - the prefix string to prepend to option requests of the object.
111: Notes:
112: A hyphen (-) must NOT be given at the beginning of the prefix name.
113: The first character of all runtime options is AUTOMATICALLY the
114: hyphen.
116: Concepts: prefix^setting
118: */
119: PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
120: {
121: char *buf = obj->prefix;
123: size_t len1,len2;
126: if (!prefix) {return(0);}
127: if (!buf) {
128: PetscObjectSetOptionsPrefix(obj,prefix);
129: return(0);
130: }
131: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
133: PetscStrlen(prefix,&len1);
134: PetscStrlen(buf,&len2);
135: PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
136: PetscStrcpy(obj->prefix,prefix);
137: PetscStrcat(obj->prefix,buf);
138: PetscFree(buf);
139: return(0);
140: }