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: {
30: PetscStrfree(obj->prefix);
31: if (!prefix) {
32: obj->prefix = PETSC_NULL;
33: } else {
34: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
35: PetscStrallocpy(prefix,&obj->prefix);
36: }
37: return(0);
38: }
42: /*
43: PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
44: options of PetscObjectType in the database.
46: Input Parameters:
47: . obj - any PETSc object, for example a Vec, Mat or KSP.
48: . prefix - the prefix string to prepend to option requests of the object.
50: Notes:
51: A hyphen (-) must NOT be given at the beginning of the prefix name.
52: The first character of all runtime options is AUTOMATICALLY the
53: hyphen.
55: Concepts: prefix^setting
57: */
58: PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
59: {
60: char *buf = obj->prefix;
62: size_t len1,len2;
65: if (!prefix) {return(0);}
66: if (!buf) {
67: PetscObjectSetOptionsPrefix(obj,prefix);
68: return(0);
69: }
70: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
72: PetscStrlen(prefix,&len1);
73: PetscStrlen(buf,&len2);
74: PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
75: PetscStrcpy(obj->prefix,buf);
76: PetscStrcat(obj->prefix,prefix);
77: PetscFree(buf);
78: return(0);
79: }
83: /*
84: PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.
86: Input Parameters:
87: . obj - any PETSc object, for example a Vec, Mat or KSP.
89: Output Parameters:
90: . prefix - pointer to the prefix string used is returned
92: Concepts: prefix^getting
94: */
95: PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[])
96: {
98: *prefix = obj->prefix;
99: return(0);
100: }
104: /*
105: PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
106: options of PetscObjectType in the database.
108: Input Parameters:
109: . obj - any PETSc object, for example a Vec, Mat or KSP.
110: . prefix - the prefix string to prepend to option requests of the object.
112: Notes:
113: A hyphen (-) must NOT be given at the beginning of the prefix name.
114: The first character of all runtime options is AUTOMATICALLY the
115: hyphen.
117: Concepts: prefix^setting
119: */
120: PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
121: {
122: char *buf = obj->prefix;
124: size_t len1,len2;
127: if (!prefix) {return(0);}
128: if (!buf) {
129: PetscObjectSetOptionsPrefix(obj,prefix);
130: return(0);
131: }
132: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
134: PetscStrlen(prefix,&len1);
135: PetscStrlen(buf,&len2);
136: PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
137: PetscStrcpy(obj->prefix,prefix);
138: PetscStrcat(obj->prefix,buf);
139: PetscFree(buf);
140: return(0);
141: }