<commit_before>#include "common.h"

dcomplex exp_kr_O[3][11], exp_kr_H1[3][11], exp_kr_H2[3][11], exp_kr_ion[3][11];
dcomplex COMPLEX_ONE(1.0, 0.0);

void initialize_erfc_table() {
    double sqrt_alpha_1000 = sqrt(EWALD_ALPHA) / 1000.0, key;
    for (double r = 0.0; r < HALF_BOX_LENGTH; r += 0.001) {
        // to optimize map search by using one less division, we keep the keys as x10^4
        key = floor(r * 1000.0);
        (*ERFC_TABLE)[key] = erfc(key * sqrt_alpha_1000);
    }
    return;
}

void initialize_k_vectors_table() {
    // K vector order as follows (go through all ny and nzvalues descending, then ascending):
    double tmp_k2, half_factor, alpha_inv_4 = -1.0 / (4.0 * EWALD_ALPHA), four_pi_volume = 4.0 * M_PI / BOX_VOLUME;
    int k = 0;

    for (int nx = 0; nx <= 5; nx++) {
        for (int ny = -5; ny <= 5; ny++) {
            for (int nz = -5; nz <= 5; nz++) {
                if (nx != 0 || ny != 0 || nz != 0) { // removes the K=0 case
                    K_VECTORS[k] = new double[4];
                    K_VECTORS[k][0] = 2.0 * M_PI * nx / BOX_LENGTH;
                    K_VECTORS[k][1] = 2.0 * M_PI * ny / BOX_LENGTH;
                    K_VECTORS[k][2] = 2.0 * M_PI * nz / BOX_LENGTH;

                    // k_entry[3] will be the Fourier coefficient exp(-K^2 / (4*alpha)) / K^2, where K^2, or kx^2 + ky^2 + kz^2
                    tmp_k2 = K_VECTORS[k][0] * K_VECTORS[k][0] + K_VECTORS[k][1] * K_VECTORS[k][1] + K_VECTORS[k][2] * K_VECTORS[k][2];
                    K_VECTORS[k][3] = exp(tmp_k2 * alpha_inv_4) / tmp_k2;

                    // placing the 4*pi/V here allows for smaller number of multiplications and divisions later on
                    // half_factor accounts for double weighting of Fourier coefficients along the nx=0 plane
                    half_factor = (nx == 0) ? 0.5 : 1.0;
                    K_VECTORS[k][3] *= half_factor * four_pi_volume;
                    k++;
                }
            }
        }
    }
    return;
}

void initialize_rho_k_values_table() {
    dcomplex *column, column_sum;

    for (int k = 0; k < 725; k++) {
        column = new dcomplex [NUM_TOTAL_PARTICLES + 2];
        column_sum = dcomplex(0.0, 0.0);

        for (int w = 0; w < NUM_TOTAL_PARTICLES; w++) {
            column[w] = partial_rho(w, K_VECTORS[k]);
            column_sum += column[w];
        }

        column[NUM_TOTAL_PARTICLES] = column_sum;
        RHO_K_VALUES[k] = column;
    }

    for (int i = 0; i < 3; i++)
        exp_kr_O[i][5] = exp_kr_H1[i][5] = exp_kr_H2[i][5] = exp_kr_ion[i][5] = COMPLEX_ONE;

    return;
}

dcomplex partial_rho(int index, double * k_coords) {
    double rx, ry, rz, q;
    dcomplex part_rho(0.0, 0.0);

    if (index >= NUM_WATERS) {
        int ions_index = index - NUM_WATERS;
        rx = IONS[ions_index][0];
        ry = IONS[ions_index][1];
        rz = IONS[ions_index][2];
        part_rho = IONS[ions_index][3] * exp(dcomplex(0.0, k_coords[0] * rx + k_coords[1] * ry + k_coords[2] * rz));
    } else {
        for (int atom = 0; atom < 9; atom += 3) {
            q = (atom == 0) ? WATER_Q_O : WATER_Q_H;
            rx = WATER_POSITIONS[index][atom];
            ry = WATER_POSITIONS[index][atom + 1];
            rz = WATER_POSITIONS[index][atom + 2];
            part_rho += q * exp(dcomplex(0.0, k_coords[0] * rx + k_coords[1] * ry + k_coords[2] * rz));
        }
    }
    return part_rho;
}

double total_ewald_energy() {
    double ewald_energy = 0.0;
    for (int k = 0; k < 725; k++) {
        ewald_energy += norm(RHO_K_VALUES[k][NUM_TOTAL_PARTICLES]) * K_VECTORS[k][3];
    }
    return ewald_energy;
}

double ewald_diff(int index) {
    return (index >= NUM_WATERS) ? ewald_diff_ion(index) : ewald_diff_water(index);
}

double ewald_diff_water(int water_index) {
    set_exp_kr_table_for_water(water_index);
    double sum_of_ewald_diffs = 0.0, old_pk2;
    dcomplex *column, tmp_x_O, tmp_y_O, tmp_x_H1, tmp_y_H1, tmp_x_H2, tmp_y_H2;
    int k = 0;

    for (int nx = 0; nx <= 5; nx++) {
        tmp_x_O = WATER_Q_O * exp_kr_O[0][nx];
        tmp_x_H1 = WATER_Q_H * exp_kr_H1[0][nx];
        tmp_x_H2 = WATER_Q_H * exp_kr_H2[0][nx];

        for (int ny = 0; ny <= 10; ny++) {
            tmp_y_O = tmp_x_O * exp_kr_O[1][ny];
            tmp_y_H1 = tmp_x_H1 * exp_kr_H1[1][ny];
            tmp_y_H2 = tmp_x_H2 * exp_kr_H2[1][ny];

            for (int nz = 0; nz <= 10; nz++) {
                if (nx != 0 || ny != 5 || nz != 5) {
                    column = RHO_K_VALUES[k];
                    old_pk2 = norm(column[NUM_TOTAL_PARTICLES]);

                    // save old rho(K, R)
                    // calculate and save new rho(K, R)
                    // update total rho to rho(K, R)_new - rho(K, R)_old
                    column[NUM_TOTAL_PARTICLES + 1] = column[water_index];
                    column[water_index] = tmp_y_O * exp_kr_O[2][nz] + tmp_y_H1 * exp_kr_H1[2][nz] + tmp_y_H2 * exp_kr_H2[2][nz];
                    column[NUM_TOTAL_PARTICLES] += column[water_index] - column[NUM_TOTAL_PARTICLES + 1];

                    sum_of_ewald_diffs += (norm(column[NUM_TOTAL_PARTICLES]) - old_pk2) * K_VECTORS[k][3];
                    k++;
                }
            }
        }
    }
    return sum_of_ewald_diffs;
}

double ewald_diff_ion(int index) {
    int k = 0, ion_index = index - NUM_WATERS;
    set_exp_kr_table_for_ion(ion_index);
    double sum_of_ewald_diffs = 0.0, old_pk2;
    dcomplex *column, tmp_x_ion, tmp_y_ion;

    for (int nx = 0; nx <= 5; nx++) {
        tmp_x_ion = IONS[ion_index][3] * exp_kr_ion[0][nx];

        for (int ny = 0; ny <= 10; ny++) {
            tmp_y_ion = tmp_x_ion * exp_kr_ion[1][ny];

            for (int nz = 0; nz <= 10; nz++) {
                if (nx != 0 || ny != 5 || nz != 5) {
                    column = RHO_K_VALUES[k];
                    old_pk2 = norm(column[NUM_TOTAL_PARTICLES]);

                    // save old rho(K, R)
                    // calculate and save new rho(K, R)
                    // update total rho to rho(K, R)_new - rho(K, R)_old
                    column[NUM_TOTAL_PARTICLES + 1] = column[index];
                    column[index] = tmp_y_ion * exp_kr_ion[2][nz];
                    column[NUM_TOTAL_PARTICLES] += column[index] - column[NUM_TOTAL_PARTICLES + 1];

                    sum_of_ewald_diffs += (norm(column[NUM_TOTAL_PARTICLES]) - old_pk2) * K_VECTORS[k][3];
                    k++;
                }
            }
        }
    }
    return sum_of_ewald_diffs;
}

void set_exp_kr_table_for_water(int water_index) {
    for (int i = 0; i < 3; i++) {
        exp_kr_O[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i]));
        exp_kr_H1[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i + 3]));
        exp_kr_H2[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i + 6]));

        exp_kr_O[i][4] = COMPLEX_ONE / exp_kr_O[i][6];
        exp_kr_H1[i][4] = COMPLEX_ONE / exp_kr_H1[i][6];
        exp_kr_H2[i][4] = COMPLEX_ONE / exp_kr_H2[i][6];

        for (int j = 2; j <= 5; j++) {
            exp_kr_O[i][5 + j] = exp_kr_O[i][4 + j] * exp_kr_O[i][6];
            exp_kr_O[i][5 - j] = exp_kr_O[i][6 - j] * exp_kr_O[i][4];

            exp_kr_H1[i][5 + j] = exp_kr_H1[i][4 + j] * exp_kr_H1[i][6];
            exp_kr_H1[i][5 - j] = exp_kr_H1[i][6 - j] * exp_kr_H1[i][4];

            exp_kr_H2[i][5 + j] = exp_kr_H2[i][4 + j] * exp_kr_H2[i][6];
            exp_kr_H2[i][5 - j] = exp_kr_H2[i][6 - j] * exp_kr_H2[i][4];
        }
    }
    return;
}

void set_exp_kr_table_for_ion(int ion_index) {
    for (int i = 0; i < 3; i++) {
        exp_kr_ion[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * IONS[ion_index][i]));

        exp_kr_ion[i][4] = COMPLEX_ONE / exp_kr_ion[i][6];

        for (int j = 2; j <= 5; j++) {
            exp_kr_ion[i][5 + j] = exp_kr_ion[i][4 + j] * exp_kr_ion[i][6];
            exp_kr_ion[i][5 - j] = exp_kr_ion[i][6 - j] * exp_kr_ion[i][4];
        }
    }
    return;
}

void test_k_vector_table() {
    cout << "---- BEGIN TEST - TEST K VECTOR TABLE ----" << endl;

    BOX_LENGTH = 10.0;
    initialize_k_vectors_table();
    double * coords = K_VECTORS[0];
    cout << setprecision(10) << coords[0] << " " << coords[1] << " " << coords[2] << " " << coords[3] << endl;

    cout << "---- END TEST - TEST K VECTOR TABLE ----\n" << endl;
    return;
}
<commit_msg>conversion factor added to fix ewald energy units<commit_after>#include "common.h"

dcomplex exp_kr_O[3][11], exp_kr_H1[3][11], exp_kr_H2[3][11], exp_kr_ion[3][11];
dcomplex COMPLEX_ONE(1.0, 0.0);

void initialize_erfc_table() {
    double sqrt_alpha_1000 = sqrt(EWALD_ALPHA) / 1000.0, key;
    for (double r = 0.0; r < HALF_BOX_LENGTH; r += 0.001) {
        // to optimize map search by using one less division, we keep the keys as x10^4
        key = floor(r * 1000.0);
        (*ERFC_TABLE)[key] = erfc(key * sqrt_alpha_1000);
    }
    return;
}

void initialize_k_vectors_table() {
    // K vector order as follows (go through all ny and nzvalues descending, then ascending):
    double tmp_k2, half_factor, alpha_inv_4 = -1.0 / (4.0 * EWALD_ALPHA), four_pi_volume = 4.0 * M_PI / BOX_VOLUME;
    int k = 0;

    for (int nx = 0; nx <= 5; nx++) {
        for (int ny = -5; ny <= 5; ny++) {
            for (int nz = -5; nz <= 5; nz++) {
                if (nx != 0 || ny != 0 || nz != 0) { // removes the K=0 case
                    K_VECTORS[k] = new double[4];
                    K_VECTORS[k][0] = 2.0 * M_PI * nx / BOX_LENGTH;
                    K_VECTORS[k][1] = 2.0 * M_PI * ny / BOX_LENGTH;
                    K_VECTORS[k][2] = 2.0 * M_PI * nz / BOX_LENGTH;

                    // k_entry[3] will be the Fourier coefficient exp(-K^2 / (4*alpha)) / K^2, where K^2, or kx^2 + ky^2 + kz^2
                    tmp_k2 = K_VECTORS[k][0] * K_VECTORS[k][0] + K_VECTORS[k][1] * K_VECTORS[k][1] + K_VECTORS[k][2] * K_VECTORS[k][2];
                    K_VECTORS[k][3] = exp(tmp_k2 * alpha_inv_4) / tmp_k2;

                    // placing the 4*pi/V here allows for smaller number of multiplications and divisions later on
                    // half_factor accounts for double weighting of Fourier coefficients along the nx=0 plane
                    half_factor = (nx == 0) ? 0.5 : 1.0;
                    K_VECTORS[k][3] *= ELECTROSTATIC_K * half_factor * four_pi_volume;
                    k++;
                }
            }
        }
    }
    return;
}

void initialize_rho_k_values_table() {
    dcomplex *column, column_sum;

    for (int k = 0; k < 725; k++) {
        column = new dcomplex [NUM_TOTAL_PARTICLES + 2];
        column_sum = dcomplex(0.0, 0.0);

        for (int w = 0; w < NUM_TOTAL_PARTICLES; w++) {
            column[w] = partial_rho(w, K_VECTORS[k]);
            column_sum += column[w];
        }

        column[NUM_TOTAL_PARTICLES] = column_sum;
        RHO_K_VALUES[k] = column;
    }

    for (int i = 0; i < 3; i++)
        exp_kr_O[i][5] = exp_kr_H1[i][5] = exp_kr_H2[i][5] = exp_kr_ion[i][5] = COMPLEX_ONE;

    return;
}

dcomplex partial_rho(int index, double * k_coords) {
    double rx, ry, rz, q;
    dcomplex part_rho(0.0, 0.0);

    if (index >= NUM_WATERS) {
        int ions_index = index - NUM_WATERS;
        rx = IONS[ions_index][0];
        ry = IONS[ions_index][1];
        rz = IONS[ions_index][2];
        part_rho = IONS[ions_index][3] * exp(dcomplex(0.0, k_coords[0] * rx + k_coords[1] * ry + k_coords[2] * rz));
    } else {
        for (int atom = 0; atom < 9; atom += 3) {
            q = (atom == 0) ? WATER_Q_O : WATER_Q_H;
            rx = WATER_POSITIONS[index][atom];
            ry = WATER_POSITIONS[index][atom + 1];
            rz = WATER_POSITIONS[index][atom + 2];
            part_rho += q * exp(dcomplex(0.0, k_coords[0] * rx + k_coords[1] * ry + k_coords[2] * rz));
        }
    }
    return part_rho;
}

double total_ewald_energy() {
    double ewald_energy = 0.0;
    for (int k = 0; k < 725; k++) {
        ewald_energy += norm(RHO_K_VALUES[k][NUM_TOTAL_PARTICLES]) * K_VECTORS[k][3];
    }
    return ewald_energy;
}

double ewald_diff(int index) {
    return (index >= NUM_WATERS) ? ewald_diff_ion(index) : ewald_diff_water(index);
}

double ewald_diff_water(int water_index) {
    set_exp_kr_table_for_water(water_index);
    double sum_of_ewald_diffs = 0.0, old_pk2;
    dcomplex *column, tmp_x_O, tmp_y_O, tmp_x_H1, tmp_y_H1, tmp_x_H2, tmp_y_H2;
    int k = 0;

    for (int nx = 0; nx <= 5; nx++) {
        tmp_x_O = WATER_Q_O * exp_kr_O[0][nx];
        tmp_x_H1 = WATER_Q_H * exp_kr_H1[0][nx];
        tmp_x_H2 = WATER_Q_H * exp_kr_H2[0][nx];

        for (int ny = 0; ny <= 10; ny++) {
            tmp_y_O = tmp_x_O * exp_kr_O[1][ny];
            tmp_y_H1 = tmp_x_H1 * exp_kr_H1[1][ny];
            tmp_y_H2 = tmp_x_H2 * exp_kr_H2[1][ny];

            for (int nz = 0; nz <= 10; nz++) {
                if (nx != 0 || ny != 5 || nz != 5) {
                    column = RHO_K_VALUES[k];
                    old_pk2 = norm(column[NUM_TOTAL_PARTICLES]);

                    // save old rho(K, R)
                    // calculate and save new rho(K, R)
                    // update total rho to rho(K, R)_new - rho(K, R)_old
                    column[NUM_TOTAL_PARTICLES + 1] = column[water_index];
                    column[water_index] = tmp_y_O * exp_kr_O[2][nz] + tmp_y_H1 * exp_kr_H1[2][nz] + tmp_y_H2 * exp_kr_H2[2][nz];
                    column[NUM_TOTAL_PARTICLES] += column[water_index] - column[NUM_TOTAL_PARTICLES + 1];

                    sum_of_ewald_diffs += (norm(column[NUM_TOTAL_PARTICLES]) - old_pk2) * K_VECTORS[k][3];
                    k++;
                }
            }
        }
    }
    return sum_of_ewald_diffs;
}

double ewald_diff_ion(int index) {
    int k = 0, ion_index = index - NUM_WATERS;
    set_exp_kr_table_for_ion(ion_index);
    double sum_of_ewald_diffs = 0.0, old_pk2;
    dcomplex *column, tmp_x_ion, tmp_y_ion;

    for (int nx = 0; nx <= 5; nx++) {
        tmp_x_ion = IONS[ion_index][3] * exp_kr_ion[0][nx];

        for (int ny = 0; ny <= 10; ny++) {
            tmp_y_ion = tmp_x_ion * exp_kr_ion[1][ny];

            for (int nz = 0; nz <= 10; nz++) {
                if (nx != 0 || ny != 5 || nz != 5) {
                    column = RHO_K_VALUES[k];
                    old_pk2 = norm(column[NUM_TOTAL_PARTICLES]);

                    // save old rho(K, R)
                    // calculate and save new rho(K, R)
                    // update total rho to rho(K, R)_new - rho(K, R)_old
                    column[NUM_TOTAL_PARTICLES + 1] = column[index];
                    column[index] = tmp_y_ion * exp_kr_ion[2][nz];
                    column[NUM_TOTAL_PARTICLES] += column[index] - column[NUM_TOTAL_PARTICLES + 1];

                    sum_of_ewald_diffs += (norm(column[NUM_TOTAL_PARTICLES]) - old_pk2) * K_VECTORS[k][3];
                    k++;
                }
            }
        }
    }
    return sum_of_ewald_diffs;
}

void set_exp_kr_table_for_water(int water_index) {
    for (int i = 0; i < 3; i++) {
        exp_kr_O[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i]));
        exp_kr_H1[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i + 3]));
        exp_kr_H2[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * WATER_POSITIONS[water_index][i + 6]));

        exp_kr_O[i][4] = COMPLEX_ONE / exp_kr_O[i][6];
        exp_kr_H1[i][4] = COMPLEX_ONE / exp_kr_H1[i][6];
        exp_kr_H2[i][4] = COMPLEX_ONE / exp_kr_H2[i][6];

        for (int j = 2; j <= 5; j++) {
            exp_kr_O[i][5 + j] = exp_kr_O[i][4 + j] * exp_kr_O[i][6];
            exp_kr_O[i][5 - j] = exp_kr_O[i][6 - j] * exp_kr_O[i][4];

            exp_kr_H1[i][5 + j] = exp_kr_H1[i][4 + j] * exp_kr_H1[i][6];
            exp_kr_H1[i][5 - j] = exp_kr_H1[i][6 - j] * exp_kr_H1[i][4];

            exp_kr_H2[i][5 + j] = exp_kr_H2[i][4 + j] * exp_kr_H2[i][6];
            exp_kr_H2[i][5 - j] = exp_kr_H2[i][6 - j] * exp_kr_H2[i][4];
        }
    }
    return;
}

void set_exp_kr_table_for_ion(int ion_index) {
    for (int i = 0; i < 3; i++) {
        exp_kr_ion[i][6] = exp(dcomplex(0.0, K_VECTORS[71][i] * IONS[ion_index][i]));

        exp_kr_ion[i][4] = COMPLEX_ONE / exp_kr_ion[i][6];

        for (int j = 2; j <= 5; j++) {
            exp_kr_ion[i][5 + j] = exp_kr_ion[i][4 + j] * exp_kr_ion[i][6];
            exp_kr_ion[i][5 - j] = exp_kr_ion[i][6 - j] * exp_kr_ion[i][4];
        }
    }
    return;
}

void test_k_vector_table() {
    cout << "---- BEGIN TEST - TEST K VECTOR TABLE ----" << endl;

    BOX_LENGTH = 10.0;
    initialize_k_vectors_table();
    double * coords = K_VECTORS[0];
    cout << setprecision(10) << coords[0] << " " << coords[1] << " " << coords[2] << " " << coords[3] << endl;

    cout << "---- END TEST - TEST K VECTOR TABLE ----\n" << endl;
    return;
}
<|endoftext|>


<commit_before>#ifndef SOLAIRE_FORMAT_HPP
#define SOLAIRE_FORMAT_HPP

//Copyright 2015 Adam Smith
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

// Contact :
// Email             : solairelibrary@mail.com
// GitHub repository : https://github.com/SolaireLibrary/SolaireCPP

/*!
	\file Format.hpp
	\brief
	\author
	Created			: Adam Smith
	Last modified	: Adam Smith
	\version 1.0
	\date
	Created			: 16th January 2016
	Last Modified	: 16th January 2016
*/

#include "Solaire/Core/IStream.hpp"
#include "Solaire/Core/OStream.hpp"
#include "Solaire/Encode/GenericValue.hpp"
#include "Solaire/Encode/Encoder.hpp"

namespace Solaire {

	SOLAIRE_EXPORT_INTERFACE Format {
    public:
        SOLAIRE_EXPORT_CALL ~Format(){}
        GenericValue SOLAIRE_EXPORT_CALL readValue(IStream&) const throw();
        bool SOLAIRE_EXPORT_CALL writeValue(const GenericValue&, OStream&) const throw();

        template<class T>
        typename Encoder<T>::DecodeType read(Allocator& aAllocator, IStream& aStream) {
            return Encoder<T>::decode(aAllocator, readValue(aStream));
        }

        template<class T>
        bool write(Allocator& aAllocator, const T& aValue, OStream& aStream) {
            return writeValue(Encoder<T>::encode(aAllocator, aValue), aStream);
        }
	};
}

#endif
<commit_msg>Inlined templated formatting<commit_after>#ifndef SOLAIRE_FORMAT_HPP
#define SOLAIRE_FORMAT_HPP

//Copyright 2015 Adam Smith
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

// Contact :
// Email             : solairelibrary@mail.com
// GitHub repository : https://github.com/SolaireLibrary/SolaireCPP

/*!
	\file Format.hpp
	\brief
	\author
	Created			: Adam Smith
	Last modified	: Adam Smith
	\version 1.0
	\date
	Created			: 16th January 2016
	Last Modified	: 16th January 2016
*/

#include "Solaire/Core/IStream.hpp"
#include "Solaire/Core/OStream.hpp"
#include "Solaire/Encode/GenericValue.hpp"
#include "Solaire/Encode/Encoder.hpp"

namespace Solaire {

	SOLAIRE_EXPORT_INTERFACE Format {
    public:
        SOLAIRE_EXPORT_CALL ~Format(){}
        GenericValue SOLAIRE_EXPORT_CALL readValue(IStream&) const throw();
        bool SOLAIRE_EXPORT_CALL writeValue(const GenericValue&, OStream&) const throw();

        template<class T>
        SOLAIRE_FORCE_INLINE typename Encoder<T>::DecodeType read(Allocator& aAllocator, IStream& aStream) {
            return Encoder<T>::decode(aAllocator, readValue(aStream));
        }

        template<class T>
        SOLAIRE_FORCE_INLINE bool write(Allocator& aAllocator, const T& aValue, OStream& aStream) {
            return writeValue(Encoder<T>::encode(aAllocator, aValue), aStream);
        }
	};
}

#endif
<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2016, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//      * Redistributions of source code must retain the above
//        copyright notice, this list of conditions and the following
//        disclaimer.
//
//      * Redistributions in binary form must reproduce the above
//        copyright notice, this list of conditions and the following
//        disclaimer in the documentation and/or other materials provided with
//        the distribution.
//
//      * Neither the name of John Haddon nor the names of
//        any other contributors to this software may be used to endorse or
//        promote products derived from this software without specific prior
//        written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include "boost/python.hpp"

#include "PlugAdderBinding.h"

#include "GafferUIBindings/GadgetBinding.h"

#include "GafferUI/PlugAdder.h"

#include "GafferBindings/SignalBinding.h"

#include "Gaffer/Plug.h"

#include "IECorePython/ExceptionAlgo.h"
#include "IECorePython/ScopedGILLock.h"

using namespace boost::python;
using namespace std;
using namespace Gaffer;
using namespace GafferBindings;
using namespace GafferUI;
using namespace GafferUIBindings;

namespace
{

struct PlugMenuSignalCaller
{

	PlugPtr call( PlugAdder::PlugMenuSignal &s, const std::string &title, const vector<Plug *> &plugs )
	{
		return s( title, plugs );
	}

};

struct PlugMenuSlotCaller
{

	Plug *operator()( boost::python::object slot, const std::string &title, const vector<Plug *> &plugs )
	{
		try
		{
			boost::python::list pythonPlugs;
			for( vector<Plug *>::const_iterator it = plugs.begin(), eIt = plugs.end(); it != eIt; ++it )
			{
				pythonPlugs.append( PlugPtr( *it ) );
			}
			object r = slot( title, pythonPlugs );

			return extract<Plug *>( r );
		}
		catch( const error_already_set &e )
		{
			IECorePython::ExceptionAlgo::translatePythonException();
		}
		return nullptr;
	}

};

struct PlugAdderWrapper : public GadgetWrapper<PlugAdder>
{

	PlugAdderWrapper(PyObject *self, StandardNodeGadget::Edge edge )
		: GadgetWrapper<PlugAdder>( self, edge )
	{
	}

	bool acceptsPlug( const Gaffer::Plug *connectionEndPoint ) const override
	{
		if( this->isSubclassed() )
		{
			IECorePython::ScopedGILLock gilLock;
			boost::python::object f = this->methodOverride( "acceptsPlug" );
			if( f )
			{
				try
				{
					return f( Gaffer::PlugPtr( const_cast<Gaffer::Plug *>( connectionEndPoint ) ) );
				}
				catch( const error_already_set &e )
				{
					IECorePython::ExceptionAlgo::translatePythonException();
				}
			}
		}
		throw IECore::Exception( "No acceptsPlug method defined in Python." );
	}

	void addPlug( Gaffer::Plug *connectionEndPoint ) override
	{
		if( this->isSubclassed() )
		{
			IECorePython::ScopedGILLock gilLock;
			boost::python::object f = this->methodOverride( "addPlug" );
			if( f )
			{
				try
				{
					f( Gaffer::PlugPtr( const_cast<Gaffer::Plug *>( connectionEndPoint ) ) );
					return;
				}
				catch( const error_already_set &e )
				{
					IECorePython::ExceptionAlgo::translatePythonException();
				}
			}
		}
		throw IECore::Exception( "No addPlug method defined in Python." );
	}
};

} // namespace

void GafferUIModule::bindPlugAdder()
{
	scope s = GadgetClass<PlugAdder, PlugAdderWrapper>( "PlugAdder" )
		.def( init<StandardNodeGadget::Edge>() )
		.def( "plugMenuSignal", &PlugAdder::plugMenuSignal, return_value_policy<reference_existing_object>() )
		.staticmethod( "plugMenuSignal" )
		.def( "acceptsPlug", &PlugAdderWrapper::acceptsPlug )
		.def( "addPlug", &PlugAdderWrapper::addPlug )
	;

	SignalClass<PlugAdder::PlugMenuSignal, PlugMenuSignalCaller, PlugMenuSlotCaller>( "PlugMenuSignal" );
}
<commit_msg>PlugAdderBinding : update to support new API<commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2016, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//      * Redistributions of source code must retain the above
//        copyright notice, this list of conditions and the following
//        disclaimer.
//
//      * Redistributions in binary form must reproduce the above
//        copyright notice, this list of conditions and the following
//        disclaimer in the documentation and/or other materials provided with
//        the distribution.
//
//      * Neither the name of John Haddon nor the names of
//        any other contributors to this software may be used to endorse or
//        promote products derived from this software without specific prior
//        written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include "boost/python.hpp"

#include "PlugAdderBinding.h"

#include "GafferUIBindings/GadgetBinding.h"

#include "GafferUI/PlugAdder.h"

#include "GafferBindings/SignalBinding.h"

#include "Gaffer/Plug.h"

#include "IECorePython/ExceptionAlgo.h"
#include "IECorePython/ScopedGILLock.h"

using namespace boost::python;
using namespace std;
using namespace Gaffer;
using namespace GafferBindings;
using namespace GafferUI;
using namespace GafferUIBindings;

namespace
{

struct PlugMenuSignalCaller
{

	PlugPtr call( PlugAdder::PlugMenuSignal &s, const std::string &title, const vector<Plug *> &plugs )
	{
		return s( title, plugs );
	}

};

struct PlugMenuSlotCaller
{

	Plug *operator()( boost::python::object slot, const std::string &title, const vector<Plug *> &plugs )
	{
		try
		{
			boost::python::list pythonPlugs;
			for( vector<Plug *>::const_iterator it = plugs.begin(), eIt = plugs.end(); it != eIt; ++it )
			{
				pythonPlugs.append( PlugPtr( *it ) );
			}
			object r = slot( title, pythonPlugs );

			return extract<Plug *>( r );
		}
		catch( const error_already_set &e )
		{
			IECorePython::ExceptionAlgo::translatePythonException();
		}
		return nullptr;
	}

};

struct PlugAdderWrapper : public GadgetWrapper<PlugAdder>
{

	PlugAdderWrapper(PyObject *self, StandardNodeGadget::Edge edge )
		: GadgetWrapper<PlugAdder>( self, edge )
	{
	}

	bool canCreateConnection( const Gaffer::Plug *endpoint ) override
	{
		if( this->isSubclassed() )
		{
			IECorePython::ScopedGILLock gilLock;
			boost::python::object f = this->methodOverride( "canCreateConnection" );
			if( f )
			{
				try
				{
					return f( Gaffer::PlugPtr( const_cast<Gaffer::Plug *>( endpoint ) ) );
				}
				catch( const error_already_set &e )
				{
					IECorePython::ExceptionAlgo::translatePythonException();
				}
			}
		}
		throw IECore::Exception( "No canCreateConnection method defined in Python." );
	}

	void createConnection( Gaffer::Plug *endpoint ) override
	{
		if( this->isSubclassed() )
		{
			IECorePython::ScopedGILLock gilLock;
			boost::python::object f = this->methodOverride( "createConnection" );
			if( f )
			{
				try
				{
					f( Gaffer::PlugPtr( const_cast<Gaffer::Plug *>( endpoint ) ) );
					return;
				}
				catch( const error_already_set &e )
				{
					IECorePython::ExceptionAlgo::translatePythonException();
				}
			}
		}
		throw IECore::Exception( "No canCreateConnection method defined in Python." );
	}
};

} // namespace

void GafferUIModule::bindPlugAdder()
{
	scope s = GadgetClass<PlugAdder, PlugAdderWrapper>( "PlugAdder" )
		.def( init<StandardNodeGadget::Edge>() )
		.def( "plugMenuSignal", &PlugAdder::plugMenuSignal, return_value_policy<reference_existing_object>() )
		.staticmethod( "plugMenuSignal" )
		.def( "canCreateConnection", &PlugAdderWrapper::canCreateConnection )
		.def( "createConnection", &PlugAdderWrapper::createConnection )
	;

	SignalClass<PlugAdder::PlugMenuSignal, PlugMenuSignalCaller, PlugMenuSlotCaller>( "PlugMenuSignal" );
}
<|endoftext|>


<commit_before>#include "pcloudwindow.h"
#include "ui_pcloudwindow.h"
#include "pcloudapp.h"
#include "common.h"

#include <QDesktopServices>
#include <QUrl>
#include<QDebug>

PCloudWindow::PCloudWindow(PCloudApp *a,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PCloudWindow)
{
    app=a;
    ui->setupUi(this);

    // the window consists of QListWidget(for icon-buttons) and
    //QStackedWidget which loads different page according to selected item in the listWidget (and hides other pages)

    ui->listButtonsWidget->setViewMode(QListView::IconMode);
    ui->listButtonsWidget->setFlow(QListWidget::LeftToRight); //orientation
    ui->listButtonsWidget->setSpacing(12);

    ui->listButtonsWidget->setStyleSheet("background-color:transparent");
    //ui->listButtonsWidget->setWrapping(true); //
    //ui->listButtonsWidget->setSelectionRectVisible(false); //
    ui->listButtonsWidget->setMovement(QListView::Static); //not to move items with the mouse
    //temp
    ui->listButtonsWidget->setMinimumWidth(360);
    ui->listButtonsWidget->setMaximumHeight(85);
    ui->listButtonsWidget->setMinimumHeight(84); // precakva mi layouta
    // TEMP comment ui->listButtonsWidget->setFrameStyle(QFrame::Sunken); //hides frame

    //create Items for QListWidget
    new QListWidgetItem(QIcon(":/images/images/user.png"),tr("Account"),ui->listButtonsWidget); //index 0
    new QListWidgetItem(QIcon(":/images/images/user.png"),tr("Account"),ui->listButtonsWidget); //index 1
    new QListWidgetItem(QIcon(":/images/images/shares.png"),tr("Shares"),ui->listButtonsWidget); //index 2
    //QListWidgetItem *linksItem = new QListWidgetItem(QIcon(":/images/images/online.png"),tr("Links"),ui->listButtonsWidget);
    new QListWidgetItem(ui->listButtonsWidget); // temp hide page, not managed yet index 3
    new QListWidgetItem(QIcon(":/images/images/settings.png"),tr("Settings"),ui->listButtonsWidget); //index 4
    new QListWidgetItem(QIcon(":/images/images/help.png"),tr("Help"),ui->listButtonsWidget); //index 5
    new QListWidgetItem(QIcon(":/images/images/info.png"),tr("About"),ui->listButtonsWidget); //index 6

    fillAcountNotLoggedPage();
    fillAboutPage();
    fillHelpPage();
    settngsPage = new SettingsPage(this, app);

    // indexes of Items in listWidget and their coresponding pages in StackWidget are the same
    connect(ui->listButtonsWidget,
            SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
            this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));

    connect(ui->btnShareFolder,SIGNAL(clicked()), app, SLOT(shareFolder()));

    //for resize
    for(int i = 0; i < ui->pagesWidget->count(); i++)
        ui->pagesWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

    ui->verticalLayout_10->setAlignment(Qt::AlignCenter); //tab help

    setWindowIcon(QIcon(WINDOW_ICON));
    setWindowTitle("pCloud");
}

PCloudWindow::~PCloudWindow()
{
    delete ui;
}

void PCloudWindow::closeEvent(QCloseEvent *event)
{
    hide();
    event->ignore();
}

void PCloudWindow::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (!current)
        current = previous;
    int currentIndex = ui->listButtonsWidget->row(current);

    // auto resize
    for(int i = 0; i < ui->pagesWidget->count(); i++)
    {
        if ( i != currentIndex)
            ui->pagesWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    }
    ui->pagesWidget->widget(currentIndex)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    updateGeometry();

    //layout()->activate();
    //setFixedSize(minimumSizeHint());

    ui->pagesWidget->setCurrentIndex(currentIndex); // sets page
    refreshPages();

}
void PCloudWindow::showEvent(QShowEvent *)
{
    refreshPages();
}

void PCloudWindow::refreshPages()
{
    int currentIndex = ui->listButtonsWidget->currentRow();
    if (currentIndex == 1 && verifyClicked) // Account page, case when user has clicked Verify Email
    {
        checkVerify();
        return;
    }
    if (currentIndex == 2) //shares page
    {
        sharesPage->load(0);
        return;
    }
    if (currentIndex == 4) //settings page, if user has changed smthng but hasn't save it
    {
        settngsPage->initSettingsPage();
        return;
    }
}

void PCloudWindow::showpcloudWindow(int index)
{
    ui->listButtonsWidget->setCurrentRow(index);
    ui->pagesWidget->setCurrentIndex(index);

    this->raise();
    this->activateWindow();
    this->showNormal();
    this->setWindowState(Qt::WindowActive);
    app->setActiveWindow(this);
}

void PCloudWindow::setOnlineItems(bool online) // change pcloud window menu when is loggedin and loggedout
{
    if(online)
    {
        ui->listButtonsWidget->setRowHidden(0,true); //Accont - not logged
        ui->listButtonsWidget->setRowHidden(1,false); //Account - logged
        ui->listButtonsWidget->setRowHidden(2,false); //Shares
        ui->listButtonsWidget->setRowHidden(3,false); //Links
    }
    else
    {
        ui->listButtonsWidget->setRowHidden(0,false);
        ui->listButtonsWidget->setRowHidden(1,true);
        ui->listButtonsWidget->setRowHidden(2,true);
        ui->listButtonsWidget->setRowHidden(3,true);
    }
}

void PCloudWindow::setOnlinePages()
{
    sharesPage = new SharesPage(this, app);
    fillAccountLoggedPage();

}
void PCloudWindow::fillAcountNotLoggedPage()
{
    connect(ui->btnLogin, SIGNAL(clicked()),app, SLOT(showLogin()));
    connect(ui->btnRegstr, SIGNAL(clicked()), app, SLOT(showRegister()));
    connect(ui->btnExit, SIGNAL(clicked()), app, SLOT(doExit())); // to move slot in this class
    connect(ui->toolBtnContact, SIGNAL(clicked()), this, SLOT(contactUs()));
    ui->toolBtnContact->setStyleSheet("QToolButton{background-color:transparent;} QToolButton:hover{text-decoration: underline; background-color: transparent;}");
}

void PCloudWindow::fillAboutPage()
{
    ui->label_versionVal->setText(APP_VERSION);
}

void PCloudWindow::fillHelpPage()
{
    connect(ui->tBtnOnlineHelp, SIGNAL(clicked()), this, SLOT(openOnlineHelp()));
    connect(ui->tBtnOnlineTutorial, SIGNAL(clicked()), this, SLOT(openOnlineTutorial()));
    connect(ui->tBtnFeedback, SIGNAL(clicked()), this, SLOT(sendFeedback()));
}

void PCloudWindow::fillAccountLoggedPage()
{
    ui->label_email->setText(app->username);
    if (app->isVerified)
    {
        ui->btnVerify->setVisible(false);
        ui->checkBoxVerified->setCheckState(Qt::Checked);
    }
    else
    {
        ui->checkBoxVerified->setCheckState(Qt::Unchecked);
        ui->btnVerify->setVisible(true);
        connect(ui->btnVerify, SIGNAL(clicked()), this, SLOT(verifyEmail()));
    }
    ui->checkBoxVerified->setEnabled(false);

    ui->progressBar_space->setMinimum(0);
    ui->progressBar_space->setMaximum(100);
    ui->progressBar_space->setValue(app->freeSpacePercentage);
    ui->progressBar_space->setFormat("%v% free");
    ui->label_space->setText(QString::number(app->usedSpace, 'f', 1) + " GB used of " + app->plan);

    ui->label_planVal->setText(app->plan);

    ui->toolBtnChangePass->setStyleSheet("QToolButton{background-color:transparent;} QToolButton:hover{text-decoration: underline; background-color: transparent;}");
    connect(ui->toolBtnOpenWeb, SIGNAL(clicked()), this, SLOT(openWebPage()));
    connect(ui->toolBtnChangePass, SIGNAL(clicked()), this, SLOT(changePass()));
    connect(ui->tbtnGetSpace, SIGNAL(clicked()), this, SLOT(upgradePlan()));
    ui->tbtnGetSpace->setVisible(false);
    connect(ui->tbtnOpenFolder, SIGNAL(clicked()),app,SLOT(openCloudDir()));
    connect(ui->tBtnExit, SIGNAL(clicked()), app, SLOT(doExit())); // to move in this class
    connect(ui->tBtnLogout, SIGNAL(clicked()), app, SLOT(logOut()));
    connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(upgradePlan()));

}

//SLOTS
void PCloudWindow::openWebPage()
{
    QUrl url("https://my.pcloud.com/#page=filemanager");
    QDesktopServices::openUrl(url);
}

void PCloudWindow::changePass()
{
    QUrl url("https://my.pcloud.com/#page=changepassword");
    QDesktopServices::openUrl(url);
}

void PCloudWindow::upgradePlan()
{
    QUrl url("https://my.pcloud.com/#page=plans&authtoken="+app->authentication);
    QDesktopServices::openUrl(url);
}

void PCloudWindow::sendFeedback()
{
    QUrl url("https://my.pcloud.com/#page=contact"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::openOnlineTutorial(){

    QUrl url ("https://my.pcloud.com/#page=contact&tutorial=show"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::openOnlineHelp()
{
    QUrl url ("https://my.pcloud.com/#page=faq"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::contactUs(){
    QUrl url ("https://my.pcloud.com/#page=contact");
    QDesktopServices::openUrl(url);
}
void PCloudWindow::verifyEmail(){
    apisock *conn=app->getAPISock();
    auth=app->authentication.toUtf8();
    binresult *res;
    res=send_command(conn, "sendverificationemail",
                     P_LSTR("auth", auth.constData(), auth.size()));
    checkConnErr(res);
    QMessageBox::information(this, "Please check your e-mail", "E-mail verification sent to: "+app->username);
    api_close(conn);
    verifyClicked = true;
}

void PCloudWindow::checkVerify()
{
    apisock *conn=app->getAPISock();
    binresult *res;
    if (!conn)
        return;
    res=send_command(conn, "userinfo",
                     P_LSTR("auth", auth.constData(), auth.size()));
    api_close(conn);
    bool verified =  find_res(res, "emailverified")->num;
    checkConnErr(res);
    if (verified)
    {
        ui->checkBoxVerified->setChecked(true);
        ui->btnVerify->setVisible(false);
        verifyClicked = false;
    }
}

void PCloudWindow::checkConnErr(binresult *res)
{
    binresult *result=find_res(res, "result");
    if (!result){
        QMessageBox::information(this,"", "Could not connect to server. Check your Internet connection.");
        free(res);
        return;
    }
    if (result->num!=0){
        QMessageBox::information(this,"",find_res(res, "error")->str);
        free(res);
        return;
    }
    free(res);
}
<commit_msg>verify update<commit_after>#include "pcloudwindow.h"
#include "ui_pcloudwindow.h"
#include "pcloudapp.h"
#include "common.h"

#include <QDesktopServices>
#include <QUrl>
#include<QDebug>

PCloudWindow::PCloudWindow(PCloudApp *a,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PCloudWindow)
{
    app=a;
    ui->setupUi(this);
    this->verifyClicked = false;

    // the window consists of QListWidget(for icon-buttons) and
    //QStackedWidget which loads different page according to selected item in the listWidget (and hides other pages)

    ui->listButtonsWidget->setViewMode(QListView::IconMode);
    ui->listButtonsWidget->setFlow(QListWidget::LeftToRight); //orientation
    ui->listButtonsWidget->setSpacing(12);

    ui->listButtonsWidget->setStyleSheet("background-color:transparent");
    //ui->listButtonsWidget->setWrapping(true); //
    //ui->listButtonsWidget->setSelectionRectVisible(false); //
    ui->listButtonsWidget->setMovement(QListView::Static); //not to move items with the mouse
    //temp
    ui->listButtonsWidget->setMinimumWidth(360);
    ui->listButtonsWidget->setMaximumHeight(85);
    ui->listButtonsWidget->setMinimumHeight(84); // precakva mi layouta
    // TEMP comment ui->listButtonsWidget->setFrameStyle(QFrame::Sunken); //hides frame

    //create Items for QListWidget
    new QListWidgetItem(QIcon(":/images/images/user.png"),tr("Account"),ui->listButtonsWidget); //index 0
    new QListWidgetItem(QIcon(":/images/images/user.png"),tr("Account"),ui->listButtonsWidget); //index 1
    new QListWidgetItem(QIcon(":/images/images/shares.png"),tr("Shares"),ui->listButtonsWidget); //index 2
    //QListWidgetItem *linksItem = new QListWidgetItem(QIcon(":/images/images/online.png"),tr("Links"),ui->listButtonsWidget);
    new QListWidgetItem(ui->listButtonsWidget); // temp hide page, not managed yet index 3
    new QListWidgetItem(QIcon(":/images/images/settings.png"),tr("Settings"),ui->listButtonsWidget); //index 4
    new QListWidgetItem(QIcon(":/images/images/help.png"),tr("Help"),ui->listButtonsWidget); //index 5
    new QListWidgetItem(QIcon(":/images/images/info.png"),tr("About"),ui->listButtonsWidget); //index 6

    fillAcountNotLoggedPage();
    fillAboutPage();
    fillHelpPage();
    settngsPage = new SettingsPage(this, app);

    // indexes of Items in listWidget and their coresponding pages in StackWidget are the same
    connect(ui->listButtonsWidget,
            SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
            this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));

    connect(ui->btnShareFolder,SIGNAL(clicked()), app, SLOT(shareFolder()));

    //for resize
    for(int i = 0; i < ui->pagesWidget->count(); i++)
        ui->pagesWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

    ui->verticalLayout_10->setAlignment(Qt::AlignCenter); //tab help

    setWindowIcon(QIcon(WINDOW_ICON));
    setWindowTitle("pCloud");
}

PCloudWindow::~PCloudWindow()
{
    delete ui;
}

void PCloudWindow::closeEvent(QCloseEvent *event)
{
    hide();
    event->ignore();
}

void PCloudWindow::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (!current)
        current = previous;
    int currentIndex = ui->listButtonsWidget->row(current);

    // auto resize
    for(int i = 0; i < ui->pagesWidget->count(); i++)
    {
        if ( i != currentIndex)
            ui->pagesWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    }
    ui->pagesWidget->widget(currentIndex)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    updateGeometry();

    //layout()->activate();
    //setFixedSize(minimumSizeHint());

    ui->pagesWidget->setCurrentIndex(currentIndex); // sets page
    refreshPages();

}
void PCloudWindow::showEvent(QShowEvent *)
{
    refreshPages();
}

void PCloudWindow::refreshPages()
{
    int currentIndex = ui->listButtonsWidget->currentRow();
    if (currentIndex == 1 && verifyClicked) // Account page, case when user has clicked Verify Email
    {
        checkVerify();
        return;
    }
    if (currentIndex == 2) //shares page
    {
        sharesPage->load(0);
        return;
    }
    if (currentIndex == 4) //settings page, if user has changed smthng but hasn't save it
    {
        settngsPage->initSettingsPage();
        return;
    }
}

void PCloudWindow::showpcloudWindow(int index)
{
    ui->listButtonsWidget->setCurrentRow(index);
    ui->pagesWidget->setCurrentIndex(index);

    this->raise();
    this->activateWindow();
    this->showNormal();
    this->setWindowState(Qt::WindowActive);
    app->setActiveWindow(this);
}

void PCloudWindow::setOnlineItems(bool online) // change pcloud window menu when is loggedin and loggedout
{
    if(online)
    {
        ui->listButtonsWidget->setRowHidden(0,true); //Accont - not logged
        ui->listButtonsWidget->setRowHidden(1,false); //Account - logged
        ui->listButtonsWidget->setRowHidden(2,false); //Shares
        ui->listButtonsWidget->setRowHidden(3,false); //Links
    }
    else
    {
        ui->listButtonsWidget->setRowHidden(0,false);
        ui->listButtonsWidget->setRowHidden(1,true);
        ui->listButtonsWidget->setRowHidden(2,true);
        ui->listButtonsWidget->setRowHidden(3,true);
    }
}

void PCloudWindow::setOnlinePages()
{
    sharesPage = new SharesPage(this, app);
    fillAccountLoggedPage();

}
void PCloudWindow::fillAcountNotLoggedPage()
{
    connect(ui->btnLogin, SIGNAL(clicked()),app, SLOT(showLogin()));
    connect(ui->btnRegstr, SIGNAL(clicked()), app, SLOT(showRegister()));
    connect(ui->btnExit, SIGNAL(clicked()), app, SLOT(doExit())); // to move slot in this class
    connect(ui->toolBtnContact, SIGNAL(clicked()), this, SLOT(contactUs()));
    ui->toolBtnContact->setStyleSheet("QToolButton{background-color:transparent;} QToolButton:hover{text-decoration: underline; background-color: transparent;}");
}

void PCloudWindow::fillAboutPage()
{
    ui->label_versionVal->setText(APP_VERSION);
}

void PCloudWindow::fillHelpPage()
{
    connect(ui->tBtnOnlineHelp, SIGNAL(clicked()), this, SLOT(openOnlineHelp()));
    connect(ui->tBtnOnlineTutorial, SIGNAL(clicked()), this, SLOT(openOnlineTutorial()));
    connect(ui->tBtnFeedback, SIGNAL(clicked()), this, SLOT(sendFeedback()));
}

void PCloudWindow::fillAccountLoggedPage()
{
    ui->label_email->setText(app->username);
    if (app->isVerified)
    {
        ui->btnVerify->setVisible(false);
        ui->checkBoxVerified->setCheckState(Qt::Checked);
    }
    else
    {
        ui->checkBoxVerified->setCheckState(Qt::Unchecked);
        ui->btnVerify->setVisible(true);
        connect(ui->btnVerify, SIGNAL(clicked()), this, SLOT(verifyEmail()));
    }
    ui->checkBoxVerified->setEnabled(false);

    ui->progressBar_space->setMinimum(0);
    ui->progressBar_space->setMaximum(100);
    ui->progressBar_space->setValue(app->freeSpacePercentage);
    ui->progressBar_space->setFormat("%v% free");
    ui->label_space->setText(QString::number(app->usedSpace, 'f', 1) + " GB used of " + app->plan);

    ui->label_planVal->setText(app->plan);

    ui->toolBtnChangePass->setStyleSheet("QToolButton{background-color:transparent;} QToolButton:hover{text-decoration: underline; background-color: transparent;}");
    connect(ui->toolBtnOpenWeb, SIGNAL(clicked()), this, SLOT(openWebPage()));
    connect(ui->toolBtnChangePass, SIGNAL(clicked()), this, SLOT(changePass()));
    connect(ui->tbtnGetSpace, SIGNAL(clicked()), this, SLOT(upgradePlan()));
    ui->tbtnGetSpace->setVisible(false);
    connect(ui->tbtnOpenFolder, SIGNAL(clicked()),app,SLOT(openCloudDir()));
    connect(ui->tBtnExit, SIGNAL(clicked()), app, SLOT(doExit())); // to move in this class
    connect(ui->tBtnLogout, SIGNAL(clicked()), app, SLOT(logOut()));
    connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(upgradePlan()));

}

//SLOTS
void PCloudWindow::openWebPage()
{
    QUrl url("https://my.pcloud.com/#page=filemanager");
    QDesktopServices::openUrl(url);
}

void PCloudWindow::changePass()
{
    QUrl url("https://my.pcloud.com/#page=changepassword");
    QDesktopServices::openUrl(url);
}

void PCloudWindow::upgradePlan()
{
    QUrl url("https://my.pcloud.com/#page=plans&authtoken="+app->authentication);
    QDesktopServices::openUrl(url);
}

void PCloudWindow::sendFeedback()
{
    QUrl url("https://my.pcloud.com/#page=contact"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::openOnlineTutorial(){

    QUrl url ("https://my.pcloud.com/#page=contact&tutorial=show"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::openOnlineHelp()
{
    QUrl url ("https://my.pcloud.com/#page=faq"); //to check
    QDesktopServices::openUrl(url);
}

void PCloudWindow::contactUs(){
    QUrl url ("https://my.pcloud.com/#page=contact");
    QDesktopServices::openUrl(url);
}
void PCloudWindow::verifyEmail(){
    apisock *conn=app->getAPISock();
    auth=app->authentication.toUtf8();
    binresult *res;
    res=send_command(conn, "sendverificationemail",
                     P_LSTR("auth", auth.constData(), auth.size()));
    checkConnErr(res);
    free(res);
    api_close(conn);
    QMessageBox::information(this, "Please check your e-mail", "E-mail verification sent to: "+app->username);

    verifyClicked = true;
}

void PCloudWindow::checkVerify()
{
    apisock *conn=app->getAPISock();
    auth=app->authentication.toUtf8();
    binresult *res;
    if (!conn)
        return;
    res=send_command(conn, "userinfo",
                     P_LSTR("auth", auth.constData(), auth.size()));
    checkConnErr(res);
    bool verified =  find_res(res, "emailverified")->num;
    free(res);
    api_close(conn);
    if (verified)
    {
        ui->checkBoxVerified->setChecked(true);
        ui->btnVerify->setVisible(false);
        verifyClicked = false;
    }
}

void PCloudWindow::checkConnErr(binresult *res)
{
    binresult *result=find_res(res, "result");
    if (!result){
        QMessageBox::information(this,"", "Could not connect to server. Check your Internet connection.");
        free(res);
        return;
    }
    if (result->num!=0){
        QMessageBox::information(this,"",find_res(res, "error")->str);
        free(res);
        return;
    }
}
<|endoftext|>


<commit_before>// @(#)root/base:$Name:  $:$Id: TAttAxis.cxx,v 1.14 2007/01/12 09:31:33 brun Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TFile.h"
#include "TAttAxis.h"
#include "TStyle.h"
#include "TVirtualPad.h"
#include "TColor.h"
#include "TClass.h"
#include "TMathBase.h"

ClassImp(TAttAxis)

//______________________________________________________________________________
//
//  Manages histogram axis attributes
//

TAttAxis::TAttAxis()
{
   // Constructor.
   ResetAttAxis();
}

//______________________________________________________________________________
TAttAxis::~TAttAxis()
{
   // Destructor.
}

//______________________________________________________________________________
void TAttAxis::Copy(TAttAxis &attaxis) const
{
   // Copy of the object.

   attaxis.fNdivisions  = fNdivisions;
   attaxis.fAxisColor   = fAxisColor;
   attaxis.fLabelColor  = fLabelColor;
   attaxis.fLabelFont   = fLabelFont;
   attaxis.fLabelOffset = fLabelOffset;
   attaxis.fLabelSize   = fLabelSize;
   attaxis.fTickLength  = fTickLength;
   attaxis.fTitleOffset = fTitleOffset;
   attaxis.fTitleSize   = fTitleSize;
   attaxis.fTitleColor  = fTitleColor;
   attaxis.fTitleFont   = fTitleFont;
}

//______________________________________________________________________________
void TAttAxis::ResetAttAxis(Option_t *option)
{
   // Reset axis attributes

   if (gStyle) {
      fNdivisions  = gStyle->GetNdivisions(option);
      fAxisColor   = gStyle->GetAxisColor(option);
      fLabelColor  = gStyle->GetLabelColor(option);
      fLabelFont   = gStyle->GetLabelFont(option);
      fLabelOffset = gStyle->GetLabelOffset(option);
      fLabelSize   = gStyle->GetLabelSize(option);
      fTickLength  = gStyle->GetTickLength(option);
      fTitleOffset = gStyle->GetTitleOffset(option);
      fTitleSize   = gStyle->GetTitleSize(option);
      fTitleColor  = gStyle->GetTitleColor(option);
      fTitleFont   = gStyle->GetTitleFont(option);
   } else {
      fNdivisions  = 510;
      fAxisColor   = 1;
      fLabelColor  = 1;
      fLabelFont   = 62;
      fLabelOffset = 0.005;
      fLabelSize   = 0.04;
      fTickLength  = 0.03;
      fTitleOffset = 1;
      fTitleSize   = fLabelSize;
      fTitleColor  = 1;
      fTitleFont   = 62;
   }
}

//______________________________________________________________________________
void TAttAxis::SaveAttributes(ostream &out, const char *name, const char *subname)
{
    // Save axis attributes as C++ statement(s) on output stream out

   if (fNdivisions != 510) {
      out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
   }
   if (fAxisColor != 1) {
      if (fAxisColor > 228) {
         TColor::SaveColor(out, fAxisColor);
         out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
   }
   if (fLabelColor != 1) {
      if (fLabelColor > 228) {
         TColor::SaveColor(out, fLabelColor);
         out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
   }
   if (fLabelFont != 62) {
      out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
   }
   if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
      out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
   }
   if (TMath::Abs(fLabelSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
   }
   if (TMath::Abs(fTitleSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
   }
   if (TMath::Abs(fTickLength-0.03) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
   }
   if (TMath::Abs(fTitleOffset-1) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
   }
   if (fTitleColor != 1) {
      if (fTitleColor > 228) {
         TColor::SaveColor(out, fTitleColor);
         out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
   }
   if (fTitleFont != 62) {
      out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttAxis::SetAxisColor(Color_t color)
{
   // Set color of the line axis and tick marks

   fAxisColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelColor(Color_t color)
{
   // Set color of labels

   fLabelColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelFont(Style_t font)
{
   // Set labels' font.

   fLabelFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelOffset(Float_t offset)
{
   // Set distance between the axis and the labels
   // The distance is expressed in per cent of the pad width

   fLabelOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelSize(Float_t size)
{
   // Set size of axis labels
   // The size is expressed in per cent of the pad width

   fLabelSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
{
   // Set the number of divisions for this axis.
   //
   // if optim = kTRUE (default), the number of divisions will be
   //                   optimized around the specified value.
   // if optim = kFALSE, or n < 0, the axis will be forced to use
   //                   exactly n divisions.
   //
   // n = n1 + 100*n2 + 10000*n3
   //
   // Where n1 is the number of primary divisions,
   // n2 is the number of second order divisions and
   // n3 is the number of third order divisions.
   //
   // e.g. 512 means 12 primary and 5 secondary divisions.
   //
   // If the number of divisions is "optimized" (see above) n1, n2, n3 are
   // maximum values.

   fNdivisions = n;
   if (!optim) fNdivisions = -abs(n);
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTickLength(Float_t length)
{
   // Set tick mark length
   // The length is expressed in per cent of the pad width

   fTickLength = length;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleOffset(Float_t offset)
{
   // Set distance between the axis and the axis title
   // Offset is a correction factor with respect to the "standard" value.
   // offset = 1  uses the default position that is computed in function
   // of the label offset and size.
   // offset = 1.2 will add 20 per cent more to the default offset.

   fTitleOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleSize(Float_t size)
{
   // Set size of axis title
   // The size is expressed in per cent of the pad width

   fTitleSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleColor(Color_t color)
{
   // Set color of axis title

   fTitleColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleFont(Style_t font)
{
   // Set the title font.

   fTitleFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::Streamer(TBuffer &R__b)
{
   // Stream an object of class TAttAxis.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 3) {
         TAttAxis::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      R__b >> fNdivisions;
      R__b >> fAxisColor;
      R__b >> fLabelColor;
      R__b >> fLabelFont;
      R__b >> fLabelOffset;
      R__b >> fLabelSize;
      R__b >> fTickLength;
      R__b >> fTitleOffset;
      // !file is the case of only TMapFile
      TFile *file = (TFile*)R__b.GetParent();
      if (R__v > 1 && (!file || (file && file->GetVersion() > 900)))
         R__b >> fTitleSize;
      else
         fTitleSize = fLabelSize;
      if (R__v > 2) {
         R__b >> fTitleColor;
         R__b >> fTitleFont;
      }
      //====end of old versions

   } else {
      TAttAxis::Class()->WriteBuffer(R__b,this);
   }
}
<commit_msg>Remove dependency from TFile (thanks to new function TBuffer::GetVersionOwner)<commit_after>// @(#)root/base:$Name:  $:$Id: TAttAxis.cxx,v 1.15 2007/01/15 11:52:01 rdm Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TAttAxis.h"
#include "TStyle.h"
#include "TVirtualPad.h"
#include "TColor.h"
#include "TClass.h"
#include "TMathBase.h"

ClassImp(TAttAxis)

//______________________________________________________________________________
//
//  Manages histogram axis attributes
//

TAttAxis::TAttAxis()
{
   // Constructor.
   ResetAttAxis();
}

//______________________________________________________________________________
TAttAxis::~TAttAxis()
{
   // Destructor.
}

//______________________________________________________________________________
void TAttAxis::Copy(TAttAxis &attaxis) const
{
   // Copy of the object.

   attaxis.fNdivisions  = fNdivisions;
   attaxis.fAxisColor   = fAxisColor;
   attaxis.fLabelColor  = fLabelColor;
   attaxis.fLabelFont   = fLabelFont;
   attaxis.fLabelOffset = fLabelOffset;
   attaxis.fLabelSize   = fLabelSize;
   attaxis.fTickLength  = fTickLength;
   attaxis.fTitleOffset = fTitleOffset;
   attaxis.fTitleSize   = fTitleSize;
   attaxis.fTitleColor  = fTitleColor;
   attaxis.fTitleFont   = fTitleFont;
}

//______________________________________________________________________________
void TAttAxis::ResetAttAxis(Option_t *option)
{
   // Reset axis attributes

   if (gStyle) {
      fNdivisions  = gStyle->GetNdivisions(option);
      fAxisColor   = gStyle->GetAxisColor(option);
      fLabelColor  = gStyle->GetLabelColor(option);
      fLabelFont   = gStyle->GetLabelFont(option);
      fLabelOffset = gStyle->GetLabelOffset(option);
      fLabelSize   = gStyle->GetLabelSize(option);
      fTickLength  = gStyle->GetTickLength(option);
      fTitleOffset = gStyle->GetTitleOffset(option);
      fTitleSize   = gStyle->GetTitleSize(option);
      fTitleColor  = gStyle->GetTitleColor(option);
      fTitleFont   = gStyle->GetTitleFont(option);
   } else {
      fNdivisions  = 510;
      fAxisColor   = 1;
      fLabelColor  = 1;
      fLabelFont   = 62;
      fLabelOffset = 0.005;
      fLabelSize   = 0.04;
      fTickLength  = 0.03;
      fTitleOffset = 1;
      fTitleSize   = fLabelSize;
      fTitleColor  = 1;
      fTitleFont   = 62;
   }
}

//______________________________________________________________________________
void TAttAxis::SaveAttributes(ostream &out, const char *name, const char *subname)
{
    // Save axis attributes as C++ statement(s) on output stream out

   if (fNdivisions != 510) {
      out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
   }
   if (fAxisColor != 1) {
      if (fAxisColor > 228) {
         TColor::SaveColor(out, fAxisColor);
         out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
   }
   if (fLabelColor != 1) {
      if (fLabelColor > 228) {
         TColor::SaveColor(out, fLabelColor);
         out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
   }
   if (fLabelFont != 62) {
      out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
   }
   if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
      out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
   }
   if (TMath::Abs(fLabelSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
   }
   if (TMath::Abs(fTitleSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
   }
   if (TMath::Abs(fTickLength-0.03) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
   }
   if (TMath::Abs(fTitleOffset-1) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
   }
   if (fTitleColor != 1) {
      if (fTitleColor > 228) {
         TColor::SaveColor(out, fTitleColor);
         out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
   }
   if (fTitleFont != 62) {
      out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttAxis::SetAxisColor(Color_t color)
{
   // Set color of the line axis and tick marks

   fAxisColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelColor(Color_t color)
{
   // Set color of labels

   fLabelColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelFont(Style_t font)
{
   // Set labels' font.

   fLabelFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelOffset(Float_t offset)
{
   // Set distance between the axis and the labels
   // The distance is expressed in per cent of the pad width

   fLabelOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelSize(Float_t size)
{
   // Set size of axis labels
   // The size is expressed in per cent of the pad width

   fLabelSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
{
   // Set the number of divisions for this axis.
   //
   // if optim = kTRUE (default), the number of divisions will be
   //                   optimized around the specified value.
   // if optim = kFALSE, or n < 0, the axis will be forced to use
   //                   exactly n divisions.
   //
   // n = n1 + 100*n2 + 10000*n3
   //
   // Where n1 is the number of primary divisions,
   // n2 is the number of second order divisions and
   // n3 is the number of third order divisions.
   //
   // e.g. 512 means 12 primary and 5 secondary divisions.
   //
   // If the number of divisions is "optimized" (see above) n1, n2, n3 are
   // maximum values.

   fNdivisions = n;
   if (!optim) fNdivisions = -abs(n);
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTickLength(Float_t length)
{
   // Set tick mark length
   // The length is expressed in per cent of the pad width

   fTickLength = length;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleOffset(Float_t offset)
{
   // Set distance between the axis and the axis title
   // Offset is a correction factor with respect to the "standard" value.
   // offset = 1  uses the default position that is computed in function
   // of the label offset and size.
   // offset = 1.2 will add 20 per cent more to the default offset.

   fTitleOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleSize(Float_t size)
{
   // Set size of axis title
   // The size is expressed in per cent of the pad width

   fTitleSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleColor(Color_t color)
{
   // Set color of axis title

   fTitleColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleFont(Style_t font)
{
   // Set the title font.

   fTitleFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::Streamer(TBuffer &R__b)
{
   // Stream an object of class TAttAxis.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 3) {
         TAttAxis::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      R__b >> fNdivisions;
      R__b >> fAxisColor;
      R__b >> fLabelColor;
      R__b >> fLabelFont;
      R__b >> fLabelOffset;
      R__b >> fLabelSize;
      R__b >> fTickLength;
      R__b >> fTitleOffset;

      if (R__v > 1 && R__b.GetVersionOwner() > 900)
         R__b >> fTitleSize;
      else
         fTitleSize = fLabelSize;
      if (R__v > 2) {
         R__b >> fTitleColor;
         R__b >> fTitleFont;
      }
      //====end of old versions

   } else {
      TAttAxis::Class()->WriteBuffer(R__b,this);
   }
}
<|endoftext|>


<commit_before>// @(#)root/base:$Name:  $:$Id: TBrowser.cxx,v 1.1.1.1 2000/05/16 17:00:38 rdm Exp $
// Author: Fons Rademakers   25/10/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Using a TBrowser one can browse all ROOT objects. It shows in a list //
// on the left side of the window all browsable ROOT classes. Selecting //
// one of the classes displays, in the iconbox on the right side, all   //
// objects in the class. Selecting one of the objects in the iconbox,   //
// will place all browsable objects in a new list and draws the         //
// contents of the selected class in the iconbox. And so on....         //
//                                                                      //
//Begin_Html  End_Html                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TBrowser.h"
#include "TGuiFactory.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TTimer.h"
#include "TContextMenu.h"
#include "TInterpreter.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TBrowserTimer                                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TBrowserTimer : public TTimer {

protected:
   TBrowser *fBrowser;
   Bool_t    fActivate;

public:
   TBrowserTimer(TBrowser *b, Long_t ms = 1000)
      : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
   Bool_t Notify();
};

ClassImp(TBrowser)

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title)
   : TNamed(name, title)
{
   // Create a new browser with a name, title. Width and height are by
   // default set to 640x400 and (optionally) adjusted by the screen factor
   // (depending on Rint.Canvas.UseScreenFactor to be true or false, default
   // is true).

   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*640);
   UInt_t h = UInt_t(cx*400);

   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height.

   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, position, width and height.

   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*640);
   UInt_t h = UInt_t(cx*400);

   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create(obj);
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create(obj);
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create(obj);
}
//______________________________________________________________________________
TBrowser::~TBrowser()
{
   // Delete the browser.

   gROOT->GetListOfBrowsers()->Remove(this);
   if (fContextMenu) { delete fContextMenu; fContextMenu = 0; }
   if (fTimer) delete fTimer;
   delete fImp;
}

//______________________________________________________________________________
void TBrowser::Add(TObject *obj, const char *name)
{
   // Add object with name to browser. If name not set the objects GetName()
   // is used.

   if (obj && fImp) {
      fImp->Add(obj, name);
      obj->SetBit(kMustCleanup);
   }
}

//______________________________________________________________________________
void TBrowser::Create(TObject *obj)
{
   // Create the browser, called by the ctors.

   fNeedRefresh = kFALSE;

   fTimer = new TBrowserTimer(this);
   if (fTimer) gSystem->AddTimer(fTimer);

   gROOT->GetListOfBrowsers()->Add(this);

   // Get the list of globals
   gROOT->GetListOfGlobals(kTRUE);
   gROOT->GetListOfGlobalFunctions(kTRUE);

   fContextMenu = new TContextMenu("BrowserContextMenu") ;

   // Fill the first list from the present TObject obj
   if (obj) {
      Add(obj);
#ifndef WIN32
      if (fImp) fImp->BrowseObj(obj);
#else
 //     obj->Browse(this);
#endif
   }
   // Fill the first list with all browsable classes from TROOT
#ifndef WIN32
   else if (fImp) fImp->BrowseObj(gROOT);
#else
   // The first list will be filled by TWin32BrowserImp ctor
   // with all browsable classes from TROOT
#endif
}

//______________________________________________________________________________
void TBrowser::ExecuteDefaultAction(TObject *obj)
{
   // Execute default action for selected object (action is specified
   // in the $HOME/.root.mimes or $ROOTSYS/icons/root.mimes file.

   if (obj && fImp)
      fImp->ExecuteDefaultAction(obj);
}

//______________________________________________________________________________
TObject *TBrowser::GetSelected()
{
 // return the last selected object
 return fLastSelectedObject;
}

//______________________________________________________________________________
void TBrowser::RecursiveRemove(TObject *obj)
{
   // Recursively remove obj from browser.

   if (fImp && obj) {
      fImp->RecursiveRemove(obj);
      fNeedRefresh = kTRUE;
   }
}

//______________________________________________________________________________
void TBrowser::Refresh()
{
   // Refresh browser contents.

   fNeedRefresh = kTRUE;
   if (fImp) fImp->Refresh();
   fNeedRefresh = kFALSE;
}

//______________________________________________________________________________
void TBrowser::SetSelected(TObject *clickedObject)
{
 // assign the last selected object
 fLastSelectedObject = clickedObject;
}

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TBrowserTimer                                                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

//______________________________________________________________________________
Bool_t TBrowserTimer::Notify()
{
   // Called whenever timer times out.

   if (fBrowser) {
      if (fBrowser->GetRefreshFlag()) {
         fBrowser->SetRefreshFlag(kFALSE);
         fActivate = kTRUE;
      } else if (fActivate) {
         fActivate = kFALSE;
         fBrowser->Refresh();
      }
   }
   Reset();

   return kFALSE;
}
<commit_msg>cosmetics.<commit_after>// @(#)root/base:$Name:  $:$Id: TBrowser.cxx,v 1.2 2000/09/08 07:40:59 brun Exp $
// Author: Fons Rademakers   25/10/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Using a TBrowser one can browse all ROOT objects. It shows in a list //
// on the left side of the window all browsable ROOT classes. Selecting //
// one of the classes displays, in the iconbox on the right side, all   //
// objects in the class. Selecting one of the objects in the iconbox,   //
// will place all browsable objects in a new list and draws the         //
// contents of the selected class in the iconbox. And so on....         //
//                                                                      //
//Begin_Html  End_Html                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TBrowser.h"
#include "TGuiFactory.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TTimer.h"
#include "TContextMenu.h"
#include "TInterpreter.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TBrowserTimer                                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TBrowserTimer : public TTimer {

protected:
   TBrowser *fBrowser;
   Bool_t    fActivate;

public:
   TBrowserTimer(TBrowser *b, Long_t ms = 1000)
      : TTimer(ms, kTRUE), fBrowser(b), fActivate(kFALSE) { }
   Bool_t Notify();
};

ClassImp(TBrowser)

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title)
   : TNamed(name, title)
{
   // Create a new browser with a name, title. Width and height are by
   // default set to 640x400 and (optionally) adjusted by the screen factor
   // (depending on Rint.Canvas.UseScreenFactor to be true or false, default
   // is true).

   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*640);
   UInt_t h = UInt_t(cx*400);

   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height.

   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, position, width and height.

   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create();
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   Float_t cx = gStyle->GetScreenFactor();
   UInt_t w = UInt_t(cx*640);
   UInt_t h = UInt_t(cx*400);

   fImp = gGuiFactory->CreateBrowserImp(this, title, w, h);
   Create(obj);
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   fImp = gGuiFactory->CreateBrowserImp(this, title, width, height);
   Create(obj);
}

//______________________________________________________________________________
TBrowser::TBrowser(const char *name, TObject *obj, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height)
   : TNamed(name, title)
{
   // Create a new browser with a name, title, width and height for TObject *obj.

   fImp = gGuiFactory->CreateBrowserImp(this, title, x, y, width, height);
   Create(obj);
}
//______________________________________________________________________________
TBrowser::~TBrowser()
{
   // Delete the browser.

   gROOT->GetListOfBrowsers()->Remove(this);
   if (fContextMenu) { delete fContextMenu; fContextMenu = 0; }
   if (fTimer) delete fTimer;
   delete fImp;
}

//______________________________________________________________________________
void TBrowser::Add(TObject *obj, const char *name)
{
   // Add object with name to browser. If name not set the objects GetName()
   // is used.

   if (obj && fImp) {
      fImp->Add(obj, name);
      obj->SetBit(kMustCleanup);
   }
}

//______________________________________________________________________________
void TBrowser::Create(TObject *obj)
{
   // Create the browser, called by the ctors.

   fNeedRefresh = kFALSE;

   fTimer = new TBrowserTimer(this);
   if (fTimer) gSystem->AddTimer(fTimer);

   gROOT->GetListOfBrowsers()->Add(this);

   // Get the list of globals
   gROOT->GetListOfGlobals(kTRUE);
   gROOT->GetListOfGlobalFunctions(kTRUE);

   fContextMenu = new TContextMenu("BrowserContextMenu") ;

   // Fill the first list from the present TObject obj
   if (obj) {
      Add(obj);
#ifndef WIN32
      if (fImp) fImp->BrowseObj(obj);
#else
 //     obj->Browse(this);
#endif
   }
   // Fill the first list with all browsable classes from TROOT
#ifndef WIN32
   else if (fImp) fImp->BrowseObj(gROOT);
#else
   // The first list will be filled by TWin32BrowserImp ctor
   // with all browsable classes from TROOT
#endif
}

//______________________________________________________________________________
void TBrowser::ExecuteDefaultAction(TObject *obj)
{
   // Execute default action for selected object (action is specified
   // in the $HOME/.root.mimes or $ROOTSYS/icons/root.mimes file.

   if (obj && fImp)
      fImp->ExecuteDefaultAction(obj);
}

//______________________________________________________________________________
TObject *TBrowser::GetSelected()
{
 // return the last selected object
 return fLastSelectedObject;
}

//______________________________________________________________________________
void TBrowser::RecursiveRemove(TObject *obj)
{
   // Recursively remove obj from browser.

   if (fImp && obj) {
      fImp->RecursiveRemove(obj);
      fNeedRefresh = kTRUE;
   }
}

//______________________________________________________________________________
void TBrowser::Refresh()
{
   // Refresh browser contents.

   fNeedRefresh = kTRUE;
   if (fImp) fImp->Refresh();
   fNeedRefresh = kFALSE;
}

//______________________________________________________________________________
void TBrowser::SetSelected(TObject *clickedObject)
{
   // Assign the last selected object

   fLastSelectedObject = clickedObject;
}

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TBrowserTimer                                                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

//______________________________________________________________________________
Bool_t TBrowserTimer::Notify()
{
   // Called whenever timer times out.

   if (fBrowser) {
      if (fBrowser->GetRefreshFlag()) {
         fBrowser->SetRefreshFlag(kFALSE);
         fActivate = kTRUE;
      } else if (fActivate) {
         fActivate = kFALSE;
         fBrowser->Refresh();
      }
   }
   Reset();

   return kFALSE;
}
<|endoftext|>


<commit_before>#include "writer/verilog/insn_writer.h"

#include "iroha/logging.h"
#include "iroha/i_design.h"
#include "iroha/resource_class.h"
#include "iroha/resource_params.h"
#include "writer/names.h"
#include "writer/verilog/state.h"
#include "writer/verilog/table.h"

static const char I[] = "          ";

namespace iroha {
namespace writer {
namespace verilog {

InsnWriter::InsnWriter(const IInsn *insn, const State *st,
		       ostream &os)
  : insn_(insn), st_(st), os_(os) {
}

string InsnWriter::RegisterValue(const IRegister &reg, Names *names) {
  if (reg.IsConst()) {
    int w = reg.value_type_.GetWidth();
    if (w == 0) {
      w = 1;
    }
    return Util::Itoa(w) + "'d" + Util::ULLtoA(reg.GetInitialValue().GetValue0());
  } else {
    return names->GetRegName(reg);
  }
}

string InsnWriter::ConstValue(const IRegister &reg) {
  CHECK(reg.IsConst());
  return Util::Itoa(reg.GetInitialValue().GetValue0());
}

string InsnWriter::CustomResourceName(const string &name,
				      const IResource &res) {
  return name + "_" + Util::Itoa(res.GetTable()->GetId()) +
    "_" + Util::Itoa(res.GetId());
}

string InsnWriter::ResourceName(const IResource &res) {
  return CustomResourceName(res.GetClass()->GetName(), res);
}

void InsnWriter::Print() {
  for (int i = 0; i < insn_->inputs_.size(); ++i) {
    IRegister *reg = insn_->inputs_[i];
    os_ << I << "$display(\"%d\", " << RegisterValue(*reg, st_->GetNames()) << ");\n";
  }
}

void InsnWriter::Assert() {
  os_ << I << "if (!(";
  for (int i = 0; i < insn_->inputs_.size(); ++i) {
    if (i > 0) {
      os_ << " && ";
    }
    IRegister *reg = insn_->inputs_[i];
    os_ << "(" << RegisterValue(*reg, st_->GetNames()) << " === 1)";
  }
  os_ << ")) begin\n";
  os_ << I << "  $display(\"ASSERTION FAILURE: "
      << st_->GetIState()->GetId() <<"\");\n";
  os_ << I << "end\n";
}

string InsnWriter::InsnOutputWireName(const IInsn &insn, int nth) {
  return "insn_o_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId()) + "_" + Util::Itoa(nth);
}

string InsnWriter::InsnConstWireName(const IInsn &insn) {
  return "insn_c_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId());
}

string InsnWriter::InsnSpecificWireName(const IInsn &insn) {
  return "insn_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId());
}

string InsnWriter::MultiCycleStateName(const IResource &res) {
  return "st_res_" + Util::Itoa(res.GetTable()->GetId())
    + "_" + Util::Itoa(res.GetId());
}

}  // namespace verilog
}  // namespace writer
}  // namespace iroha
<commit_msg>Show module path on $display()<commit_after>#include "writer/verilog/insn_writer.h"

#include "iroha/logging.h"
#include "iroha/i_design.h"
#include "iroha/resource_class.h"
#include "iroha/resource_params.h"
#include "writer/names.h"
#include "writer/verilog/state.h"
#include "writer/verilog/table.h"

static const char I[] = "          ";

namespace iroha {
namespace writer {
namespace verilog {

InsnWriter::InsnWriter(const IInsn *insn, const State *st,
		       ostream &os)
  : insn_(insn), st_(st), os_(os) {
}

string InsnWriter::RegisterValue(const IRegister &reg, Names *names) {
  if (reg.IsConst()) {
    int w = reg.value_type_.GetWidth();
    if (w == 0) {
      w = 1;
    }
    return Util::Itoa(w) + "'d" + Util::ULLtoA(reg.GetInitialValue().GetValue0());
  } else {
    return names->GetRegName(reg);
  }
}

string InsnWriter::ConstValue(const IRegister &reg) {
  CHECK(reg.IsConst());
  return Util::Itoa(reg.GetInitialValue().GetValue0());
}

string InsnWriter::CustomResourceName(const string &name,
				      const IResource &res) {
  return name + "_" + Util::Itoa(res.GetTable()->GetId()) +
    "_" + Util::Itoa(res.GetId());
}

string InsnWriter::ResourceName(const IResource &res) {
  return CustomResourceName(res.GetClass()->GetName(), res);
}

void InsnWriter::Print() {
  for (int i = 0; i < insn_->inputs_.size(); ++i) {
    IRegister *reg = insn_->inputs_[i];
    os_ << I << "$display(\"%m %d\", " << RegisterValue(*reg, st_->GetNames()) << ");\n";
  }
}

void InsnWriter::Assert() {
  os_ << I << "if (!(";
  for (int i = 0; i < insn_->inputs_.size(); ++i) {
    if (i > 0) {
      os_ << " && ";
    }
    IRegister *reg = insn_->inputs_[i];
    os_ << "(" << RegisterValue(*reg, st_->GetNames()) << " === 1)";
  }
  os_ << ")) begin\n";
  os_ << I << "  $display(\"ASSERTION FAILURE: "
      << st_->GetIState()->GetId() <<"\");\n";
  os_ << I << "end\n";
}

string InsnWriter::InsnOutputWireName(const IInsn &insn, int nth) {
  return "insn_o_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId()) + "_" + Util::Itoa(nth);
}

string InsnWriter::InsnConstWireName(const IInsn &insn) {
  return "insn_c_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId());
}

string InsnWriter::InsnSpecificWireName(const IInsn &insn) {
  return "insn_" + Util::Itoa(insn.GetResource()->GetTable()->GetId()) + "_"
    + Util::Itoa(insn.GetId());
}

string InsnWriter::MultiCycleStateName(const IResource &res) {
  return "st_res_" + Util::Itoa(res.GetTable()->GetId())
    + "_" + Util::Itoa(res.GetId());
}

}  // namespace verilog
}  // namespace writer
}  // namespace iroha
<|endoftext|>