OSDN Git Service

revises makefile
[qcad/qcad.git] / qclib / qclib.cpp
1 /*\r
2  *  qclib.cpp\r
3  *  $Date: 2003/01/17 19:38:13 $\r
4  *  $Revision: 1.2 $\r
5  */\r
6  \r
7 #include <iostream>\r
8 #include <cstdlib>\r
9 #include <cmath>\r
10 #include <new>\r
11 #include "qclib.h"\r
12 #include "qcunitcalc.h"\r
13 #include "QBits.h"\r
14 \r
15 namespace qc {\r
16 \r
17 static QBits    *gQBits         = NULL;\r
18 static int      gNumberOfQBits  = 0;\r
19 static double   *gRe            = NULL;\r
20 static double   *gIm            = NULL;\r
21 static bool     gInitialized    = false;\r
22 \r
23 //----------------------------------------------------------------------------\r
24 /**\r
25  *  Initialize qclib\r
26  *  This function must be called at first.\r
27  */\r
28 void allocWith(const QBits &qBits)\r
29 {\r
30     try {\r
31         gQBits          = new QBits(qBits);\r
32         gNumberOfQBits  = gQBits->GetNumberOfQBits();\r
33         gRe             = gQBits->GetBitsR();\r
34         gIm             = gQBits->GetBitsI();\r
35         gInitialized    = true;\r
36     } catch (std::bad_alloc ex) {\r
37         std::cerr << "qclib: failed in init.\n";\r
38         std::exit(1);\r
39     }\r
40 }\r
41 \r
42 //----------------------------------------------------------------------------\r
43 /**\r
44  *  Get qubits\r
45  */\r
46 QBits *getQBits(void)\r
47 {\r
48     if (false == gInitialized)\r
49     {\r
50         std::cerr << "qclib: you must initialized correctly.\n";\r
51         std::exit(1);\r
52     }\r
53     return gQBits;\r
54 }\r
55 \r
56 //----------------------------------------------------------------------------\r
57 /**\r
58  *  Realease memory\r
59  *  This function should be called in the end.\r
60  */\r
61 void release(void)\r
62 {\r
63     if (NULL != gQBits) delete gQBits;\r
64     gQBits = NULL;\r
65 }\r
66 //----------------------------------------------------------------------------\r
67 } //qc\r