glc_global.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #include "glc_global.h"
00026 
00027 QMutex glc::iDMutex;
00028 QMutex glc::geomIdMutex;
00029 QMutex glc::userIdMutex;
00030 QMutex glc::widget3dIdMutex;
00031 QMutex glc::shadingGroupIdMutex;
00032 
00033 GLC_uint glc::GLC_GenID(void)
00034 {
00035         static GLC_uint Id= 0;
00036         glc::iDMutex.lock();
00037         Id++;
00038         glc::iDMutex.unlock();
00039         return Id;
00040 }
00041 
00042 GLC_uint glc::GLC_GenGeomID(void)
00043 {
00044         static GLC_uint Id= 0;
00045         glc::geomIdMutex.lock();
00046         Id++;
00047         glc::geomIdMutex.unlock();
00048         return Id;
00049 }
00050 
00051 GLC_uint glc::GLC_GenUserID(void)
00052 {
00053         static GLC_uint Id= 0;
00054         glc::userIdMutex.lock();
00055         Id++;
00056         glc::userIdMutex.unlock();
00057         return Id;
00058 }
00059 
00060 GLC_uint glc::GLC_Gen3DWidgetID(void)
00061 {
00062         static GLC_uint Id= 0;
00063         glc::widget3dIdMutex.lock();
00064         Id++;
00065         glc::widget3dIdMutex.unlock();
00066         return Id;
00067 }
00068 
00069 GLC_uint glc::GLC_GenShaderGroupID()
00070 {
00071         static GLC_uint Id= 1;
00072         glc::shadingGroupIdMutex.lock();
00073         Id++;
00074         glc::shadingGroupIdMutex.unlock();
00075         return Id;
00076 }
00077 
00078 const QString glc::archivePrefix()
00079 {
00080         return "glc_Zip::";
00081 }
00082 
00083 const QString glc::archiveInfix()
00084 {
00085         return "::glc_Zip::";
00086 }
00087 
00088 const QString glc::filePrefix()
00089 {
00090         return "File::";
00091 }
00092 
00093 const QString glc::fileInfix()
00094 {
00095         return "::File::";
00096 }
00097 
00098 bool glc::isArchiveString(const QString& fileName)
00099 {
00100         bool inArchive= fileName.startsWith(archivePrefix());
00101         inArchive= inArchive && fileName.contains(archiveInfix());
00102         return inArchive;
00103 }
00104 
00105 bool glc::isFileString(const QString& fileName)
00106 {
00107         bool inFile= fileName.startsWith(filePrefix());
00108         inFile= inFile && fileName.contains(fileInfix());
00109         return inFile;
00110 }
00111 
00112 QString glc::builtArchiveString(const QString& Archive, const QString& entry)
00113 {
00114         return QString(archivePrefix() + Archive + archiveInfix() + entry);
00115 }
00116 
00117 QString glc::builtFileString(const QString& File, const QString& entry)
00118 {
00119         const QString repFileName= QFileInfo(File).absolutePath() + QDir::separator() + entry;
00120         return QString(filePrefix() + File + fileInfix() + repFileName);
00121 }
00122 
00123 QString glc::archiveFileName(const QString& archiveString)
00124 {
00125         const bool isArchiveEncoded= isArchiveString(archiveString);
00126         const bool isFileEncoded= isFileString(archiveString);
00127 
00128         Q_ASSERT(isArchiveEncoded || isFileEncoded);
00129         QString infix;
00130         QString prefix;
00131         if (isArchiveEncoded)
00132         {
00133                 infix= archiveInfix();
00134                 prefix= archivePrefix();
00135         }
00136         else if (isFileEncoded)
00137         {
00138                 infix= fileInfix();
00139                 prefix= filePrefix();
00140         }
00141         const int indexOfInfix= archiveString.indexOf(infix);
00142         const int prefixLength= prefix.length();
00143         const int length= indexOfInfix - prefixLength;
00144         return archiveString.mid(prefixLength, length);
00145 }
00146 
00147 QString glc::archiveEntryFileName(const QString& archiveString)
00148 {
00149         const bool isArchiveEncoded= isArchiveString(archiveString);
00150         const bool isFileEncoded= isFileString(archiveString);
00151 
00152         Q_ASSERT(isArchiveEncoded || isFileEncoded);
00153         QString infix;
00154         if (isArchiveEncoded)
00155         {
00156                 infix= archiveInfix();
00157         }
00158         else if (isFileEncoded)
00159         {
00160                 infix= fileInfix();
00161         }
00162         const int indexOfInfix= archiveString.indexOf(infix);
00163         const int infixLength= infix.length();
00164         const int length= archiveString.length() - (indexOfInfix + infixLength);
00165         return archiveString.right(length);
00166 }
00167 

SourceForge.net Logo

©2005-2011 Laurent Ribon