Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/calcunits/QBits.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Wed Aug 3 10:14:23 2011 UTC (12 years, 9 months ago) by kaityo
File MIME type: text/x-chdr
File size: 2667 byte(s)
First commit
1 //---------------------------------------------------------------------------
2 // Represent bits states
3 //---------------------------------------------------------------------------
4 #ifndef QBITS_H
5 #define QBITS_H
6 //---------------------------------------------------------------------------
7 #include <iostream>
8 #include <sstream>
9 #include <stdio.h>
10 #include <string.h>
11
12 using namespace std;
13
14 class QResultInfo{
15 public:
16 char header[4];
17 char filename[256];
18 int bitnumber;
19 QResultInfo(void)
20 {
21 header[0] = 'q';
22 header[1] = 'd';
23 header[2] = 'a';
24 header[3] = 't';
25 bitnumber = 0;
26 for (int i=0;i<256;i++)
27 {
28 filename[i] = 0;
29 }
30 }
31 };
32
33 //---------------------------------------------------------------------------
34
35 class QBits
36 {
37 friend std::ostream &operator<<(std::ostream &os, const QBits &qb);
38 friend std::ostream &operator<<(std::ostream &os, const QBits *qb);
39
40 public:
41 QBits(void);
42 QBits(const int n);
43 QBits(char * filename);
44 QBits(const QBits &qubits);
45 ~QBits();
46
47 void Init(void);
48 bool Allocate(int n);
49 int GetNumberOfQBits(void) const {
50 return mNumberOfQbits;
51 }
52 int GetNumberOfStates(void) const {
53 return mNumberOfStates;
54 }
55 void Measure(int index){
56 mMeasured[index] = true;
57 };
58 bool isMeasured(int index){
59 return mMeasured[index];
60 };
61 int GetNumberOfMeasured(void);
62 string GetMeasuredString(int index);
63
64
65 double &NthStateR(const int nth) const;
66 double &NthStateI(const int nth) const;
67 double *GetBitsR(void) {
68 return mBitsR;
69 }
70 double *GetBitsI(void) {
71 return mBitsI;
72 }
73 double GetAbsoluteValue(int index);
74 double GetMeasuredValue(int index);
75
76 void PerformMeasurement(void);
77 void SaveMeasurementToStream(ostream &os);
78
79 void LoadFromFile(const char *filename);
80 void SaveToFile(const char *filename);
81 void SaveAsText(const char *filename);
82 void SaveToStream(ostream &ss);
83 bool IsValid(void){
84 return bValid;
85 };
86
87 private:
88
89 bool bValid;
90 int mNumberOfQbits; //n
91 int mNumberOfStates; //2^n
92 double *mBitsR; //Re
93 double *mBitsI; //Im
94
95 double *mBitsM;// Measured Values
96
97 bool *mMeasured; //Measured Flag
98
99 };
100
101 std::ostream &operator<<(std::ostream &os, const QBits &qb);
102 std::ostream &operator<<(std::ostream &os, const QBits *qb);
103 //---------------------------------------------------------------------------
104 #endif //QBITS_H

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26