当前位置: 首页>>代码示例>>C++>>正文


C++ DataStore::SerializeToOstream方法代码示例

本文整理汇总了C++中DataStore::SerializeToOstream方法的典型用法代码示例。如果您正苦于以下问题:C++ DataStore::SerializeToOstream方法的具体用法?C++ DataStore::SerializeToOstream怎么用?C++ DataStore::SerializeToOstream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataStore的用法示例。


在下文中一共展示了DataStore::SerializeToOstream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mexFunction


//.........这里部分代码省略.........
    /* Add a DataValue for each cell in structure field, only one member if field is numeric */
    for(j=0;j<numcells;j++){
      /* Ensure data element is double precision numeric data if requested precision is double */
      if(!mxIsDouble(matfield) && (DataGroup::DOUBLE == prec || DataGroup::COMPLEXDOUBLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore","Field '%s' does not contain a double precision numeric literal at position %d.  Type is '%s'.", fieldname, j, mxGetClassName(matfield));
      }
      
      /* Ensure data element is double or single precision if requested precision is single */
      if(!mxIsDouble(matfield) && !mxIsSingle(matfield) && (DataGroup::SINGLE == prec || DataGroup::COMPLEXSINGLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Field '%s' does not contain a floating point literal at position %d.  Type is '%s'.", fieldname, j, mxGetClassName(matfield));
      }

      /* Ensure data is not complex if only reals were specified */
      if(mxIsComplex(matfield) && (DataGroup::DOUBLE == prec || DataGroup::SINGLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Field '%s' contains a complex literal at position %d but only real values were requested.", fieldname, j);
      }
      
      /* Store the contents of the DataValue */
      ndims = mxGetNumberOfDimensions(matfield);
      dims = mxGetDimensions(matfield);
      nelems = 1;

      /* Get pointers to the Matlab data */
      if(mxIsDouble(matfield)){
	dreal = mxGetPr(matfield);
	dimag = mxGetPi(matfield);
	sreal = NULL;
	simag = NULL;
      }else if(mxIsSingle(matfield)){
	sreal = (float*)mxGetData(matfield);
	simag = (float*)mxGetImagData(matfield);
	dreal = NULL;
	dimag = NULL;
      }

      dv = dg->add_member();

      for(k=0;k<ndims;k++){
	nelems *= dims[k];
	dv->add_dims(dims[k]);
      }
      for(k=0;k<nelems;k++){
	/* Add data based on type/precision */
	switch(prec){
	case DataGroup::COMPLEXDOUBLE:
	  if(dimag){
	    dv->add_dimag(dimag[k]);
	  }else{
	    /* Value had no imaginary data, but complex type is requested */
	    dv->add_dimag(0.0);
	  }
	  /* no break, case falls through to next */
	case DataGroup::DOUBLE:
	  dv->add_dreal(dreal[k]);
	  break;

	  /* We allow downconversion from double to single so must check type of data */
	case DataGroup::COMPLEXSINGLE:
	  if(dimag){
	    dv->add_simag((float)dimag[k]);
	  }else if(simag){
	    dv->add_simag(simag[k]);
	  }else{
	    /* Value had no imaginary data, but complex type is requested */
	    dv->add_simag(0.0f);
	  }
	  /* no break, case falls through to next */
	case DataGroup::SINGLE:
	  if(dreal){
	    dv->add_sreal((float)dreal[k]);
	  }else{
	    dv->add_sreal(sreal[k]);
	  }
	  break;
	}
      }

      /* If structure field is a cell array, advance to next cell */
      if(numcells > 1){
	matfield = mxGetCell(matcell, j+1);
      }
    }
  }

  /* Open the file */
  filename = mxArrayToString(prhs[0]);
  output.open(filename, ios::out | ios::binary | ios::trunc);
  if(output.fail()){
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Unable to open file '%s'.", filename);
  }
  mxFree(filename);

  /* Write entire DataStore to file */
  if(!ds.SerializeToOstream(&output)){
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Unable to serialize data to file '%s'.", filename);
  }

  output.close();
  google::protobuf::ShutdownProtobufLibrary();
}
开发者ID:joshuaecook,项目名称:simengine,代码行数:101,代码来源:mexDataStore.cpp


注:本文中的DataStore::SerializeToOstream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。