• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ encode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中encode函数的典型用法代码示例。如果您正苦于以下问题:C++ encode函数的具体用法?C++ encode怎么用?C++ encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: encodeFilter

//---------------------------------------------------------------------------
static bool encodeFilter(DictionarySegment& dict,DifferentialIndex* diffIndex,const SPARQLParser::PatternGroup& group,const SPARQLParser::Filter& input,QueryGraph::Filter& output)
   // Encode an element for the query graph
{
   switch (input.type) {
      case SPARQLParser::Filter::Or: return encodeBinaryFilter(QueryGraph::Filter::Or,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::And: return encodeBinaryFilter(QueryGraph::Filter::And,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Equal: return encodeBinaryFilter(QueryGraph::Filter::Equal,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::NotEqual: return encodeBinaryFilter(QueryGraph::Filter::NotEqual,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Less: return encodeBinaryFilter(QueryGraph::Filter::Less,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::LessOrEqual: return encodeBinaryFilter(QueryGraph::Filter::LessOrEqual,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Greater: return encodeBinaryFilter(QueryGraph::Filter::Greater,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::GreaterOrEqual: return encodeBinaryFilter(QueryGraph::Filter::GreaterOrEqual,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Plus: return encodeBinaryFilter(QueryGraph::Filter::Plus,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Minus: return encodeBinaryFilter(QueryGraph::Filter::Minus,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Mul: return encodeBinaryFilter(QueryGraph::Filter::Mul,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Div: return encodeBinaryFilter(QueryGraph::Filter::Div,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Not: return encodeUnaryFilter(QueryGraph::Filter::Not,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::UnaryPlus: return encodeUnaryFilter(QueryGraph::Filter::UnaryPlus,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::UnaryMinus: return encodeUnaryFilter(QueryGraph::Filter::UnaryMinus,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Literal: {
         SPARQLParser::Element e;
         e.type=SPARQLParser::Element::Literal;
         e.subType=static_cast<SPARQLParser::Element::SubType>(input.valueArg);
         e.subTypeValue=input.valueType;
         e.value=input.value;
         unsigned id; bool constant;
         if (encode(dict,diffIndex,e,id,constant)) {
            output.type=QueryGraph::Filter::Literal;
            output.id=id;
            output.value=input.value;
         } else {
            output.type=QueryGraph::Filter::Literal;
            output.id=~0u;
            output.value=input.value;
         }
         } return true;
      case SPARQLParser::Filter::Variable:
         if (binds(group,input.valueArg)) {
            output.type=QueryGraph::Filter::Variable;
            output.id=input.valueArg;
         } else {
            output.type=QueryGraph::Filter::Null;
         }
         return true;
      case SPARQLParser::Filter::IRI: {
         SPARQLParser::Element e;
         e.type=SPARQLParser::Element::IRI;
         e.subType=static_cast<SPARQLParser::Element::SubType>(input.valueArg);
         e.subTypeValue=input.valueType;
         e.value=input.value;
         unsigned id; bool constant;
         if (encode(dict,diffIndex,e,id,constant)) {
            output.type=QueryGraph::Filter::IRI;
            output.id=id;
            output.value=input.value;
         } else {
            output.type=QueryGraph::Filter::IRI;
            output.id=~0u;
            output.value=input.value;
         }
         } return true;
      case SPARQLParser::Filter::Function:
         if (input.arg1->value==tableFunctionId)
            throw SemanticAnalysis::SemanticException(std::string("<")+tableFunctionId+"> calls must be placed in seperate filter clauses");
         return encodeBinaryFilter(QueryGraph::Filter::Function,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::ArgumentList: return encodeBinaryFilter(QueryGraph::Filter::ArgumentList,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_str: return encodeUnaryFilter(QueryGraph::Filter::Builtin_str,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_lang: return encodeUnaryFilter(QueryGraph::Filter::Builtin_lang,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_langmatches: return encodeBinaryFilter(QueryGraph::Filter::Builtin_langmatches,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_datatype: return encodeUnaryFilter(QueryGraph::Filter::Builtin_datatype,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_bound: return encodeUnaryFilter(QueryGraph::Filter::Builtin_bound,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_sameterm: return encodeBinaryFilter(QueryGraph::Filter::Builtin_sameterm,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_isiri: return encodeUnaryFilter(QueryGraph::Filter::Builtin_isiri,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_isblank: return encodeUnaryFilter(QueryGraph::Filter::Builtin_isblank,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_isliteral: return encodeUnaryFilter(QueryGraph::Filter::Builtin_isliteral,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_regex: return encodeTernaryFilter(QueryGraph::Filter::Builtin_regex,dict,diffIndex,group,input,output);
      case SPARQLParser::Filter::Builtin_in: return encodeBinaryFilter(QueryGraph::Filter::Builtin_in,dict,diffIndex,group,input,output);
   }
   return false; // XXX cannot happen
}
开发者ID:gdesimone,项目名称:toMonet,代码行数:81,代码来源:SemanticAnalysis.cpp


示例2: encode

Vector<char> IndexMetaDataKey::encodeMaxKey(int64_t databaseId, int64_t objectStoreId)
{
    return encode(databaseId, objectStoreId, INT64_MAX, 255);
}
开发者ID:CannedFish,项目名称:deepin-webkit,代码行数:4,代码来源:IDBLevelDBCoding.cpp


示例3: encode

std::string
MidiDevice::toXmlString() const
{
    std::stringstream midiDevice;

    midiDevice << "    <device id=\""  << m_id 
               << "\" name=\""         << m_name 
               << "\" direction=\""    << (m_direction == Play ?
                                           "play" : "record")
               << "\" variation=\""    << (m_variationType == VariationFromLSB ?
                                           "LSB" :
                                           m_variationType == VariationFromMSB ?
                                           "MSB" : "")
               << "\" connection=\""   << encode(m_connection)
               << "\" type=\"midi\">"  << std::endl << std::endl;

    midiDevice << "        <librarian name=\"" << encode(m_librarian.first)
               << "\" email=\"" << encode(m_librarian.second)
               << "\"/>" << std::endl;

    if (m_metronome)
    {
        // Write out the metronome - watch the MidiBytes
        // when using the stringstream
        //
        midiDevice << "        <metronome "
                   << "instrument=\"" << m_metronome->getInstrument() << "\" "
                   << "barpitch=\"" << (int)m_metronome->getBarPitch() << "\" "
                   << "beatpitch=\"" << (int)m_metronome->getBeatPitch() << "\" "
                   << "subbeatpitch=\"" << (int)m_metronome->getSubBeatPitch() << "\" "
                   << "depth=\"" << (int)m_metronome->getDepth() << "\" "
                   << "barvelocity=\"" << (int)m_metronome->getBarVelocity() << "\" "
                   << "beatvelocity=\"" << (int)m_metronome->getBeatVelocity() << "\" "
                   << "subbeatvelocity=\"" << (int)m_metronome->getSubBeatVelocity() 
                   << "\"/>"
                   << std::endl << std::endl;
    }

    // and now bank information
    //
    BankList::const_iterator it;
    InstrumentList::const_iterator iit;
    ProgramList::const_iterator pt;

    for (it = m_bankList.begin(); it != m_bankList.end(); ++it)
    {
        midiDevice << "        <bank "
                   << "name=\"" << encode(it->getName()) << "\" "
                   << "percussion=\"" << (it->isPercussion() ? "true" : "false") << "\" "
                   << "msb=\"" << (int)it->getMSB() << "\" "
                   << "lsb=\"" << (int)it->getLSB() << "\">"
                   << std::endl;

        // Not terribly efficient
        //
        for (pt = m_programList.begin(); pt != m_programList.end(); ++pt)
        {
            if (pt->getBank().partialCompare(*it))
            {
                midiDevice << "            <program "
                           << "id=\"" << (int)pt->getProgram() << "\" "
                           << "name=\"" << encode(pt->getName()) << "\" ";
                if (!pt->getKeyMapping().empty()) {
                    midiDevice << "keymapping=\"" 
                               << encode(pt->getKeyMapping()) << "\" ";
                }
                midiDevice << "/>" << std::endl;
            }
        }

        midiDevice << "        </bank>" << std::endl << std::endl;
    }

    // Now controllers (before Instruments, which can depend on 
    // Controller colours)
    //
    midiDevice << "        <controls>" << std::endl;
    ControlList::const_iterator cIt;
    for (cIt = m_controlList.begin(); cIt != m_controlList.end() ; ++cIt)
        midiDevice << cIt->toXmlString();
    midiDevice << "        </controls>" << std::endl << std::endl;

    // Add instruments
    //
    for (iit = m_instruments.begin(); iit != m_instruments.end(); ++iit)
        midiDevice << (*iit)->toXmlString();

    KeyMappingList::const_iterator kit;

    for (kit = m_keyMappingList.begin(); kit != m_keyMappingList.end(); ++kit)
    {
        midiDevice << "        <keymapping "
                   << "name=\"" << encode(kit->getName()) << "\">\n";

        for (MidiKeyMapping::KeyNameMap::const_iterator nmi =
                 kit->getMap().begin(); nmi != kit->getMap().end(); ++nmi) {
            midiDevice << "          <key number=\"" << (int)nmi->first
                       << "\" name=\"" << encode(nmi->second) << "\"/>\n";
        }

//.........这里部分代码省略.........
开发者ID:tedfelix,项目名称:rosegarden,代码行数:101,代码来源:MidiDevice.cpp


示例4: WLock

int CLiveParser::GetOnePacket(char *pData, J_StreamHeader &streamHeader)
{
	WLock(m_rwLocker);
	if (m_dateType == J_VideoMjpeg)
	{
		if (m_nDataSize < (int)sizeof(int))
		{
			streamHeader.dataLen = 0;
			RWUnlock(m_rwLocker);
			return J_NOT_COMPLATE;
		}

		int nOffset = 0;
		int nLen = *((int *)(m_pDataBuff));
		nOffset += sizeof(int);
		memcpy(pData, m_pDataBuff + nOffset, nLen);
		nOffset += nLen;
		memmove(m_pDataBuff, m_pDataBuff + nOffset, m_nDataSize - nOffset);
		m_nDataSize -= nOffset;

		streamHeader.timeStamp = CTime::Instance()->GetLocalTime(0);
		streamHeader.dataLen = nLen;
		streamHeader.frameType = J_VideoIFrame;
	}
	else
	{
		int iDataLen = 640 * 480;
		if (m_nDataSize < iDataLen * 2)
		{
			streamHeader.dataLen = 0;
			RWUnlock(m_rwLocker);
			return J_NOT_COMPLATE;
		}

		streamHeader.timeStamp = CTime::Instance()->GetLocalTime(0);
		int nOffset = 0;
		YUV422To420((uint8_t *)m_pDataBuff, m_pPicIn->img.plane[0], m_pPicIn->img.plane[1], m_pPicIn->img.plane[2], 640, 480);
		nOffset = iDataLen * 2;

		m_pPicIn->i_pts = 0;//streamHeader.timeStamp * 90;
		//m_pPicIn->i_dts = streamHeader.timeStamp * 90;
		//++g_uiPTSFactor;
		encode(m_pX264Handle, m_pPicIn, m_pPicOut);
		memmove(m_pDataBuff, m_pDataBuff + nOffset, m_nDataSize - nOffset);
		m_nDataSize -= nOffset;

		nOffset = 0;
		for (int i = 0; i < m_iNal; ++i)
		{
			/*static FILE *fp = NULL;
			if (fp == NULL)
				fp = fopen("test.h264", "wb+");
			fwrite(m_pNals[i].p_payload, 1, m_pNals[i].i_payload, fp);*/

			memcpy(pData + nOffset, m_pNals[i].p_payload, m_pNals[i].i_payload);
			nOffset += m_pNals[i].i_payload;
		}

		streamHeader.dataLen = nOffset;
		streamHeader.frameType = J_VideoIFrame;
	}

	RWUnlock(m_rwLocker);
	return J_OK;
}
开发者ID:dulton,项目名称:jorhy-prj,代码行数:65,代码来源:LiveParser.cpp


示例5: main

void main()
{
   char szName[80];
   unsigned char szHolder[500], nSpaceCount = 0, nHighestVal = 0, nTot = 0;
   long lPos = 0, lToSkip;

   randomize();
   printf("Enter Sysop name   >");
   gets(szName);

   if ( strlen(szName) < 3 )
      exit(0);

   for ( short n = 0; n < strlen(szName); n++ )
      {
      if ( szName[n] == ' ' )
         nSpaceCount++;
      if ( szName[n] > nHighestVal )
         nHighestVal = szName[n];
      nTot += szName[n]/2;
      }

   szHolder[lPos++] = encode(strlen(szName), 0);
   szHolder[lPos++] = encode(nSpaceCount, 1);
   szHolder[lPos++] = encode(szName[2], 2);
   szHolder[lPos++] = encode(szName[strlen(szName)-1], 3);
   szHolder[lPos++] = encode(nHighestVal, 4);
   szHolder[lPos++] = encode(strlen(szName), 5);
   szHolder[lPos++] = encode(nTot, 6);
   
   strrev(szName);
   
   for ( short n = 0; n < strlen(szName); n++ )
      {
      szHolder[lPos] = encode(szName[n], lPos);
      lPos++;
      szHolder[lPos] = random(204) + 50;
      lToSkip = szHolder[lPos] / 50;
      szHolder[lPos] = ~szHolder[lPos];
      lPos++;

      unsigned char nSum = 7;
      for ( short k = 0; k < lToSkip; k++ )
         {
         szHolder[lPos] = random(250);
         nSum += szHolder[lPos]/6;
         lPos++;
         }
      szHolder[lPos++] = nSum;
      }

   fstream myFile;
   myFile.open("e:\\ttreg.dat", ios::binary | ios::out | ios::trunc );
   myFile.write(szHolder, lPos);
   myFile.close();

   myFile.open("e:\\doors\\trivia\\regs.log", ios::out | ios::app);
   myFile.write(strrev(szName), strlen(szName));
   char szText[120], szFullDate[12];
   _strdate(szFullDate);
   sprintf(szText, "\n  Registered on %s\n", szFullDate);
   myFile.write(szText, strlen(szText));
   sprintf(szText, "  File size: %ld\n  First ten bytes: ", lPos);
   for ( short n = 0; n < 10; n++ )
      {
      sprintf(szFullDate, "%u ", szHolder[n]);
      strcat(szText, szFullDate);
      }
   strcat(szText, "\n\n");
   myFile.write(szText, strlen(szText));
   printf("\nFile created and logged.\n");

   char szCheckName[80];
   short nStatus = getRegName(szCheckName, szHolder, lPos);
   printf("  -> Reg status: %d; %s.\n\n", nStatus, szCheckName);
}
开发者ID:evanelias,项目名称:tournament-trivia,代码行数:76,代码来源:regtriv.cpp


示例6: main

int main(int argc, char **argv) {

	int i, j, count = 0, encode_result_length, first_num, second_num, elecount, rows, personal_number = DEFAULT_PERSONAL_NUMBER, c;
	int date_len, verbose = 0, keyphrase_len;
	char t;

	int *date = DEFAULT_DATE;
	date_len = 6;
	int *random_ig = DEFAULT_RANDOM;


	/*Initialize the pointers that we'll need later */
	int *temp, *first_app_res, *assign_res, *header_checker, *first, *second;
	int *encode_result, *transpose_select, *new_header, *chain_res, *append_res, *sub_result;
	int **pseudo_random, **transpose_res, **second_num_trans, **final_res, **inter_trans, **message_matrix;

	char *key_phrase = DEFAULT_KEYPHRASE;
	keyphrase_len = strlen(key_phrase);
	
	char *message = DEFAULT_MESSAGE;


	while ((c = getopt_long(argc, argv, "d:p:k:m:v", longopts, NULL)) != -1)
        	switch (c) {
			case 'd':
				date_len = strlen(optarg);
				date = malloc(sizeof(int) * date_len);
				i = 0;
				while(i < strlen(optarg)) {
					t = optarg[i];
					if(t == 0) {
						fprintf (stderr, "--date must be in the form DDMMYYYY.\n");
						return -1;
					}
					date[i++] = atoi(&t);
				}

			break;

		        case 'p':
				personal_number = atoi(optarg);

				if(personal_number > 16) {
					fprintf (stderr, "--personal must be < 16 strictly.\n");
					return -1;
				}
		        break;
	
			case 'k':
				key_phrase = optarg;
				if(strlen(key_phrase) < 20) fprintf (stderr, "--personal must be < 16 strictly.\n");
				if(strlen(key_phrase) % 2 != 0) fprintf (stderr, "--personal must be divisible by two.\n");
				keyphrase_len = strlen(key_phrase);
			break;

			case 'm':
				message = optarg;
			break;

			case 'v':
				verbose = 1;
			break;

	                case '?':
             			if (optopt == 'k' || optopt == 'm' || optopt == 'd' || optopt == 'p')
					fprintf (stderr, "Option -%c requires an argument.\n", optopt);
			        else if (isprint (optopt))
					fprintf (stderr, "Unknown option `-%c'.\n", optopt);
             			else
			                fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
                                return -1;
			default:
				abort();
				return -1;
        }



	sub_result = modular_subtraction_digit(random_ig, date, 5);

	if(verbose == 1) {

		printf("\n1. Subtraction result:\n");

		for(i = 0; i < 5; i++) 
			printf("%d ", sub_result[i]);

		printf("\n \n");

	}

	first = assign_char(key_phrase, 0, keyphrase_len / 2, 65); 
	second = assign_char(key_phrase, keyphrase_len / 2, 10, 65); 


	if(verbose == 1) {

		printf("2. First character assigned result:\n");

		for(i = 0; i < keyphrase_len / 2; i++) 
//.........这里部分代码省略.........
开发者ID:aruneshmathur,项目名称:VIC-Cipher,代码行数:101,代码来源:main.c


示例7: encode

std::string encoder::encode() {
    std::string s;
    encode(s);
    return s;
}
开发者ID:Barba-studio,项目名称:qpid-proton,代码行数:5,代码来源:encoder.cpp


示例8: KTuplePairDist

/**
 *
 * Will compute ktuple scores and store in tmat
 * Following values will be set: tmat[i][j], where
 * istart <= i <iend
 * and
 * jstart <= j < jend
 * i.e. zero-offset
 * tmat data members have to be preallocated
 *
 * if ktuple_param_t *aln_param == NULL defaults will be used
 */
void
KTuplePairDist(symmatrix_t *tmat, mseq_t *mseq,
               int istart, int iend,
               int jstart, int jend,
               ktuple_param_t *param_override,
               progress_t *prProgress, 
               unsigned long int *ulStepNo, unsigned long int ulTotalStepNo)
{
    /* this first group of variables were previously static
       and hence un-parallelisable */
    char **seq_array;
    int maxsf;
    int **accum;
    int max_aln_length;
    /* divide score with length of smallest sequence */
    int *zza, *zzb, *zzc, *zzd;
    int private_step_no = 0;

    int i, j, dsr;
    double calc_score;
    int max_res_code = -1;

    int max_seq_len;
    int *seqlen_array;
    /* progress_t *prProgress; */
    /* int uStepNo, uTotalStepNo; */
    ktuple_param_t aln_param = default_protein_param;
    bool bPrintCR = (rLog.iLogLevelEnabled<=LOG_VERBOSE) ? FALSE : TRUE;


    if(prProgress == NULL) {
        NewProgress(&prProgress, LogGetFP(&rLog, LOG_INFO), 
                    "Ktuple-distance calculation progress", bPrintCR);
    }

    /* conversion to old style data types follows
     *
     */

    seqlen_array = (int*) CKMALLOC((mseq->nseqs+1) * sizeof(int));
    for (i=0; i<mseq->nseqs; i++) {
        seqlen_array[i+1] = mseq->sqinfo[i].len;
    }

    /* setup alignment parameters
     */
    if (SEQTYPE_PROTEIN == mseq->seqtype) {
        DNAFLAG = FALSE;
        max_res_code = strlen(AMINO_ACID_CODES)-2;
        aln_param = default_protein_param;

    } else if (SEQTYPE_RNA == mseq->seqtype || SEQTYPE_DNA == mseq->seqtype) {
        DNAFLAG = TRUE;
        max_res_code = strlen(NUCLEIC_ACID_CODES)-2;
        aln_param = default_dna_param;

    } else {
        Log(&rLog, LOG_FATAL, "Internal error in %s: Unknown sequence type.", __FUNCTION__);
    }

    if (NULL!=param_override) {
        aln_param.ktup = param_override->ktup;
        aln_param.wind_gap = param_override->wind_gap;
        aln_param.signif = param_override->signif;
        aln_param.window = param_override->window;
    }

    /*LOG_DEBUG("DNAFLAG = %d max_res_code = %d", DNAFLAG, max_res_code);*/

    /* convert mseq to clustal's old-style int encoded sequences (unit-offset)
     */
    max_aln_length = 0;
    max_seq_len = 0;
    seq_array =  (char **) CKMALLOC((mseq->nseqs+1) * sizeof(char *));
    seq_array[0] = NULL;
    /* FIXME check that non of the seqs is smaller than ktup (?).
     * Otherwise segfault occurs
     */
    for (i=0; i<mseq->nseqs; i++) {
        seq_array[i+1] = (char *) CKMALLOC((seqlen_array[i+1]+2) * sizeof (char));;
    }
    for (i=0; i<mseq->nseqs; i++) {
        /*LOG_DEBUG("calling encode with seq_array[%d+1] len=%d and seq=%s",
          i, seqlen_array[i+1], mseq->seq[i]);*/
        if (TRUE == DNAFLAG) {
            encode(&(mseq->seq[i][-1]), seq_array[i+1],
                   seqlen_array[i+1], NUCLEIC_ACID_CODES);
        } else  {
//.........这里部分代码省略.........
开发者ID:BioInfoTools,项目名称:MACSE,代码行数:101,代码来源:ktuple_pair.c


示例9: compress_site_patterns_diploid

unsigned long * compress_site_patterns_diploid(char ** sequence,
                                               const unsigned int * map,
                                               int count,
                                               int * length,
                                               unsigned int ** wptr,
                                               int attrib)
{
  int i,j;
  char * memptr;
  char ** column;
  unsigned int * weight;
  unsigned long * mapping;
  unsigned char ** jc69_invmaps = NULL;

  unsigned char charmap[ASCII_SIZE];
  unsigned char inv_charmap[ASCII_SIZE];

  /* check that at least one sequence is given */
  if (!count) return NULL;

  /* a map must be given */
  if (!map) return NULL;

  /* a zero can never be used as a state */
  if (map[0]) return NULL;

  /* if map states are out of the BYTE range, remap */
  if (findmax(map) >= ASCII_SIZE)
  {
    remap_range(map,charmap);

    /* for now only DNA with pll_map_nt */
    assert(0);
  }
  else
  {
    for (i = 0; i < ASCII_SIZE; ++i)
      charmap[i] = (unsigned char)(map[i]);
  }

  /* create inverse charmap to decode states back to characters when
     compression is finished */
  for (i = 0; i < ASCII_SIZE; ++i)
    if (map[i])
      inv_charmap[charmap[i]] = (unsigned char)i;

  /* encode sequences using charmap */
  encode(sequence,charmap,count,*length);

  /* allocate memory for columns */
  column = (char **)xmalloc((size_t)(*length)*sizeof(char *));

  /* allocate memory for the alignment */
  memptr = column[0] = (char *)xmalloc((size_t)(*length) *
                                       (size_t)(count+1) *
                                       sizeof(char));

  /* map memory to each column */
  for (i = 1; i < *length; ++i)
    column[i] = column[i-1] + (count+1);

  /* allocate space for weight vector */
  weight = (unsigned int *)xmalloc((size_t)(*length)*sizeof(unsigned int));

  /* allocate space for mapping vector */
  mapping = (unsigned long *)xmalloc((size_t)(*length)*sizeof(unsigned long));

  /* split alignment into columns instead of rows */
  for (i = 0; i < (*length); ++i)
  {
    for (j = 0; j < count; ++j)
      column[i][j] = sequence[j][i];
    column[i][j] = 0;
  }

  /* allocate space for storing original indices (before sorting sites) */
  int * oi = (int *)xmalloc(*length * sizeof(int));
  for (i = 0; i < *length; ++i)
    oi[i] = i;

    /* do the jc69 now */
  if (attrib == COMPRESS_JC69)
    jc69_invmaps = encode_jc69(column,*length,count);

  /* sort the columns and keep original indices */
  ssort1(column, *length, 0, oi);

  /*first site in uncompressed alignment maps to first site in compressed */
  int compressed_length = 1;
  size_t ref = 0;
  mapping[0] = 0;
  weight[ref] = 1;

  /* find all unique columns and set their mappings A2->A3 */
  int * compressed_oi = (int *)xmalloc(*length * sizeof(int));

  compressed_oi[0] = oi[0];
  for (i = 1; i < *length; ++i)
  {
    if (strcmp(column[i],column[i-1]))
//.........这里部分代码省略.........
开发者ID:xflouris,项目名称:bpp,代码行数:101,代码来源:compress.c


示例10: main

int
main(int argc, char **argv)
{
    SECStatus rv;
    int retval = -1;
    CERTCertDBHandle *certHandle = NULL;
    CERTCertificate *caCert = NULL, *cert = NULL;
    CERTOCSPCertID *cid = NULL;
    PLArenaPool *arena = NULL;
    PRTime now = PR_Now();
    
    SECItem *encoded = NULL;
    CERTOCSPResponse *decoded = NULL;
    SECStatus statusDecoded;

    SECItem *encodedRev = NULL;
    CERTOCSPResponse *decodedRev = NULL;
    SECStatus statusDecodedRev;
    
    SECItem *encodedFail = NULL;
    CERTOCSPResponse *decodedFail = NULL;
    SECStatus statusDecodedFail;

    CERTCertificate *obtainedSignerCert = NULL;

    if (argc != 4 && argc != 6) {
        return Usage();
    }

    if (argc == 6) {
        if (!strcmp(argv[4], "-p")) {
            pwdata.source = PW_PLAINTEXT;
            pwdata.data = PORT_Strdup(argv[5]);
        }
        else if (!strcmp(argv[4], "-f")) {
            pwdata.source = PW_FROMFILE;
            pwdata.data = PORT_Strdup(argv[5]);
        }
        else
            return Usage();
    }

    PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
    /*rv = NSS_Init(SECU_ConfigDirectory(NULL));*/
    rv = NSS_Init(argv[1]);
    if (rv != SECSuccess) {
	SECU_PrintPRandOSError(argv[0]);
	goto loser;
    }

    PK11_SetPasswordFunc(SECU_GetModulePassword);

    certHandle = CERT_GetDefaultCertDB();
    if (!certHandle)
	goto loser;

    if (!getCaAndSubjectCert(certHandle, argv[2], argv[3], &caCert, &cert))
        goto loser;

    cid = CERT_CreateOCSPCertID(cert, now);

    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
    encoded = encode(arena, cid, caCert);
    PORT_Assert(encoded);
    decoded = CERT_DecodeOCSPResponse(encoded);
    statusDecoded = CERT_GetOCSPResponseStatus(decoded);
    PORT_Assert(statusDecoded == SECSuccess);

    statusDecoded = CERT_VerifyOCSPResponseSignature(decoded, certHandle, &pwdata,
                                                &obtainedSignerCert, caCert);
    PORT_Assert(statusDecoded == SECSuccess);
    statusDecoded = CERT_GetOCSPStatusForCertID(certHandle, decoded, cid,
                                                obtainedSignerCert, now);
    PORT_Assert(statusDecoded == SECSuccess);
    CERT_DestroyCertificate(obtainedSignerCert);

    encodedRev = encodeRevoked(arena, cid, caCert);
    PORT_Assert(encodedRev);
    decodedRev = CERT_DecodeOCSPResponse(encodedRev);
    statusDecodedRev = CERT_GetOCSPResponseStatus(decodedRev);
    PORT_Assert(statusDecodedRev == SECSuccess);

    statusDecodedRev = CERT_VerifyOCSPResponseSignature(decodedRev, certHandle, &pwdata,
                                                        &obtainedSignerCert, caCert);
    PORT_Assert(statusDecodedRev == SECSuccess);
    statusDecodedRev = CERT_GetOCSPStatusForCertID(certHandle, decodedRev, cid,
                                                   obtainedSignerCert, now);
    PORT_Assert(statusDecodedRev == SECFailure);
    PORT_Assert(PORT_GetError() == SEC_ERROR_REVOKED_CERTIFICATE);
    CERT_DestroyCertificate(obtainedSignerCert);
    
    encodedFail = CERT_CreateEncodedOCSPErrorResponse(
        arena, SEC_ERROR_OCSP_TRY_SERVER_LATER);
    PORT_Assert(encodedFail);
    decodedFail = CERT_DecodeOCSPResponse(encodedFail);
    statusDecodedFail = CERT_GetOCSPResponseStatus(decodedFail);
    PORT_Assert(statusDecodedFail == SECFailure);
    PORT_Assert(PORT_GetError() == SEC_ERROR_OCSP_TRY_SERVER_LATER);

    retval = 0;
//.........这里部分代码省略.........
开发者ID:AOSC-Dev,项目名称:nss-purified,代码行数:101,代码来源:ocspresp.c


示例11: main

int main(int argc, char* argv[]){
	if (argc < 2){
		fprintf(stderr,"No se especifico ningun comando\n");
		return 1;
	}
	TParseArg* args;
	char *output = NULL;
	char *input = NULL;
	int* res = NULL;
	FILE* inFile;
	FILE* outFile;

	// Creo el parseador de argumentos
	args = ParseArg_new(6);
	// Agrego los argumentos a parsear, si uso valores por defecto como NULL con tama~no 0,
	// estoy haciendo qe sean obligatorios los argumentos
	ParseArg_addArg(args, NULL, 'h', "help", NULL, 0);
	ParseArg_addArg(args, NULL, 'v', "version", NULL, 0);
	ParseArg_addArg(args, NULL, 'e', "encode", NULL, 0);
	ParseArg_addArg(args, NULL, 'd', "decode", NULL, 0);
	ParseArg_addArg(args, &ParseArg_parseStr, 'o', "output", NULL, 0);
	ParseArg_addArg(args, &ParseArg_parseStr, 'i', "input", NULL, 0);
	ParseArg_parse(args, argc, argv);

	if(ParseArg_getArg(args, 'h')){
		usage();
		ParseArg_delete(args);
		return 0;
	}

	if(ParseArg_getArg(args, 'v')){
		version(argv[0]);
		ParseArg_delete(args);
		return 0;
	}
	input = (char*) ParseArg_getArg(args, 'i');
	output = (char*) ParseArg_getArg(args, 'o');

	if(input == NULL){
		inFile = stdin;
	}else{
		inFile = fopen(input, "r");
		if(!inFile){
			free(input);
			ParseArg_delete(args);
			return 1;
		}
	}

	if(output == NULL){
		outFile = stdout;
	}else{
		outFile = fopen(output, "wb");
		if(!outFile){
			free(output);
			ParseArg_delete(args);
			return 1;
		}
	}

	if(ParseArg_getArg(args, 'e')){
		encode(inFile,outFile);
		ParseArg_delete(args);
		return 0;
	}

	if(ParseArg_getArg(args, 'd')){
		decode(inFile,outFile);
		ParseArg_delete(args);
		return 0;
	}


	if( !(ParseArg_getArg(args,'e')) || !(ParseArg_getArg(args,'d')) || !(ParseArg_getArg(args,'h')) || !(ParseArg_getArg(args,'v'))){
		perror("No se especifico un comando valido");
		return 1;
	}

	
	if(outFile != stdout)
		fclose(outFile);

	if(inFile != stdin)
		fclose(inFile);

	free(res);
	free(output);
	free(input);
	ParseArg_delete(args);

	return 0;
}
开发者ID:Xero-Hige,项目名称:gaston-rodrigo,代码行数:92,代码来源:main.c


示例12: transformSubquery

//---------------------------------------------------------------------------
static bool transformSubquery(DictionarySegment& dict,DifferentialIndex* diffIndex,const SPARQLParser::PatternGroup& group,QueryGraph::SubQuery& output)
   // Transform a subquery
{
   // Encode all patterns
   for (std::vector<SPARQLParser::Pattern>::const_iterator iter=group.patterns.begin(),limit=group.patterns.end();iter!=limit;++iter) {
      // Encode the entries
      QueryGraph::Node node;
      if ((!encode(dict,diffIndex,(*iter).subject,node.subject,node.constSubject))||
          (!encode(dict,diffIndex,(*iter).predicate,node.predicate,node.constPredicate))||
          (!encode(dict,diffIndex,(*iter).object,node.object,node.constObject))) {
         // A constant could not be resolved. This will produce an empty result
         return false;
      }
      output.nodes.push_back(node);
   }

   // Encode the filter conditions
   for (std::vector<SPARQLParser::Filter>::const_iterator iter=group.filters.begin(),limit=group.filters.end();iter!=limit;++iter) {
      if (((*iter).type==SPARQLParser::Filter::Function)&&((*iter).arg1->value==tableFunctionId)) {
         encodeTableFunction(group,*iter,output);
         continue;
      }
      if (!encodeFilter(dict,diffIndex,group,*iter,output)) {
         // The filter variable is not bound. This will produce an empty result
         return false;
      }
   }

   // Encode all optional parts
   for (std::vector<SPARQLParser::PatternGroup>::const_iterator iter=group.optional.begin(),limit=group.optional.end();iter!=limit;++iter) {
      QueryGraph::SubQuery subQuery;
      if (!transformSubquery(dict,diffIndex,*iter,subQuery)) {
         // Known to produce an empty result, skip it
         continue;
      }
      output.optional.push_back(subQuery);
   }

   // Encode all union parts
   for (std::vector<std::vector<SPARQLParser::PatternGroup> >::const_iterator iter=group.unions.begin(),limit=group.unions.end();iter!=limit;++iter) {
      std::vector<QueryGraph::SubQuery> unionParts;
      for (std::vector<SPARQLParser::PatternGroup>::const_iterator iter2=(*iter).begin(),limit2=(*iter).end();iter2!=limit2;++iter2) {
         QueryGraph::SubQuery subQuery;
         if (!transformSubquery(dict,diffIndex,*iter2,subQuery)) {
            // Known to produce an empty result, skip it
            continue;
         }
         unionParts.push_back(subQuery);
      }
      // Empty union?
      if (unionParts.empty())
         return false;
      output.unions.push_back(unionParts);
   }

   // Encode all gjoin parts - Hancel y Giuseppe
   for (std::vector<std::vector<SPARQLParser::PatternGroup> >::const_iterator iter=group.gjoins.begin(),limit=group.gjoins.end();iter!=limit;++iter) {
      std::vector<QueryGraph::SubQuery> gjoinParts;
      for (std::vector<SPARQLParser::PatternGroup>::const_iterator iter2=(*iter).begin(),limit2=(*iter).end();iter2!=limit2;++iter2) {
         QueryGraph::SubQuery subQuery;
         if (!transformSubquery(dict,diffIndex,*iter2,subQuery)) {
            // Known to produce an empty result, skip it
            continue;
         }
         gjoinParts.push_back(subQuery);
      }
      // Empty gjoin?
      if (gjoinParts.empty())
         return false;
      output.gjoins.push_back(gjoinParts);
   }

   return true;
}
开发者ID:gdesimone,项目名称:toMonet,代码行数:75,代码来源:SemanticAnalysis.cpp


示例13: foreach

static int foreach(struct dbengine *db,
                   const char *prefix, size_t prefixlen,
                   foreach_p *goodp,
                   foreach_cb *cb, void *rock,
                   struct txn **mytid)
{
    int r = CYRUSDB_OK;
    int offset;
    unsigned long len;
    const char *p, *pend;
    const char *dataend;

    /* for use inside the loop, but we need the values to be retained
     * from loop to loop */
    struct buf keybuf = BUF_INITIALIZER;
    int dontmove = 0;

    /* For when we have a transaction running */
    struct buf savebuf = BUF_INITIALIZER;

    /* for the local iteration so that the db can change out from under us */
    const char *dbbase = NULL;
    size_t dblen = 0;
    int dbfd = -1;

    struct buf prefixbuf = BUF_INITIALIZER;

    r = starttxn_or_refetch(db, mytid);
    if (r) return r;

    if (!mytid) {
        /* No transaction, use the fast method to avoid stomping on our
         * memory map if changes happen */
        dbfd = dup(db->fd);
        if(dbfd == -1) return CYRUSDB_IOERROR;

        map_refresh(dbfd, 1, &dbbase, &dblen, db->size, db->fname, 0);

        /* drop our read lock on the file, since we don't really care
         * if it gets replaced out from under us, our mmap stays on the
         * old version */
        lock_unlock(db->fd, db->fname);
    }
    else {
        /* use the same variables as in the no transaction case, just to
         * get things set up */
        dbbase = db->base;
        dblen = db->len;
    }

    if (prefix) {
        encode(prefix, prefixlen, &prefixbuf);
        offset = bsearch_mem_mbox(prefixbuf.s, dbbase, db->size, 0, &len);
    }
    else {
        offset = 0;
    }

    p = dbbase + offset;
    pend = dbbase + db->size;

    while (p < pend) {
        if (!dontmove) {
            GETENTRY(p)
        }
        else dontmove = 0;

        /* does it still match prefix? */
        if (keybuf.len < (size_t) prefixbuf.len) break;
        if (prefixbuf.len && memcmp(keybuf.s, prefixbuf.s, prefixbuf.len)) break;

        if (!goodp || goodp(rock, keybuf.s, keybuf.len, DATA(db), DATALEN(db))) {
            unsigned long ino = db->ino;
            unsigned long sz = db->size;

            if(mytid) {
                /* transaction present, this means we do the slow way */
                buf_copy(&savebuf, &keybuf);
            }

            /* make callback */
            r = cb(rock, keybuf.s, keybuf.len, DATA(db), DATALEN(db));
            if (r) break;

            if (mytid) {
                /* reposition? (we made a change) */
                if (!(ino == db->ino && sz == db->size)) {
                    /* something changed in the file; reseek */
                    buf_cstring(&savebuf);
                    offset = bsearch_mem_mbox(savebuf.s, db->base, db->size,
                                              0, &len);
                    p = db->base + offset;

                    GETENTRY(p);

                    /* 'key' might not equal 'savebuf'.  if it's different,
                       we want to stay where we are.  if it's the same, we
                       should move on to the next one */
                    if (!buf_cmp(&savebuf, &keybuf)) {
                        p = dataend + 1;
//.........这里部分代码省略.........
开发者ID:JensErat,项目名称:cyrus-imapd,代码行数:101,代码来源:cyrusdb_flat.c


示例14: checksum

 void checksum(unsigned short n) { encode(2, 3, n); }
开发者ID:Shumen,项目名称:asio-exp,代码行数:1,代码来源:icmp_header.hpp


示例15: mystore

static int mystore(struct dbengine *db,
                   const char *key, size_t keylen,
                   const char *data, size_t datalen,
                   struct txn **mytid, int overwrite)
{
    int r = 0;
    char fnamebuf[1024];
    int offset;
    unsigned long len;
    const char *lockfailaction;
    int writefd;
    struct iovec iov[10];
    int niov;
    struct stat sbuf;
    struct buf keybuf = BUF_INITIALIZER;
    struct buf databuf = BUF_INITIALIZER;

    /* lock file, if needed */
    if (!mytid || !*mytid) {
        r = lock_reopen(db->fd, db->fname, &sbuf, &lockfailaction);
        if (r < 0) {
            syslog(LOG_ERR, "IOERROR: %s %s: %m", lockfailaction, db->fname);
            return CYRUSDB_IOERROR;
        }

        if (sbuf.st_ino != db->ino) {
            db->ino = sbuf.st_ino;
            map_free(&db->base, &db->len);
            map_refresh(db->fd, 0, &db->base, &db->len,
                        sbuf.st_size, db->fname, 0);
            db->size = sbuf.st_size;
        }

        if (mytid) {
            *mytid = new_txn();
        }
    }

    encode(key, keylen, &keybuf);

    /* find entry, if it exists */
    offset = bsearch_mem_mbox(keybuf.s, db->base, db->size, 0, &len);

    /* overwrite? */
    if (len && !overwrite) {
        if (mytid) abort_txn(db, *mytid);
        buf_free(&keybuf);
        buf_free(&databuf);
        return CYRUSDB_EXISTS;
    }

    /* write new file */
    if (mytid && (*mytid)->fnamenew) {
        strlcpy(fnamebuf, (*mytid)->fnamenew, sizeof(fnamebuf));
    } else {
        strlcpy(fnamebuf, db->fname, sizeof(fnamebuf));
        strlcat(fnamebuf, ".NEW", sizeof(fnamebuf));
    }

    unlink(fnamebuf);
    r = writefd = open(fnamebuf, O_RDWR | O_CREAT, 0666);
    if (r < 0) {
        syslog(LOG_ERR, "opening %s for writing failed: %m", fnamebuf);
        if (mytid) abort_txn(db, *mytid);
        buf_free(&keybuf);
        buf_free(&databuf);
        return CYRUSDB_IOERROR;
    }

    niov = 0;
    if (offset) {
        WRITEV_ADD_TO_IOVEC(iov, niov, (char *) db->base, offset);
    }

    if (data) {
        /* new entry */
        encode(data, datalen, &databuf);
        WRITEV_ADD_TO_IOVEC(iov, niov, keybuf.s, keybuf.len);
        WRITEV_ADD_TO_IOVEC(iov, niov, "\t", 1);
        WRITEV_ADD_TO_IOVEC(iov, niov, databuf.s, databuf.len);
        WRITEV_ADD_TO_IOVEC(iov, niov, "\n", 1);
    }

    if (db->size - (offset + len) > 0) {
        WRITEV_ADD_TO_IOVEC(iov, niov, (char *) db->base + offset + len,
                            db->size - (offset + len));
    }

    /* do the write */
    r = retry_writev(writefd, iov, niov);
    if (r == -1) {
        syslog(LOG_ERR, "IOERROR: writing %s: %m", fnamebuf);
        close(writefd);
        if (mytid) abort_txn(db, *mytid);
        buf_free(&keybuf);
        buf_free(&databuf);
        return CYRUSDB_IOERROR;
    }
    r = 0;

//.........这里部分代码省略.........
开发者ID:JensErat,项目名称:cyrus-imapd,代码行数:101,代码来源:cyrusdb_flat.c


示例16: identifier

 void identifier(unsigned short n) { encode(4, 5, n); }
开发者ID:Shumen,项目名称:asio-exp,代码行数:1,代码来源:icmp_header.hpp


示例17: invoke_reuse_incomplete

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ encode_ok_reply函数代码示例发布时间:2022-05-30
下一篇:
C++ enclosingIntRect函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap