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


C++ ostream::write方法代码示例

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


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

示例1: sizeof

void sosicon::shape::Shapefile::
writeDbf( std::ostream &os ) {
    os.write( mDbfHeader, sizeof( mDbfHeader ) );
    os.write( mDbfBuffer, mDbfBufferSize );
}
开发者ID:espena,项目名称:sosicon,代码行数:5,代码来源:shapefile.cpp

示例2: sizeof

void tap::CodeHeader::write (std::ostream & out) const
{
	out.write (reinterpret_cast <const char *> (block), sizeof (block) );
}
开发者ID:JamesGlanville,项目名称:Z80,代码行数:4,代码来源:tap.cpp

示例3: Save

bool CLink::Save(std::ostream& so) {
	so.write((char*)&m_nPos, 4);
	so.write((char*)&m_nSize, 4);

	return true;
};
开发者ID:DesmonD97,项目名称:lab5,代码行数:6,代码来源:CLink.cpp

示例4: save

void BlockchainSynchronizer::save(std::ostream& os) {
  os.write(reinterpret_cast<const char*>(&m_genesisBlockHash), sizeof(m_genesisBlockHash));
}
开发者ID:iamsmooth,项目名称:bitcedi,代码行数:3,代码来源:BlockchainSynchronizer.cpp

示例5: writeBytesRLE

/* encoded separately for better compression. */
bool HDRWriter::writeBytesRLE(std::ostream &fout, unsigned char *data, int numbytes)
{
#define MINRUNLENGTH 4
    int           cur, beg_run, run_count, old_run_count, nonrun_count;
    unsigned char buf[2];

    cur = 0;

    while (cur < numbytes)
    {
        beg_run = cur;
        /* find next run of length at least 4 if one exists */
        run_count = old_run_count = 0;

        while ((run_count < MINRUNLENGTH) && (beg_run < numbytes))
        {
            beg_run      += run_count;
            old_run_count = run_count;
            run_count     = 1;

            while ((data[beg_run] == data[beg_run + run_count])
                   && (beg_run + run_count < numbytes)
                   && (run_count < 127))
            {
                run_count++;
            }
        }

        /* if data before next big run is a short run then write it as such */
        if ((old_run_count > 1) && (old_run_count == beg_run - cur))
        {
            buf[0] = 128 + old_run_count;   /*write short run*/
            buf[1] = data[cur];
            fout.write(reinterpret_cast<const char*>(buf), sizeof(buf[0]) * 2);
            // if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1) return false
            cur = beg_run;
        }

        /* write out bytes until we reach the start of the next run */
        while (cur < beg_run)
        {
            nonrun_count = beg_run - cur;
            if (nonrun_count > 128)
                nonrun_count = 128;

            buf[0] = nonrun_count;
            fout.write(reinterpret_cast<const char*>(buf), sizeof(buf[0]));
            // if (fwrite(buf,sizeof(buf[0]),1,fp) < 1) return false
            fout.write(reinterpret_cast<const char*>(&data[cur]), sizeof(data[0]) * nonrun_count);
            // if (fwrite(&data[cur],sizeof(data[0])*nonrun_count,1,fp) < 1) return false;
            cur += nonrun_count;
        }

        /* write out next run if one was found */
        if (run_count >= MINRUNLENGTH)
        {
            buf[0] = 128 + run_count;
            buf[1] = data[beg_run];
            fout.write(reinterpret_cast<const char*>(buf), sizeof(buf[0]) * 2);
            // if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1) return false;
            cur += run_count;
        }
    }

    return true;
#undef MINRUNLENGTH
}
开发者ID:hyyh619,项目名称:OpenSceneGraph-3.4.0,代码行数:68,代码来源:hdrwriter.cpp

示例6: save

 void matrix::save(std::ostream &out) {
     out.write((char*) &m_, sizeof(uint32_t));
     out.write((char*) &n_, sizeof(uint32_t));
     out.write((char*) data_, m_ * n_ * sizeof(real));
 }
开发者ID:Sanqiang,项目名称:entity2vector,代码行数:5,代码来源:matrix.cpp

示例7: write_header

 bool request::write_header(std::ostream &os) {
     // Some validation
     if (method==http_method::INVALID_METHOD) return false;
     if (url.empty()) return false;
     if (version==http_version::INVALID_VERSION) return false;
     
     // METHOD " " URL " " HTTP_VER "\r\n"
     auto m=detail::method_name_map.find(method);
     if (m==detail::method_name_map.end()) return false;
     os.write(&(m->second[0]), m->second.size());
     os.write(" ", 1);
     os.write(&(url[0]), url.size());
     os.write(" ", 1);
     auto v=detail::http_version_name_map.find(version);
     if (v==detail::http_version_name_map.end()) return false;
     os.write(&(v->second[0]), v->second.size());
     os.write("\r\n", 2);
     
     // Write headers
     for (auto &p: headers) {
         os.write(&(p.first[0]), p.first.size());
         os.write(": ", 2);
         os.write(&(p.second[0]), p.second.size());
         os.write("\r\n", 2);
     }
     // End of header
     os.write("\r\n", 2);
     return true;
 }
开发者ID:sharpglasses,项目名称:fibio,代码行数:29,代码来源:common.cpp

示例8:


//.........这里部分代码省略.........
#endif
		ostr << "<array><data>";
		LLSD::array_const_iterator it = sd.beginArray();
		LLSD::array_const_iterator end = sd.endArray();
		for(; it != end; ++it)
		{
			streamOut(ostr, *it);
			if(ostr.fail())
			{
				LL_INFOS() << "STREAM FAILURE writing array element sd type "
						<< (*it).type() << LL_ENDL;
			}
		}
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(array) END" << LL_ENDL;
#endif
		ostr << "</data></array>";
		break;
	}
	case LLSD::TypeUndefined:
		// treat undefined as a bool with a false value.
	case LLSD::TypeBoolean:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(bool)" << LL_ENDL;
#endif
		ostr << "<boolean>" << (sd.asBoolean() ? "1" : "0") << "</boolean>";
		break;
	case LLSD::TypeInteger:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(int)" << LL_ENDL;
#endif
		ostr << "<i4>" << sd.asInteger() << "</i4>";
		break;
	case LLSD::TypeReal:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(real)" << LL_ENDL;
#endif
		ostr << "<double>" << sd.asReal() << "</double>";
		break;
	case LLSD::TypeString:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(string)" << LL_ENDL;
#endif
		ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
		break;
	case LLSD::TypeUUID:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(uuid)" << LL_ENDL;
#endif
		// serialize it as a string
		ostr << "<string>" << sd.asString() << "</string>";
		break;
	case LLSD::TypeURI:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(uri)" << LL_ENDL;
#endif
		// serialize it as a string
		ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
		break;
	}
	case LLSD::TypeBinary:
	{
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(binary)" << LL_ENDL;
#endif
		// this is pretty inefficient, but we'll deal with that
		// problem when it becomes one.
		ostr << "<base64>";
		LLSD::Binary buffer = sd.asBinary();
		if(!buffer.empty())
		{
			// *TODO: convert to LLBase64
			int b64_buffer_length = apr_base64_encode_len(buffer.size());
			char* b64_buffer = new char[b64_buffer_length];
			b64_buffer_length = apr_base64_encode_binary(
				b64_buffer,
				&buffer[0],
				buffer.size());
			ostr.write(b64_buffer, b64_buffer_length - 1);
			delete[] b64_buffer;
		}
		ostr << "</base64>";
		break;
	}
	case LLSD::TypeDate:
#if LL_SPEW_STREAM_OUT_DEBUGGING
		LL_INFOS() << "streamOut(date)" << LL_ENDL;
#endif
		// no need to escape this since it will be alpha-numeric.
		ostr << "<dateTime.iso8601>" << sd.asString() << "</dateTime.iso8601>";
		break;
	default:
		// unhandled type
		LL_WARNS() << "Unhandled structured data type: " << sd.type()
			<< LL_ENDL;
		break;
	}
	ostr << "</value>";
}
开发者ID:DamianZhaoying,项目名称:SingularityViewer,代码行数:101,代码来源:llfiltersd2xmlrpc.cpp

示例9: format_impl


//.........这里部分代码省略.........
			if(need_comma) ostr << ",";
			need_comma = true;
			format_count += format_impl(*iter, ostr, options, level + 1);
		}
		ostr << "]";
		break;
	}

	case LLSD::TypeUndefined:
		ostr << "!";
		break;

	case LLSD::TypeBoolean:
		if(mBoolAlpha ||
#if( LL_WINDOWS || __GNUC__ > 2)
		   (ostr.flags() & std::ios::boolalpha)
#else
		   (ostr.flags() & 0x0100)
#endif
			)
		{
			ostr << (data.asBoolean()
					 ? NOTATION_TRUE_SERIAL : NOTATION_FALSE_SERIAL);
		}
		else
		{
			ostr << (data.asBoolean() ? 1 : 0);
		}
		break;

	case LLSD::TypeInteger:
		ostr << "i" << data.asInteger();
		break;

	case LLSD::TypeReal:
		ostr << "r";
		if(mRealFormat.empty())
		{
			ostr << data.asReal();
		}
		else
		{
			formatReal(data.asReal(), ostr);
		}
		break;

	case LLSD::TypeUUID:
		ostr << "u" << data.asUUID();
		break;

	case LLSD::TypeString:
		ostr << '\'';
		serialize_string(data.asStringRef(), ostr);
		ostr << '\'';
		break;

	case LLSD::TypeDate:
		ostr << "d\"" << data.asDate() << "\"";
		break;

	case LLSD::TypeURI:
		ostr << "l\"";
		serialize_string(data.asString(), ostr);
		ostr << "\"";
		break;

	case LLSD::TypeBinary:
	{
		// *FIX: memory inefficient.
		const std::vector<U8>& buffer = data.asBinary();
		ostr << "b(" << buffer.size() << ")\"";
		if(buffer.size())
		{
			if (options & LLSDFormatter::OPTIONS_PRETTY_BINARY)
			{
				std::ios_base::fmtflags old_flags = ostr.flags();
				ostr.setf( std::ios::hex, std::ios::basefield );
				ostr << "0x";
				for (size_t i = 0; i < buffer.size(); i++)
				{
					ostr << (int) buffer[i];
				}
				ostr.flags(old_flags);
			}
			else
			{
				ostr.write((const char*)&buffer[0], buffer.size());
			}
		}
		ostr << "\"";
		break;
	}

	default:
		// *NOTE: This should never happen.
		ostr << "!";
		break;
	}
	return format_count;
}
开发者ID:AlericInglewood,项目名称:SingularityViewer,代码行数:101,代码来源:llsdserialize.cpp

示例10: format

// virtual
S32 LLSDBinaryFormatter::format(const LLSD& data, std::ostream& ostr, U32 options) const
{
	S32 format_count = 1;
	switch(data.type())
	{
	case LLSD::TypeMap:
	{
		ostr.put('{');
		U32 size_nbo = htonl(data.size());
		ostr.write((const char*)(&size_nbo), sizeof(U32));
		LLSD::map_const_iterator iter = data.beginMap();
		LLSD::map_const_iterator end = data.endMap();
		for(; iter != end; ++iter)
		{
			ostr.put('k');
			formatString((*iter).first, ostr);
			format_count += format((*iter).second, ostr);
		}
		ostr.put('}');
		break;
	}

	case LLSD::TypeArray:
	{
		ostr.put('[');
		U32 size_nbo = htonl(data.size());
		ostr.write((const char*)(&size_nbo), sizeof(U32));
		LLSD::array_const_iterator iter = data.beginArray();
		LLSD::array_const_iterator end = data.endArray();
		for(; iter != end; ++iter)
		{
			format_count += format(*iter, ostr);
		}
		ostr.put(']');
		break;
	}

	case LLSD::TypeUndefined:
		ostr.put('!');
		break;

	case LLSD::TypeBoolean:
		if(data.asBoolean()) ostr.put(BINARY_TRUE_SERIAL);
		else ostr.put(BINARY_FALSE_SERIAL);
		break;

	case LLSD::TypeInteger:
	{
		ostr.put('i');
		U32 value_nbo = htonl(data.asInteger());
		ostr.write((const char*)(&value_nbo), sizeof(U32));
		break;
	}

	case LLSD::TypeReal:
	{
		ostr.put('r');
		F64 value_nbo = ll_htond(data.asReal());
		ostr.write((const char*)(&value_nbo), sizeof(F64));
		break;
	}

	case LLSD::TypeUUID:
	{
		ostr.put('u');
		LLUUID temp = data.asUUID();
		ostr.write((const char*)(&(temp.mData)), UUID_BYTES);
		break;
	}

	case LLSD::TypeString:
		ostr.put('s');
		formatString(data.asStringRef(), ostr);
		break;

	case LLSD::TypeDate:
	{
		ostr.put('d');
		F64 value = data.asReal();
		ostr.write((const char*)(&value), sizeof(F64));
		break;
	}

	case LLSD::TypeURI:
		ostr.put('l');
		formatString(data.asString(), ostr);
		break;

	case LLSD::TypeBinary:
	{
		ostr.put('b');
		const std::vector<U8>& buffer = data.asBinary();
		U32 size_nbo = htonl(buffer.size());
		ostr.write((const char*)(&size_nbo), sizeof(U32));
		if(buffer.size()) ostr.write((const char*)&buffer[0], buffer.size());
		break;
	}

	default:
//.........这里部分代码省略.........
开发者ID:AlericInglewood,项目名称:SingularityViewer,代码行数:101,代码来源:llsdserialize.cpp

示例11: memset

  unsigned long
  StaticRangeCoder::encodeCharVectorToStream (const std::vector<char>& inputByteVector_arg,
                                              std::ostream& outputByteStream_arg)
  {
    DWord freq[257];
    uint8_t ch;
    int i, f;
    char out;

    // define numerical limits
    const DWord top = (DWord)1 << 24;
    const DWord bottom = (DWord)1 << 16;
    const DWord maxRange = (DWord)1 << 16;

    DWord low, range;

    unsigned int input_size;
    input_size = inputByteVector_arg.size ();

    unsigned int readPos;

    unsigned long streamByteCount;

    streamByteCount = 0;

    // init output vector
    outputCharVector_.clear();
    outputCharVector_.reserve(sizeof(char) * input_size);

    uint64_t FreqHist[257];

    // calculate frequency table
    memset (FreqHist, 0, sizeof(FreqHist));
    readPos = 0;
    while (readPos < input_size)
    {
      uint8_t symbol = (uint8_t)inputByteVector_arg[readPos++];
      FreqHist[symbol + 1]++;
    }

    // convert to cumulative frequency table
    freq[0] = 0;
    for (f = 1; f <= 256; f++)
    {
      freq[f] = freq[f - 1] + (DWord)FreqHist[f];
      if (freq[f] <= freq[f - 1])
        freq[f] = freq[f - 1] + 1;
    }

    // rescale if numerical limits are reached
    while (freq[256] >= maxRange)
    {
      for (f = 1; f <= 256; f++)
      {
        freq[f] /= 2;
        ;
        if (freq[f] <= freq[f - 1])
          freq[f] = freq[f - 1] + 1;
      }
    }

    // write cumulative  frequency table to output stream
    outputByteStream_arg.write ((const char *)&freq[0], sizeof(freq));
    streamByteCount += sizeof(freq);

    readPos = 0;

    low = 0;
    range = (DWord)-1;

    // start encoding
    while (readPos < input_size)
    {

      // read symol
      ch = inputByteVector_arg[readPos++];

      // map to range
      low += freq[ch] * (range /= freq[256]);
      range *= freq[ch + 1] - freq[ch];

      // check range limits
      while ((low ^ (low + range)) < top || ((range < bottom) && ((range = -low & (bottom - 1)), 1)))
      {
        out = low >> 24;
        range <<= 8;
        low <<= 8;
        outputCharVector_.push_back(out);
      }

    }

    // flush remaining data
    for (i = 0; i < 4; i++)
    {
      out = low >> 24;
      outputCharVector_.push_back(out);
      low <<= 8;
    }

//.........这里部分代码省略.........
开发者ID:MorS25,项目名称:pcl-fuerte,代码行数:101,代码来源:entropy_range_coder.hpp

示例12: while

  unsigned long
  StaticRangeCoder::encodeIntVectorToStream (std::vector<unsigned int>& inputIntVector_arg,
                                             std::ostream& outputByteStream_arg)
  {

    unsigned int inputsymbol;
    unsigned int i, f;
    char out;

    uint64_t frequencyTableSize;
    uint8_t frequencyTableByteSize;

    // define numerical limits
    const uint64_t top = (uint64_t)1 << 56;
    const uint64_t bottom = (uint64_t)1 << 48;
    const uint64_t maxRange = (uint64_t)1 << 48;

    unsigned long input_size = (unsigned) inputIntVector_arg.size ();
    uint64_t low, range;

    unsigned int inputSymbol;

    unsigned int readPos;

    unsigned long streamByteCount;

    streamByteCount = 0;

    // init output vector
    outputCharVector_.clear();
    outputCharVector_.reserve(sizeof(char) * input_size * 2);

    frequencyTableSize = 1;

    readPos = 0;

    // calculate frequency table
    cFreqTable_[0] = cFreqTable_[1] = 0;
    while (readPos < input_size)
    {
      inputSymbol = inputIntVector_arg[readPos++];

      if (inputSymbol + 1 >= frequencyTableSize)
      {
        // frequency table is to small -> adaptively extend it
        uint64_t oldfrequencyTableSize;
        oldfrequencyTableSize = frequencyTableSize;

        do
        {
          // increase frequency table size by factor 2
          frequencyTableSize <<= 1;
        } while (inputSymbol + 1 > frequencyTableSize);

        if (cFreqTable_.size () < frequencyTableSize + 1)
        {
          // resize frequency vector
          cFreqTable_.resize (frequencyTableSize + 1);
        }

        // init new frequency range with zero
        memset (&cFreqTable_[oldfrequencyTableSize + 1], 0,
                sizeof(uint64_t) * (frequencyTableSize - oldfrequencyTableSize));
      }
      cFreqTable_[inputSymbol + 1]++;
    }
    frequencyTableSize++;

    // convert to cumulative frequency table
    for (f = 1; f < frequencyTableSize; f++)
    {
      cFreqTable_[f] = cFreqTable_[f - 1] + cFreqTable_[f];
      if (cFreqTable_[f] <= cFreqTable_[f - 1])
        cFreqTable_[f] = cFreqTable_[f - 1] + 1;
    }

    // rescale if numerical limits are reached
    while (cFreqTable_[frequencyTableSize - 1] >= maxRange)
    {
      for (f = 1; f < cFreqTable_.size (); f++)
      {
        cFreqTable_[f] /= 2;
        ;
        if (cFreqTable_[f] <= cFreqTable_[f - 1])
          cFreqTable_[f] = cFreqTable_[f - 1] + 1;
      }
    }

    // calculate amount of bytes per frequency table entry
    frequencyTableByteSize = (uint8_t)ceil (Log2 ((double) cFreqTable_[frequencyTableSize - 1]) / 8.0);

    // write size of frequency table to output stream
    outputByteStream_arg.write ((const char *)&frequencyTableSize, sizeof(frequencyTableSize));
    outputByteStream_arg.write ((const char *)&frequencyTableByteSize, sizeof(frequencyTableByteSize));

    streamByteCount += sizeof(frequencyTableSize)+sizeof(frequencyTableByteSize);

    // write cumulative  frequency table to output stream
    for (f = 1; f < frequencyTableSize; f++)
    {
//.........这里部分代码省略.........
开发者ID:MorS25,项目名称:pcl-fuerte,代码行数:101,代码来源:entropy_range_coder.hpp

示例13: inflate

/* Decompress from file source to file dest until stream ends or EOF.
   inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
   allocated for processing, Z_DATA_ERROR if the deflate data is
   invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
   the version of the library linked do not match, or Z_ERRNO if there
   is an error reading or writing the files. */
bool Misc::inflate(const uint8_t* in, size_t inlen, std::ostream& dest, string& err, int CHUNK)
{
  int ret;
  unsigned have;
  z_stream strm;
  if ( CHUNK == -1 ) CHUNK = CL_Z_DEFAULT_CHUNK;
  uint8_t* out = (uint8_t*)malloc(CHUNK);

  /* allocate inflate state */
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = 0;
  strm.next_in = Z_NULL;
  ret = inflateInit(&strm);
  if (ret != Z_OK){
    free(out);
    zerr(ret, err);
    return false;
  }

  /* decompress until deflate stream ends or end of file */
  do {
    strm.avail_in = inlen;
    if (strm.avail_in == 0)
      break;
    strm.next_in = (uint8_t*)in;

    /* run inflate() on input until output buffer not full */
    do {
      strm.avail_out = CHUNK;
      strm.next_out = out;
      ret = ::inflate(&strm, Z_NO_FLUSH);
      assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
      switch (ret) {
      case Z_NEED_DICT:
        ret = Z_DATA_ERROR;   /* and fall through */
      case Z_DATA_ERROR:
      case Z_MEM_ERROR:
        (void)inflateEnd(&strm);
        free(out);
        zerr(ret, err);
        return false;
      }
      have = CHUNK - strm.avail_out;
      dest.write( (char*)out,have);
      if ( dest.fail() ) {
        (void)inflateEnd(&strm);
        free(out);
        zerr(Z_ERRNO, err);
        return false;
      }
    } while (strm.avail_out == 0);

    /* done when inflate() says it's done */
  } while (ret != Z_STREAM_END);

  /* clean up and return */
  (void)inflateEnd(&strm);
  free(out);
  if ( ret == Z_STREAM_END )
    return true;
  zerr(Z_DATA_ERROR, err);
  return false;
}
开发者ID:AlanForeverAi,项目名称:WizQTClient,代码行数:71,代码来源:Misc.cpp

示例14: if

void MapBlock::serialize_pre22(std::ostream &os, u8 version, bool disk)
{
	u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;

	MapNode *tmp_data = new MapNode[nodecount];
	
	// Legacy data changes
	// This code has to change from post-22 to pre-22 format.
	INodeDefManager *nodedef = m_gamedef->ndef();
	for(u32 i=0; i<nodecount; i++)
	{
		const ContentFeatures &f = nodedef->get(tmp_data[i].getContent());
		// Mineral
		if(nodedef->getId("default:stone_with_coal") == tmp_data[i].getContent())
		{
			tmp_data[i].setContent(nodedef->getId("default:stone"));
			tmp_data[i].setParam1(1);  // MINERAL_COAL
		}
		else if(nodedef->getId("default:stone_with_iron") == tmp_data[i].getContent())
		{
			tmp_data[i].setContent(nodedef->getId("default:stone"));
			tmp_data[i].setParam1(2);  // MINERAL_IRON
		}
		// facedir_simple
		if(f.legacy_facedir_simple)
		{
			tmp_data[i].setParam1(tmp_data[i].getParam2());
			tmp_data[i].setParam2(0);
		}
		// wall_mounted
		if(f.legacy_wallmounted)
		{
			u8 wallmounted_new_to_old[8] = {0x04, 0x08, 0x01, 0x02, 0x10, 0x20, 0, 0};
			u8 dir_new_format = tmp_data[i].getParam2() & 7; // lowest 3 bits
			u8 dir_old_format = wallmounted_new_to_old[dir_new_format];
			tmp_data[i].setParam2(dir_old_format);
		}
	}

	// Serialize nodes
	u32 ser_length = MapNode::serializedLength(version);
	SharedBuffer<u8> databuf_nodelist(nodecount * ser_length);
	for(u32 i=0; i<nodecount; i++)
	{
		tmp_data[i].serialize(&databuf_nodelist[i*ser_length], version);
	}

	delete[] tmp_data;
		
	// These have no compression
	if(version <= 3 || version == 5 || version == 6)
	{
		writeU8(os, is_underground);
		os.write((char*)*databuf_nodelist, databuf_nodelist.getSize());
	}
	else if(version <= 10)
	{
		/*
			With compression.
			Compress the materials and the params separately.
		*/
		
		// First byte
		writeU8(os, is_underground);

		// Get and compress materials
		SharedBuffer<u8> materialdata(nodecount);
		for(u32 i=0; i<nodecount; i++)
		{
			materialdata[i] = databuf_nodelist[i*ser_length];
		}
		compress(materialdata, os, version);

		// Get and compress lights
		SharedBuffer<u8> lightdata(nodecount);
		for(u32 i=0; i<nodecount; i++)
		{
			lightdata[i] = databuf_nodelist[i*ser_length+1];
		}
		compress(lightdata, os, version);
		
		if(version >= 10)
		{
			// Get and compress param2
			SharedBuffer<u8> param2data(nodecount);
			for(u32 i=0; i<nodecount; i++)
			{
				param2data[i] = databuf_nodelist[i*ser_length+2];
			}
			compress(param2data, os, version);
		}
	}
	// All other versions (newest)
	else
	{
		// First byte
		u8 flags = 0;
		if(is_underground)
			flags |= 0x01;
		if(getDayNightDiff())
//.........这里部分代码省略.........
开发者ID:Anchakor,项目名称:minetest,代码行数:101,代码来源:mapblock.cpp

示例15: EncodeTargetPhrasePREnc

void PhraseTableCreator::EncodeTargetPhrasePREnc(std::vector<std::string>& s,
    std::vector<std::string>& t,
    std::set<AlignPoint>& a,
    size_t ownRank,
    std::ostream& os)
{
  std::vector<unsigned> encodedSymbols(t.size());
  std::vector<unsigned> encodedSymbolsLengths(t.size(), 0);

  ConsistentPhrases cp(s.size(), t.size(), a);
  while(!cp.Empty()) {
    ConsistentPhrases::Phrase p = cp.Pop();

    std::stringstream key1;
    key1 << s[p.i];
    for(int i = p.i+1; i < p.i+p.m; i++)
      key1 << " " << s[i];

    std::stringstream key2;
    key2 << t[p.j];
    for(int i = p.j+1; i < p.j+p.n; i++)
      key2 << " " << t[i];

    int rank = -1;
    std::string key1Str = key1.str(), key2Str = key2.str();
    size_t idx = m_rnkHash[MakeSourceTargetKey(key1Str, key2Str)];
    if(idx != m_rnkHash.GetSize())
      rank = m_ranks[idx];

    if(rank >= 0 && (m_maxRank == 0 || unsigned(rank) < m_maxRank)) {
      if(unsigned(p.m) != s.size() || unsigned(rank) < ownRank) {
        std::stringstream encodedSymbol;
        encodedSymbols[p.j] = EncodePREncSymbol2(p.i-p.j, s.size()-(p.i+p.m), rank);
        encodedSymbolsLengths[p.j] = p.n;

        std::set<AlignPoint> tAlignment;
        for(std::set<AlignPoint>::iterator it = a.begin();
            it != a.end(); it++)
          if(it->first < p.i || it->first >= p.i + p.m
              || it->second < p.j || it->second >= p.j + p.n)
            tAlignment.insert(*it);
        a = tAlignment;
        cp.RemoveOverlap(p);
      }
    }
  }

  std::stringstream encodedTargetPhrase;

  size_t j = 0;
  while(j < t.size()) {
    if(encodedSymbolsLengths[j] > 0) {
      unsigned encodedSymbol = encodedSymbols[j];
      m_symbolCounter.Increase(encodedSymbol);
      os.write((char*)&encodedSymbol, sizeof(encodedSymbol));
      j += encodedSymbolsLengths[j];
    } else {
      unsigned targetSymbolId = GetOrAddTargetSymbolId(t[j]);
      unsigned encodedSymbol = EncodePREncSymbol1(targetSymbolId);
      m_symbolCounter.Increase(encodedSymbol);
      os.write((char*)&encodedSymbol, sizeof(encodedSymbol));
      j++;
    }
  }

  unsigned stopSymbolId = GetTargetSymbolId(m_phraseStopSymbol);
  unsigned encodedSymbol = EncodePREncSymbol1(stopSymbolId);
  os.write((char*)&encodedSymbol, sizeof(encodedSymbol));
  m_symbolCounter.Increase(encodedSymbol);
}
开发者ID:dynotes,项目名称:mosesdecoder,代码行数:70,代码来源:PhraseTableCreator.cpp


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