MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
FileName Class Reference

#include <filename.h>

Inheritance diagram for FileName:
Collaboration diagram for FileName:

Public Member Functions

 FileName (const char *n=NULL, int i=0)
 
virtual ~FileName (void)
 
int iInit (const char *n, int i=0)
 
const char *const _sPutExt (const char *n)
 
const char *const sGet (void) const
 

Private Attributes

char * sName
 
char * sExt
 
char * sRef
 
unsigned int iMaxSize
 
unsigned int iCurSize
 

Detailed Description

Definition at line 91 of file filename.h.

Constructor & Destructor Documentation

FileName::FileName ( const char *  n = NULL,
int  i = 0 
)

Definition at line 41 of file fn_UNIX.cc.

References iInit().

42 : sName(NULL), sExt(NULL), sRef(NULL)
43 {
44  if (sFName != NULL) {
45  iInit(sFName, iExtSepNum);
46  }
47 }
char * sRef
Definition: filename.h:95
char * sExt
Definition: filename.h:94
char * sName
Definition: filename.h:93
int iInit(const char *n, int i=0)
Definition: fn_UNIX.cc:63

Here is the call graph for this function:

FileName::~FileName ( void  )
virtual

Definition at line 49 of file fn_UNIX.cc.

References SAFEDELETEARR, sExt, and sName.

50 {
51  if (sName != NULL) {
52  /* delete []sName; */
54  }
55 
56  if (sExt != NULL) {
57  /* delete []sExt; */
59  }
60 }
char * sExt
Definition: filename.h:94
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
char * sName
Definition: filename.h:93

Member Function Documentation

const char *const FileName::_sPutExt ( const char *  n)

Definition at line 161 of file fn_UNIX.cc.

References ASSERT, EXT_SEP, iCurSize, iMaxSize, SAFEDELETEARR, SAFENEWARR, sExt, sName, and sRef.

Referenced by OutputHandler::Open(), OutputHandler::RestartOpen(), and sGet().

162 {
163  if (sEName == NULL) {
164  sEName = sExt;
165  }
166 
167  unsigned int uExtLen = strlen(sEName);
168  if (sEName[0] != '\0' && sEName[0] != EXT_SEP) {
169  uExtLen++;
170  }
171 
172  if (iCurSize + uExtLen > iMaxSize) {
173  char *sTmp = NULL;
174  SAFENEWARR(sTmp, char, iCurSize + uExtLen + 1);
175 
176  ASSERT(sName != NULL);
177  strcpy(sTmp, sName);
178  sRef = sTmp + (sRef - sName);
180  sName = sTmp;
181  iMaxSize = iCurSize + uExtLen;
182  }
183 
184  ASSERT(sRef != NULL);
185  ASSERT(sEName != NULL);
186 
187  if (sEName[0] != '\0') {
188  char *sTmp = sRef;
189  if (sEName[0] != EXT_SEP) {
190  sTmp[0] = EXT_SEP;
191  sTmp++;
192  }
193  strcpy(sTmp, sEName);
194  }
195 
196  return sName;
197 }
char * sRef
Definition: filename.h:95
char * sExt
Definition: filename.h:94
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
char * sName
Definition: filename.h:93
unsigned int iCurSize
Definition: filename.h:97
const char EXT_SEP
Definition: filename.h:63
#define ASSERT(expression)
Definition: colamd.c:977
unsigned int iMaxSize
Definition: filename.h:96
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
int FileName::iInit ( const char *  n,
int  i = 0 
)

Definition at line 63 of file fn_UNIX.cc.

References ASSERT, DIR_SEP, EXT_SEP, iCurSize, iMaxSize, SAFEDELETEARR, SAFENEWARR, sExt, sName, and sRef.

Referenced by FileName(), and OutputHandler::Init().

64 {
65  ASSERT(sFName != NULL);
66 
67  if (sFName == NULL) {
68  return 0;
69  }
70 
71  unsigned int iNewSize = strlen(sFName);
72  if ((sName == NULL) || (iNewSize > iMaxSize)) {
73  if (sName != NULL) {
75  sName = NULL;
76  }
77  iMaxSize = iNewSize;
78  SAFENEWARR(sName, char, iMaxSize + 1);
79  }
80 
81  strcpy(sName, sFName);
82  sRef = (char *)sName + strlen(sName);
83  ASSERT(sRef[0] == '\0');
84 
85  if (iExtSepNum > 0) { /* se si parte dall'inizio */
86  while (--sRef > sName) { /* cerca il simbolo "/" */
87  if (sRef[0] == DIR_SEP) {
88  break;
89  }
90  }
91 
92  int iCnt = 0;
93  while (sRef[0] != '\0') { /* cerca il "." n. iExtSepNum */
94  if (sRef[0] == EXT_SEP) {
95  iCnt++;
96  if (iCnt == iExtSepNum) {
97  goto label;
98  }
99  }
100  sRef++;
101  }
102 
103 label:
104  iNewSize = strlen(sRef);
105  if (sExt == NULL || strlen(sExt) < iNewSize) {
106  /* se c'e' gia' sExt lo cancella */
107  if (sExt != NULL) {
109  }
110  SAFENEWARR(sExt, char, iNewSize+1);
111  }
112 
113  ASSERT(sRef != NULL);
114  strcpy(sExt, sRef);
115  sRef[0] = '\0';
116  } else if (iExtSepNum < 0) { /* se si parte dalla fine */
117  iExtSepNum = -iExtSepNum;
118  while (--sRef > sName) { /* cerca il simbolo "/" */
119  if (sRef[0] == DIR_SEP) {
120  break;
121  }
122  }
123 
124  int iCnt = 0;
125  char *sLim = sRef;
126  sRef = (char *)sName + strlen(sName);
127  while (--sRef > sLim) { /* cerca il "." n. iExtSepNum */
128  if (sRef[0] == EXT_SEP) {
129  iCnt++;
130  if (iCnt == iExtSepNum) {
131  goto label2;
132  }
133  }
134  }
135  sRef = (char *)sName + strlen(sName);
136 
137 label2:
138  iNewSize = strlen(sRef);
139  if (sExt == NULL || strlen(sExt) < iNewSize) {
140  if (sExt != NULL) {
142  }
143  SAFENEWARR(sExt, char, iNewSize + 1);
144  }
145 
146  ASSERT(sRef != NULL);
147  strcpy(sExt, sRef);
148  sRef[0] = '\0';
149  } else {
150  if (sExt == 0) {
151  SAFENEWARR(sExt, char, 1);
152  }
153  sExt[0] = '\0';
154  }
155 
156  iCurSize = iMaxSize - strlen(sExt);
157  return iCurSize;
158 }
char * sRef
Definition: filename.h:95
char * sExt
Definition: filename.h:94
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
char * sName
Definition: filename.h:93
unsigned int iCurSize
Definition: filename.h:97
const char DIR_SEP
Definition: filename.h:88
const char EXT_SEP
Definition: filename.h:63
#define ASSERT(expression)
Definition: colamd.c:977
unsigned int iMaxSize
Definition: filename.h:96
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
const char *const FileName::sGet ( void  ) const

Definition at line 200 of file fn_UNIX.cc.

References _sPutExt().

Referenced by OutputHandler::Open().

201 {
202  return const_cast<FileName *>(this)->_sPutExt(0);
203 }
const char *const _sPutExt(const char *n)
Definition: fn_UNIX.cc:161

Here is the call graph for this function:

Member Data Documentation

unsigned int FileName::iCurSize
mutableprivate

Definition at line 97 of file filename.h.

Referenced by _sPutExt(), and iInit().

unsigned int FileName::iMaxSize
mutableprivate

Definition at line 96 of file filename.h.

Referenced by _sPutExt(), and iInit().

char* FileName::sExt
mutableprivate

Definition at line 94 of file filename.h.

Referenced by _sPutExt(), iInit(), and ~FileName().

char* FileName::sName
mutableprivate

Definition at line 93 of file filename.h.

Referenced by _sPutExt(), iInit(), and ~FileName().

char* FileName::sRef
mutableprivate

Definition at line 95 of file filename.h.

Referenced by _sPutExt(), and iInit().


The documentation for this class was generated from the following files: