1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Partitioning/decimation module for the SALOME v3.2 platform
22 * \file MULTIPR_Utils.hxx
24 * \brief Some useful miscellaneous tools.
26 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
31 #ifndef MULTIPR_UTILS_HXX
32 #define MULTIPR_UTILS_HXX
48 * Removes all the pChar at the end of the string.
49 * \param pStr any valid C string ending with the char '\0'.
50 * \param pChar any char; SPACE by default.
51 * \return the same string where the ending spaces have been removed.
53 void trim(char* pStr, char pChar=' ');
57 * Returns true iff the given string starts by prefix.
58 * \param pStr any valid C string ending with the char '\0'.
59 * \param pStrPrefix any valid C string ending with the char '\0'.
60 * \return true iff the given string starts by prefix.
62 bool startsWith(const char* pStr, const char* pStrPrefix);
66 * Removes the extension (suffix) of a filename.
67 * Example: removeExtension("agregat100grains_12pas.med", ".med") -> "agregat100grains_12pas"
68 * \param pPilename any valid C string ending with the char '\0'.
69 * \param pExtension any valid C string ending with the char '\0'.
70 * \return the filename without extension.
72 std::string removeExtension(const char* pFilename, const char* pExtension);
76 * Returns the name of the file, excluding the path.
77 * Example: getFilenameWithoutPath("/home/data/agregat100grains_12pas.med") -> "agregat100grains_12pas.med"
78 * \param pPilename any valid C string ending with the char '\0'.
79 * \return the name of the file, excluding the path.
81 std::string getFilenameWithoutPath(const char* pFilename);
85 * Returns the path of the filename (which may be relative or absolute).
86 * Example: getPath("/home/data/agregat100grains_12pas.med") -> "/home/data/"
87 * \param pPilename any valid C string ending with the char '\0'.
88 * \return the path of the filename (which may be relative or absolute).
90 std::string getPath(const char* pFilename);
94 * Copies the given file into a directory.
95 * \param pFilename name of any file to be copied.
96 * \param pDestDir destination directory.
98 void copyFile(const char* pFilename, const char* pDestDir);
102 * Prints all the elements of a 2D array.
103 * \param pData all the data (should contain pNumberOfElements * pDimOfElements values)
104 * \param pNumElt number of elements to display.
105 * \param pDimElt Dimension of elements.
106 * \param pPrefix string to display before each element.
109 const med_float* pData,
112 const char* pPrefix);
116 * Converts any float value to a string (remove unecessary 0).
117 * \param mV any float value.
119 std::string realToString(med_float mV);
123 * Returns the name of all meshes contained in a sequential MED file.
124 * \param pMEDfilename name of any valid sequential MED file; must not be NULL.
125 * \return a list of mesh names.
126 * \throw NullArgumentException if pMEDfilename is NULL.
127 * \throw IOException if any other error occurs while reading MED file.
129 std::vector<std::string> getListMeshes(const char* pMEDfilename);
133 * For each scalar field in a sequential MED file, returns its name and the related number of time stamps.
134 * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields).
135 * \param pMEDfilename name of any valid sequential MED file; must not be NULL.
136 * \param pFields The information on the fields.
137 * \param pAddNbGaussPoint If set to true, the number of gauss point of each field is added.
138 * \param pMeshName Mesh name used if pAddNbGaussPoint is true.
139 * \throw NullArgumentException if pMEDfilename is NULL.
140 * \throw IOException if any other error occurs while reading MED file.
142 void getListScalarFields(const char* pMEDfilename, std::vector<std::pair<std::string, int> >& pFields, bool pAddNbGaussPoint = false, const char *pMeshName = NULL);
144 } // namespace MULTIPR
147 #endif // MULTIPR_UTILS_HXX