// file: st_cstr_3.cc
//

// isip include files
//
#include "state.h"
#include "state_constants.h"
 
// method: constructor
//
// arguments:
//  const State& state: (input) copy state
//
// return: none
//
// this is the copy constructor for the class
//
State::State(const State& state_a) {
  
  // set the number of mixtures
  //
  num_mixtures_d = state_a.num_mixtures_d;

  // copy parameters only if gaussians exist
  //
  if (num_mixtures_d != 0) {

    // allocate memory for mixture weights and copy data
    //
    weights_d = new float_4[num_mixtures_d];
    memcpy(weights_d, state_a.weights_d, num_mixtures_d * sizeof(float_4));
    
    // allocate memory for scale factors and copy data
    //
    scale_d = new float_4[num_mixtures_d];
    memcpy(scale_d, state_a.scale_d, num_mixtures_d * sizeof(float_4));
    
    // allocate memory for mean vectors and copy data
    //
    mean_d = new float_4*[num_mixtures_d];
    for (int_4 i = 0; i < num_mixtures_d; i++) {
      mean_d[i] = new float_4[num_features_d];
      memcpy(mean_d[i], state_a.mean_d[i], num_features_d * sizeof(float_4));
    }
    
    // allocate memory for covar matrices and copy data
    //
    covar_d = new float_4*[num_mixtures_d];
    for (int_4 i = 0; i < num_mixtures_d; i++) {
      covar_d[i] = new float_4[num_features_d];
      memcpy(covar_d[i], state_a.covar_d[i], num_features_d * sizeof(float_4));
    }
    
    // initialize the frame and score
    //
    frame_d = state_a.frame_d;
    score_d = state_a.score_d;
  }

  else {
    weights_d = (float_4*)NULL;
    scale_d = (float_4*)NULL;
    mean_d = (float_4**)NULL;
    covar_d = (float_4**)NULL;
    frame_d = (int_4)-1;
    score_d = STATE_SCORE;
  }

  // exit gracefully
  //
}
