GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_global.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_global.h"
26 
27 QMutex glc::iDMutex;
32 
34 {
35  static GLC_uint Id= 0;
36  glc::iDMutex.lock();
37  Id++;
38  glc::iDMutex.unlock();
39  return Id;
40 }
41 
43 {
44  static GLC_uint Id= 0;
45  glc::geomIdMutex.lock();
46  Id++;
47  glc::geomIdMutex.unlock();
48  return Id;
49 }
50 
52 {
53  static GLC_uint Id= 0;
54  glc::userIdMutex.lock();
55  Id++;
56  glc::userIdMutex.unlock();
57  return Id;
58 }
59 
61 {
62  static GLC_uint Id= 0;
63  glc::widget3dIdMutex.lock();
64  Id++;
65  glc::widget3dIdMutex.unlock();
66  return Id;
67 }
68 
70 {
71  static GLC_uint Id= 1;
73  Id++;
74  glc::shadingGroupIdMutex.unlock();
75  return Id;
76 }
77 
78 const QString glc::archivePrefix()
79 {
80  return "glc_Zip::";
81 }
82 
83 const QString glc::archiveInfix()
84 {
85  return "::glc_Zip::";
86 }
87 
88 const QString glc::filePrefix()
89 {
90  return "File::";
91 }
92 
93 const QString glc::fileInfix()
94 {
95  return "::File::";
96 }
97 
98 bool glc::isArchiveString(const QString& fileName)
99 {
100  bool inArchive= fileName.startsWith(archivePrefix());
101  inArchive= inArchive && fileName.contains(archiveInfix());
102  return inArchive;
103 }
104 
105 bool glc::isFileString(const QString& fileName)
106 {
107  bool inFile= fileName.startsWith(filePrefix());
108  inFile= inFile && fileName.contains(fileInfix());
109  return inFile;
110 }
111 
112 QString glc::builtArchiveString(const QString& Archive, const QString& entry)
113 {
114  return QString(archivePrefix() + Archive + archiveInfix() + entry);
115 }
116 
117 QString glc::builtFileString(const QString& File, const QString& entry)
118 {
119  const QString repFileName= QFileInfo(File).absolutePath() + QDir::separator() + entry;
120  return QString(filePrefix() + File + fileInfix() + repFileName);
121 }
122 
123 QString glc::archiveFileName(const QString& archiveString)
124 {
125  const bool isArchiveEncoded= isArchiveString(archiveString);
126  const bool isFileEncoded= isFileString(archiveString);
127 
128  Q_ASSERT(isArchiveEncoded || isFileEncoded);
129  QString infix;
130  QString prefix;
131  if (isArchiveEncoded)
132  {
133  infix= archiveInfix();
134  prefix= archivePrefix();
135  }
136  else if (isFileEncoded)
137  {
138  infix= fileInfix();
139  prefix= filePrefix();
140  }
141  const int indexOfInfix= archiveString.indexOf(infix);
142  const int prefixLength= prefix.length();
143  const int length= indexOfInfix - prefixLength;
144  return archiveString.mid(prefixLength, length);
145 }
146 
147 QString glc::archiveEntryFileName(const QString& archiveString)
148 {
149  const bool isArchiveEncoded= isArchiveString(archiveString);
150  const bool isFileEncoded= isFileString(archiveString);
151 
152  Q_ASSERT(isArchiveEncoded || isFileEncoded);
153  QString infix;
154  if (isArchiveEncoded)
155  {
156  infix= archiveInfix();
157  }
158  else if (isFileEncoded)
159  {
160  infix= fileInfix();
161  }
162  const int indexOfInfix= archiveString.indexOf(infix);
163  const int infixLength= infix.length();
164  const int length= archiveString.length() - (indexOfInfix + infixLength);
165  return archiveString.right(length);
166 }
167 

©2005-2013 Laurent Ribon