<commit_before>/*
 HardwareSerial.cpp - esp8266 UART support

 Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
 This file is part of the esp8266 core for Arduino environment.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266)
 Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266)
 Modified 3 May 2015 by Hristo Gochkov (change register access methods)
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "Arduino.h"
#include "HardwareSerial.h"

HardwareSerial::HardwareSerial(int uart_nr)
    : _uart_nr(uart_nr), _rx_size(256)
{}

void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
{
    end();
    _uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size);
}

void HardwareSerial::end()
{
    if(uart_get_debug() == _uart_nr) {
        uart_set_debug(UART_NO);
    }

    if (_uart) {
        uart_uninit(_uart);
        _uart = NULL;
    }
}

size_t HardwareSerial::setRxBufferSize(size_t size){
    if(_uart) {
        _rx_size = uart_resize_rx_buffer(_uart, size);
    } else {
        _rx_size = size;
    }
    return _rx_size;
}

void HardwareSerial::swap(uint8_t tx_pin)
{
    if(!_uart) {
        return;
    }
    uart_swap(_uart, tx_pin);
}

void HardwareSerial::set_tx(uint8_t tx_pin)
{
    if(!_uart) {
        return;
    }
    uart_set_tx(_uart, tx_pin);
}

void HardwareSerial::pins(uint8_t tx, uint8_t rx)
{
    if(!_uart) {
        return;
    }
    uart_set_pins(_uart, tx, rx);
}

void HardwareSerial::setDebugOutput(bool en)
{
    if(!_uart) {
        return;
    }
    if(en) {
        if(uart_tx_enabled(_uart)) {
            uart_set_debug(_uart_nr);
        } else {
            uart_set_debug(UART_NO);
        }
    } else {
        // disable debug for this interface
        if(uart_get_debug() == _uart_nr) {
            uart_set_debug(UART_NO);
        }
    }
}

bool HardwareSerial::isTxEnabled(void)
{
    return _uart && uart_tx_enabled(_uart);
}

bool HardwareSerial::isRxEnabled(void)
{
    return _uart && uart_rx_enabled(_uart);
}

int HardwareSerial::available(void)
{
    int result = static_cast<int>(uart_rx_available(_uart));
    if (!result) {
        optimistic_yield(10000);
    }
    return result;
}

int HardwareSerial::peek(void)
{
    // this may return -1, but that's okay
    return uart_peek_char(_uart);
}

int HardwareSerial::read(void)
{
    // this may return -1, but that's okay
    return uart_read_char(_uart);
}

int HardwareSerial::availableForWrite(void)
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return 0;
    }

    return static_cast<int>(uart_tx_free(_uart));
}

void HardwareSerial::flush()
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return;
    }

    uart_wait_tx_empty(_uart);
    //Workaround for a bug in serial not actually being finished yet
    //Wait for 8 data bits, 1 parity and 2 stop bits, just in case
    delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
}

size_t HardwareSerial::write(uint8_t c)
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return 0;
    }

    uart_write_char(_uart, c);
    return 1;
}

int HardwareSerial::baudRate(void)
{
    // Null pointer on _uart is checked by SDK
    return uart_get_baudrate(_uart);
}

HardwareSerial::operator bool() const
{
    return _uart != 0;
}

HardwareSerial Serial(UART0);
HardwareSerial Serial1(UART1);
<commit_msg>allow disabling global Serial and Serial1 object (#2807)<commit_after>/*
 HardwareSerial.cpp - esp8266 UART support

 Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
 This file is part of the esp8266 core for Arduino environment.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266)
 Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266)
 Modified 3 May 2015 by Hristo Gochkov (change register access methods)
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "Arduino.h"
#include "HardwareSerial.h"

HardwareSerial::HardwareSerial(int uart_nr)
    : _uart_nr(uart_nr), _rx_size(256)
{}

void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
{
    end();
    _uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size);
}

void HardwareSerial::end()
{
    if(uart_get_debug() == _uart_nr) {
        uart_set_debug(UART_NO);
    }

    if (_uart) {
        uart_uninit(_uart);
        _uart = NULL;
    }
}

size_t HardwareSerial::setRxBufferSize(size_t size){
    if(_uart) {
        _rx_size = uart_resize_rx_buffer(_uart, size);
    } else {
        _rx_size = size;
    }
    return _rx_size;
}

void HardwareSerial::swap(uint8_t tx_pin)
{
    if(!_uart) {
        return;
    }
    uart_swap(_uart, tx_pin);
}

void HardwareSerial::set_tx(uint8_t tx_pin)
{
    if(!_uart) {
        return;
    }
    uart_set_tx(_uart, tx_pin);
}

void HardwareSerial::pins(uint8_t tx, uint8_t rx)
{
    if(!_uart) {
        return;
    }
    uart_set_pins(_uart, tx, rx);
}

void HardwareSerial::setDebugOutput(bool en)
{
    if(!_uart) {
        return;
    }
    if(en) {
        if(uart_tx_enabled(_uart)) {
            uart_set_debug(_uart_nr);
        } else {
            uart_set_debug(UART_NO);
        }
    } else {
        // disable debug for this interface
        if(uart_get_debug() == _uart_nr) {
            uart_set_debug(UART_NO);
        }
    }
}

bool HardwareSerial::isTxEnabled(void)
{
    return _uart && uart_tx_enabled(_uart);
}

bool HardwareSerial::isRxEnabled(void)
{
    return _uart && uart_rx_enabled(_uart);
}

int HardwareSerial::available(void)
{
    int result = static_cast<int>(uart_rx_available(_uart));
    if (!result) {
        optimistic_yield(10000);
    }
    return result;
}

int HardwareSerial::peek(void)
{
    // this may return -1, but that's okay
    return uart_peek_char(_uart);
}

int HardwareSerial::read(void)
{
    // this may return -1, but that's okay
    return uart_read_char(_uart);
}

int HardwareSerial::availableForWrite(void)
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return 0;
    }

    return static_cast<int>(uart_tx_free(_uart));
}

void HardwareSerial::flush()
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return;
    }

    uart_wait_tx_empty(_uart);
    //Workaround for a bug in serial not actually being finished yet
    //Wait for 8 data bits, 1 parity and 2 stop bits, just in case
    delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
}

size_t HardwareSerial::write(uint8_t c)
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return 0;
    }

    uart_write_char(_uart, c);
    return 1;
}

int HardwareSerial::baudRate(void)
{
    // Null pointer on _uart is checked by SDK
    return uart_get_baudrate(_uart);
}

HardwareSerial::operator bool() const
{
    return _uart != 0;
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
HardwareSerial Serial(UART0);
#endif
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
HardwareSerial Serial1(UART1);
#endif

<|endoftext|>


<commit_before>
// (c) COPYRIGHT URI/MIT 1997-98
// Please read the full copyright statement in the file COPYRIGH.
//
// Authors: reza (Reza Nekovei)

// This file contains functions which read the variables and their description
// from a freeform API and build the in-memeory DDS. These functions form the
// core of the server-side software necessary to extract the DDS from a
// FreeForm data file.
//
// It also contains test code which will print the in-memeory DDS to
// stdout.
//
// ReZa 6/20/97

// $Log: ffdds.cc,v $
// Revision 1.4  1998/08/12 21:21:15  jimg
// Massive changes from Reza. Compatible with the new FFND library
//
// Revision 1.3  1998/04/21 17:14:10  jimg
// Fixes for warnings, etc
//
// Revision 1.2  1998/04/16 18:11:25  jimg
// Sequence support added by Reza

#include "config_ff.h"

static char rcsid[] __unused__ ={"$Id: ffdds.cc,v 1.4 1998/08/12 21:21:15 jimg Exp $"};

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <iostream.h>

#include "DDS.h"
#include "FFInt32.h"
#include "FFFloat64.h"
#include "FFByte.h"
#include "FFArray.h"
#include "FFGrid.h"
#include "FFStr.h"
#include "cgi_util.h"
#include "FreeForm.h"
#include "util_ff.h"

// Used by ErrMsgT
static char Msgt[255];

bool
read_descriptors(DDS &dds_table,const char *filename, String *err_msg)
{
  int error = 0;
  int i = 0;
  int num_names = 0;
  char **var_names_vector = NULL;
  DATA_BIN_PTR dbin = NULL;
  FF_STD_ARGS_PTR SetUps = NULL;
  VARIABLE_PTR var = NULL;
  FORMAT_PTR iformat=NULL;
  PROCESS_INFO_LIST pinfo_list = NULL;
  PROCESS_INFO_PTR pinfo = NULL;
  bool newseq = true;
  bool is_array = true;
  Array *ar = NULL;
  Sequence *seq = NULL;

  // Set dataset name
  dds_table.set_dataset_name(name_path(filename));

  SetUps = ff_create_std_args();
  if (!SetUps)
    {
      sprintf(Msgt, "ff_dds: Insufficient memory -- free more memory and try again");
      ErrMsgT(Msgt);
      cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
      return false;
    }

  /** set the structure values to create the FreeForm DB**/
  SetUps->user.is_stdin_redirected = 0;
  SetUps->input_file = (char *)filename;
  String &ds = (char *)filename;
  String iff = find_ancillary_file(ds);
  char *if_f = new char[iff.length() + 1];
  strcpy(if_f, iff);
  SetUps->input_format_file = if_f;
  SetUps->output_file = NULL;

  error = SetDodsDB(SetUps, &dbin, Msgt);
  if (error && error < ERR_WARNING_ONLY)
    {
      db_destroy(dbin);
      ErrMsgT(Msgt);
      cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
      return false;
    }

  error = db_ask(dbin, DBASK_VAR_NAMES, FFF_INPUT, &num_names,
		 &var_names_vector);
  if (error){
    sprintf(Msgt, "ff_dds: db_ask could not get varible list from the input file");
    ErrMsgT(Msgt);
    cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
    return false;
  }

  error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_INPUT, &pinfo_list);
  if (!error)
    {
      pinfo_list = dll_first(pinfo_list);
      //	  pinfo      = FF_PI(pinfo_list);
      pinfo = ((PROCESS_INFO_PTR)(pinfo_list)->data.u.pi);
      iformat = PINFO_FORMAT(pinfo);
    }
  else {
    sprintf(Msgt, "ff_dds: db_ask could not get process info. for the input file");
    ErrMsgT(Msgt);
    cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
    return false;
  }

  /*For some formats: Freefrom sends extra NULL variables at the end of the list */
  for (i=0; ((*var_names_vector)[i])&&(i<num_names);i++) {
    int num_dim_names = 0;
    char **dim_names_vector = NULL;
    char *cp = NULL;
    FF_ARRAY_DIM_INFO_PTR array_dim_info = NULL;
    int j = 0;
    /***/

    error = db_ask(dbin, DBASK_ARRAY_DIM_NAMES, var_names_vector[i],
		   &num_dim_names, &dim_names_vector);
    if (error) {
      sprintf(Msgt, "ff_dds: db_ask could not get Array_Dim_names for var. %s",var_names_vector[i]);
      ErrMsgT(Msgt);
      cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
      return false;
    }

    var = NULL;
    /* sequence names  */
    if(num_dim_names == 0)
      cp = var_names_vector[i];
    else
      /* Note: FreeForm array names are returned appened to their format
	 name with '::' ? */
      cp = strstr(var_names_vector[i], "::")+2;

    var = ff_find_variable(cp,iformat);

    while(!var){ /* search formats in the format list for the variable */

      //pinfo_list = dll_next(pinfo_list);
      pinfo_list = (pinfo_list)->next;

      //pinfo      = FF_PI(pinfo_list);
      pinfo = ((PROCESS_INFO_PTR)(pinfo_list)->data.u.pi);

      if(!pinfo) {
	sprintf(Msgt, "ff_dds: Variable %s was not in found in any of format list",cp);
	ErrMsgT(Msgt);
	cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
	return false;
      }
      iformat = PINFO_FORMAT(pinfo);
      var = ff_find_variable(cp,iformat);
    }

    if(num_dim_names == 0){
      if(newseq){
	newseq = false;
	// The format name cannot contain spaces! 8/12/98 jhrg
	seq = NewSequence(iformat->name);
      }
      is_array=false;
    }
    else {
      ar = NewArray(cp);
      newseq = true; // An array terminates the old sequence
      is_array = true;
    }

    BaseType *bt = NULL;
    switch (FFV_DATA_TYPE(var))
      {
	case FFV_TEXT:
	  bt = NewByte(cp);
	  break;

	case FFV_INT8:
	  bt = NewInt32(cp);
	  break;

	case FFV_UINT8:
	  bt = NewUInt32(cp);
	  break;

	case FFV_INT16:
	  bt = NewInt32(cp);
	  break;

	case FFV_UINT16:
	  bt = NewUInt32(cp);
	  break;

	case FFV_INT32:
	  bt = NewInt32(cp);
	  break;

	case FFV_UINT32:
	  bt = NewUInt32(cp);
	  break;

	case FFV_INT64:
	  bt = NewInt32(cp);
	  break;

	case FFV_UINT64:
	  bt = NewUInt32(cp);
	  break;

	case FFV_FLOAT32:
	  bt = NewFloat64(cp);
	  break;

	case FFV_FLOAT64:
	  bt = NewFloat64(cp);
	  break;

	case FFV_ENOTE:
	  bt = NewStr(cp);
	  break;
      }

    if(is_array)
      ar->add_var(bt);
    else
      seq->add_var(bt);

    for (j = 0; j < num_dim_names; j++) {
      error = db_ask(dbin, DBASK_ARRAY_DIM_INFO,
		     var_names_vector[i], dim_names_vector[j],
		     &array_dim_info);
      if (error) {
	sprintf(Msgt, "ff_dds: db_ask could not get Array_Dim_Info for var. %s",var_names_vector[i]);
	ErrMsgT(Msgt);
	cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
	return false;
      }

      int DimSiz = (array_dim_info->end_index-array_dim_info->start_index+1)/array_dim_info->granularity;
      ar->append_dim(DimSiz, (String)dim_names_vector[j]);

#ifdef TEST
      printf("Array %s, dimension %s:\n", var_names_vector[i],
		 dim_names_vector[j]);
      printf("Start index is %ld\n", array_dim_info->start_index);
      printf("End index is %ld\n", array_dim_info->end_index);
      printf("Granularity is %ld\n", array_dim_info->granularity);
      printf("Separation is %ld\n", array_dim_info->separation);
      printf("Grouping is %ld\n\n", array_dim_info->grouping);
#endif

      memFree(array_dim_info, "");
      array_dim_info = NULL;

    }

    memFree(dim_names_vector, "");
    dim_names_vector = NULL;
    if(is_array)
      dds_table.add_var(ar);
    else
      if(newseq)
	dds_table.add_var(seq);
  }
  if(!is_array)
    dds_table.add_var(seq);

  memFree(var_names_vector, "");
  var_names_vector = NULL;

  return 1;

}

#ifdef TEST

int
main(int argc, char *argv[])
{
    DDS dds;
    String err;

    if(!read_descriptors(dds, argv[1], &err))
	abort();

    dds.print();
}

#endif

<commit_msg>Added default case to FFV_DATA_TYPE switch statement.<commit_after>
// (c) COPYRIGHT URI/MIT 1997-98
// Please read the full copyright statement in the file COPYRIGH.
//
// Authors: reza (Reza Nekovei)

// This file contains functions which read the variables and their description
// from a freeform API and build the in-memeory DDS. These functions form the
// core of the server-side software necessary to extract the DDS from a
// FreeForm data file.
//
// It also contains test code which will print the in-memeory DDS to
// stdout.
//
// ReZa 6/20/97

// $Log: ffdds.cc,v $
// Revision 1.5  1998/08/14 19:42:57  jimg
// Added default case to FFV_DATA_TYPE switch statement.
//
// Revision 1.4  1998/08/12 21:21:15  jimg
// Massive changes from Reza. Compatible with the new FFND library
//
// Revision 1.3  1998/04/21 17:14:10  jimg
// Fixes for warnings, etc
//
// Revision 1.2  1998/04/16 18:11:25  jimg
// Sequence support added by Reza

#include "config_ff.h"

static char rcsid[] __unused__ ={"$Id: ffdds.cc,v 1.5 1998/08/14 19:42:57 jimg Exp $"};

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <iostream.h>

#include "DDS.h"
#include "FFInt32.h"
#include "FFFloat64.h"
#include "FFByte.h"
#include "FFArray.h"
#include "FFGrid.h"
#include "FFStr.h"
#include "cgi_util.h"
#include "FreeForm.h"
#include "util_ff.h"

// Used by ErrMsgT
static char Msgt[255];

bool
read_descriptors(DDS &dds_table, const char *filename, String *err_msg)
{
    int error = 0;
    int i = 0;
    int num_names = 0;
    char **var_names_vector = NULL;
    DATA_BIN_PTR dbin = NULL;
    FF_STD_ARGS_PTR SetUps = NULL;
    VARIABLE_PTR var = NULL;
    FORMAT_PTR iformat=NULL;
    PROCESS_INFO_LIST pinfo_list = NULL;
    PROCESS_INFO_PTR pinfo = NULL;
    bool newseq = true;
    bool is_array = true;
    Array *ar = NULL;
    Sequence *seq = NULL;

    // Set dataset name
    dds_table.set_dataset_name(name_path(filename));

    SetUps = ff_create_std_args();
    if (!SetUps) {
	sprintf(Msgt, "ff_dds: Insufficient memory");
	ErrMsgT(Msgt);
	cat((String)"\"", (String)Msgt, (String)" \"", *(err_msg));
	return false;
    }

    // Set the structure values to create the FreeForm DB
    SetUps->user.is_stdin_redirected = 0;
    SetUps->input_file = (char *)filename;

    String iff = find_ancillary_file(filename);
    char *if_f = new char[iff.length() + 1];
    strcpy(if_f, iff);
    SetUps->input_format_file = if_f;
    SetUps->output_file = NULL;

    error = SetDodsDB(SetUps, &dbin, Msgt);
    if (error && error < ERR_WARNING_ONLY) {
	db_destroy(dbin);
	ErrMsgT(Msgt);
	cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
	return false;
    }

    error = db_ask(dbin, DBASK_VAR_NAMES, FFF_INPUT, &num_names,
		   &var_names_vector);
    if (error) {
	sprintf(Msgt, "ff_dds: db_ask could not get varible list from the input file");
	ErrMsgT(Msgt);
	cat((String)"\"", (String)Msgt, (String)" \"", *(err_msg));
	return false;
    }

    error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_INPUT, &pinfo_list);
    if (!error) {
	pinfo_list = dll_first(pinfo_list);
	// pinfo = FF_PI(pinfo_list);
	pinfo = ((PROCESS_INFO_PTR)(pinfo_list)->data.u.pi);
	iformat = PINFO_FORMAT(pinfo);
    }
    else {
	sprintf(Msgt, "ff_dds: db_ask could not get process info. for the input file");
	ErrMsgT(Msgt);
	cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
	return false;
    }

    // For some formats: Freefrom sends extra NULL variables at the end of
    // the list.
    for (i=0; ((*var_names_vector)[i])&&(i<num_names); i++) {
	int num_dim_names = 0;
	char **dim_names_vector = NULL;
	char *cp = NULL;
	FF_ARRAY_DIM_INFO_PTR array_dim_info = NULL;
	int j = 0;
	/***/

	error = db_ask(dbin, DBASK_ARRAY_DIM_NAMES, var_names_vector[i],
		       &num_dim_names, &dim_names_vector);
	if (error) {
	    sprintf(Msgt, "ff_dds: db_ask could not get Array_Dim_names for var. %s", var_names_vector[i]);
	    ErrMsgT(Msgt);
	    cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
	    return false;
	}

	var = NULL;

	if (num_dim_names == 0)	// sequence names
	    cp = var_names_vector[i];
	else
	    // Note: FreeForm array names are returned appened to their format
	    // name with '::' ?
	    cp = strstr(var_names_vector[i], "::")+2;

	var = ff_find_variable(cp, iformat);

	while (!var) { // search formats in the format list for the variable
	    //pinfo_list = dll_next(pinfo_list);
	    pinfo_list = (pinfo_list)->next;
	    //pinfo = FF_PI(pinfo_list);
	    pinfo = ((PROCESS_INFO_PTR)(pinfo_list)->data.u.pi);

	    if(!pinfo) {
		sprintf(Msgt, "ff_dds: Variable %s was not in found in any of format list",cp);
		ErrMsgT(Msgt);
		cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
		return false;
	    }

	    iformat = PINFO_FORMAT(pinfo);
	    var = ff_find_variable(cp, iformat);
	}

	if(num_dim_names == 0) {
	    if(newseq) {
		newseq = false;
		// The format name cannot contain spaces! 8/12/98 jhrg
		seq = NewSequence(iformat->name);
	    }
	    is_array=false;
	}
	else {
	    ar = NewArray(cp);
	    newseq = true; // An array terminates the old sequence
	    is_array = true;
	}

	BaseType *bt = NULL;
	switch (FFV_DATA_TYPE(var)) {
	  case FFV_TEXT:
	    bt = NewByte(cp);
	    break;

	  case FFV_INT8:
	    bt = NewInt32(cp);
	    break;

	  case FFV_UINT8:
	    bt = NewUInt32(cp);
	    break;

	  case FFV_INT16:
	    bt = NewInt32(cp);
	    break;

	  case FFV_UINT16:
	    bt = NewUInt32(cp);
	    break;

	  case FFV_INT32:
	    bt = NewInt32(cp);
	    break;

	  case FFV_UINT32:
	    bt = NewUInt32(cp);
	    break;

	  case FFV_INT64:
	    bt = NewInt32(cp);
	    break;

	  case FFV_UINT64:
	    bt = NewUInt32(cp);
	    break;

	  case FFV_FLOAT32:
	    bt = NewFloat64(cp);
	    break;

	  case FFV_FLOAT64:
	    bt = NewFloat64(cp);
	    break;

	  case FFV_ENOTE:
	    bt = NewStr(cp);
	    break;

	  default:
	    assert("Unknown FreeForm type!" && false);
	    break;
	}

	if (is_array)
	    ar->add_var(bt);
	else
	    seq->add_var(bt);

	for (j = 0; j < num_dim_names; j++) {
	    error = db_ask(dbin, DBASK_ARRAY_DIM_INFO,
			   var_names_vector[i], dim_names_vector[j],
			   &array_dim_info);
	    if (error) {
		sprintf(Msgt, "ff_dds: db_ask could not get Array_Dim_Info for var. %s",var_names_vector[i]);
		ErrMsgT(Msgt);
		cat((String)"\"",(String)Msgt,(String)" \"",*(err_msg));
		return false;
	    }

	    int DimSiz = (array_dim_info->end_index-array_dim_info->start_index+1)/array_dim_info->granularity;
	    ar->append_dim(DimSiz, (String)dim_names_vector[j]);

#ifdef TEST
	    printf("Array %s, dimension %s:\n", var_names_vector[i],
		   dim_names_vector[j]);
	    printf("Start index is %ld\n", array_dim_info->start_index);
	    printf("End index is %ld\n", array_dim_info->end_index);
	    printf("Granularity is %ld\n", array_dim_info->granularity);
	    printf("Separation is %ld\n", array_dim_info->separation);
	    printf("Grouping is %ld\n\n", array_dim_info->grouping);
#endif

	    memFree(array_dim_info, "");
	    array_dim_info = NULL;

	}

	memFree(dim_names_vector, "");
	dim_names_vector = NULL;
	if(is_array)
	    dds_table.add_var(ar);
	else
	    if(newseq)
		dds_table.add_var(seq);
    }

    if(!is_array)
	dds_table.add_var(seq);

    memFree(var_names_vector, "");
    var_names_vector = NULL;

    return true;
}

#ifdef TEST

int
main(int argc, char *argv[])
{
    DDS dds;
    String err;

    if(!read_descriptors(dds, argv[1], &err))
	abort();

    dds.print();
}

#endif

<|endoftext|>


<commit_before>/** \file    create_author_synomym_map.cc
 *  \brief   Creates a SOLR-MARC syonym map for authors from norm data.
 *  \author  Dr. Johannes Ruscheinski
 */

/*
    Copyright (C) 2016, Library of the University of Tübingen

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <vector>
#include <cstdlib>
#include "Compiler.h"
#include "MarcUtil.h"
#include "MediaTypeUtil.h"
#include "StringUtil.h"
#include "util.h"

void Usage() {
    std::cerr << "Usage: " << ::progname << " norm_data_marc_input synonym_map_output\n";
    std::exit(EXIT_FAILURE);
}

void RemoveCommasAndEmptyEntries(std::vector<std::string> * const vector) {
    std::vector<std::string> cleaned_up_vector;

    for (auto &entry : *vector) {
	StringUtil::RemoveChars(",", &entry);
	if (not entry.empty())
	    cleaned_up_vector.emplace_back(std::move(entry));
    }

    vector->swap(cleaned_up_vector);
}

void ExtractSynonymsAndWriteSynonymMap(File * const marc_input, File * const synonym_output, const std::string &field_list) {
    std::vector<std::string> fields;
    if (unlikely(StringUtil::Split(field_list, ':', &fields) < 2))
	Error("in ExtractSynonymsAndWriteSynonymMap: need at least two fields!");

    unsigned synomym_line_count(0), count(0);
    while (const MarcUtil::Record record = MarcUtil::Record::XmlFactory(marc_input)) {
        ++count;
	if (record.getFieldIndex(fields[0].substr(0, 3)) == -1)
	    continue;

	std::vector<std::string> subfield_values;
	record.extractSubfields(fields[0].substr(0, 3), fields[0].substr(3), &subfield_values);
	RemoveCommasAndEmptyEntries(&subfield_values);

	if (subfield_values.empty())
	    continue;

	std::vector<std::string> alternatives;
	alternatives.emplace_back(StringUtil::Join(subfield_values, ' '));

	for (auto field(fields.cbegin() + 1); field != fields.cend(); ++field) {
	    record.extractSubfields(field->substr(0, 3), field->substr(3), &subfield_values);
	    RemoveCommasAndEmptyEntries(&subfield_values);

	    if (not subfield_values.empty())
		alternatives.emplace_back(StringUtil::Join(subfield_values, ' '));
	}

	if (alternatives.size() > 1) {
	    (*synonym_output) << StringUtil::Join(alternatives, ',') << '\n';
	    ++synomym_line_count;
	}
    }

    std::cout << "Created " << synomym_line_count << " lines in the synonym map while processing " << count
	      << " norm data records.\n";
}

std::unique_ptr<File> OpenInputFile(const std::string &filename) {
    std::string mode("r");
    mode += MediaTypeUtil::GetFileMediaType(filename) == "application/lz4" ? "u" : "m";
    std::unique_ptr<File> file(new File(filename, mode));
    if (file == nullptr)
        Error("can't open \"" + filename + "\" for reading!");

    return file;
}

int main(int argc, char **argv) {
    ::progname = argv[0];

    if (argc != 3)
	Usage();

    std::unique_ptr<File> marc_input(OpenInputFile(argv[1]));

    const std::string synonym_map_filename(argv[2]);
    File synonym_output(synonym_map_filename, "w");
    if (not synonym_output)
        Error("can't open \"" + synonym_map_filename + "\" for writing!");

    try {
	ExtractSynonymsAndWriteSynonymMap(marc_input.get(), &synonym_output, "100abcd:400abcd");
    } catch (const std::exception &x) {
	Error("caught exception: " + std::string(x.what()));
    }
}
<commit_msg>Suplication elimination of author synonyms.<commit_after>/** \file    create_author_synomym_map.cc
 *  \brief   Creates a SOLR-MARC syonym map for authors from norm data.
 *  \author  Dr. Johannes Ruscheinski
 */

/*
    Copyright (C) 2016, Library of the University of Tübingen

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <vector>
#include <cstdlib>
#include "Compiler.h"
#include "MarcUtil.h"
#include "MediaTypeUtil.h"
#include "StringUtil.h"
#include "util.h"

void Usage() {
    std::cerr << "Usage: " << ::progname << " norm_data_marc_input synonym_map_output\n";
    std::exit(EXIT_FAILURE);
}

void RemoveCommasDuplicatesAndEmptyEntries(std::vector<std::string> * const vector) {
    std::vector<std::string> cleaned_up_vector;
    std::set<std::string> uniqe_entries;

    for (auto &entry : *vector) {
	StringUtil::RemoveChars(",", &entry);

        if (entry.empty())
            continue;

        bool isNewEntry = uniqe_entries.insert(entry).second;
        if (isNewEntry)
            cleaned_up_vector.emplace_back(std::move(entry));
    }

    vector->swap(cleaned_up_vector);
}

void ExtractSynonymsAndWriteSynonymMap(File * const marc_input, File * const synonym_output, const std::string &field_list) {
    std::set<std::string> synonyms;
    std::vector<std::string> fields;
    if (unlikely(StringUtil::Split(field_list, ':', &fields) < 2))
	Error("in ExtractSynonymsAndWriteSynonymMap: need at least two fields!");

    unsigned synomym_line_count(0), count(0);
    while (const MarcUtil::Record record = MarcUtil::Record::XmlFactory(marc_input)) {
        ++count;
	if (record.getFieldIndex(fields[0].substr(0, 3)) == -1)
	    continue;

	std::vector<std::string> subfield_values;
	record.extractSubfields(fields[0].substr(0, 3), fields[0].substr(3), &subfield_values);
        RemoveCommasDuplicatesAndEmptyEntries(&subfield_values);

	if (subfield_values.empty())
	    continue;

        std::sort(subfield_values.begin(), subfield_values.end());

	std::vector<std::string> alternatives;
	alternatives.emplace_back(StringUtil::Join(subfield_values, ' '));

	for (auto field(fields.cbegin() + 1); field != fields.cend(); ++field) {
	    record.extractSubfields(field->substr(0, 3), field->substr(3), &subfield_values);
            RemoveCommasDuplicatesAndEmptyEntries(&subfield_values);

	    if (subfield_values.empty())
                continue;

            std::sort(subfield_values.begin(), subfield_values.end());
            alternatives.emplace_back(StringUtil::Join(subfield_values, ' '));
	}

        RemoveCommasDuplicatesAndEmptyEntries(&alternatives);
        if (alternatives.size() <= 1)
            continue;

        std::string synonym(StringUtil::Join(alternatives, ','));
        if (not synonyms.insert(synonym).second)
            continue;

        (*synonym_output) << synonym << '\n';
	++synomym_line_count;
    }

    std::cout << "Created " << synomym_line_count << " lines in the synonym map while processing " << count
	      << " norm data records.\n";
}

std::unique_ptr<File> OpenInputFile(const std::string &filename) {
    std::string mode("r");
    mode += MediaTypeUtil::GetFileMediaType(filename) == "application/lz4" ? "u" : "m";
    std::unique_ptr<File> file(new File(filename, mode));
    if (file == nullptr)
        Error("can't open \"" + filename + "\" for reading!");

    return file;
}

int main(int argc, char **argv) {
    ::progname = argv[0];

    if (argc != 3)
	Usage();

    std::unique_ptr<File> marc_input(OpenInputFile(argv[1]));

    const std::string synonym_map_filename(argv[2]);
    File synonym_output(synonym_map_filename, "w");
    if (not synonym_output)
        Error("can't open \"" + synonym_map_filename + "\" for writing!");

    try {
	ExtractSynonymsAndWriteSynonymMap(marc_input.get(), &synonym_output, "100abcd:400abcd");
    } catch (const std::exception &x) {
	Error("caught exception: " + std::string(x.what()));
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: testidlclass.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-15 16:36:00 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#if OSL_DEBUG_LEVEL == 0
#define NDEBUG
#endif
#include <assert.h>

#include <cppuhelper/stdidlclass.hxx>

#include <com/sun/star/reflection/XIdlClassProvider.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>

#include "testhelper.hxx"

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::reflection;
using namespace ::rtl;

void testidlclass( const Reference < XMultiServiceFactory > &rSMgr)
{
    const OUString sImplName( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.cpputest") ) );

    // this reference is static to test behaviour during exiting application
    Reference < XIdlClass > r =
                ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0
                                            );

    assert( r.is() );

    {  // test the xidlclassprovider interface !
        Reference< XIdlClassProvider > rProv( r , UNO_QUERY );
        assert( rProv.is() );

        {
            Sequence < Reference < XIdlClass > > seq = rProv->getIdlClasses();

            // is always one
            assert( seq.getLength() == 1 );

            // test the weak reference
            rProv->getIdlClasses();

        }

        rProv->getIdlClasses();

    }

    assert( r->getName() == sImplName );

    // test equals
    Reference < XIdlClass > r2 =
                ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0
                                            );
    // test for implementation name
    assert( r2->equals( r ) );

    Sequence < Reference < XIdlClass > > seqIdlClass = r->getInterfaces();

    //TODO !
    // one idl class for one interface
    // this test fails, if core reflection fails !
//  assert( 1 == seqIdlClass.getLength() );
//  Reference < XIdlClass > rIdlInterface = seqIdlClass.getArray()[0];

    // check for IdlClass interface returned by Core Reflection
//  assert( rIdlInterface.is() );

    // Test all ten templates
    Reference< XIdlClass > x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );
}
<commit_msg>INTEGRATION: CWS ooo19126 (1.3.136); FILE MERGED 2005/09/05 12:07:47 rt 1.3.136.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: testidlclass.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 09:34:07 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#if OSL_DEBUG_LEVEL == 0
#define NDEBUG
#endif
#include <assert.h>

#include <cppuhelper/stdidlclass.hxx>

#include <com/sun/star/reflection/XIdlClassProvider.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>

#include "testhelper.hxx"

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::reflection;
using namespace ::rtl;

void testidlclass( const Reference < XMultiServiceFactory > &rSMgr)
{
    const OUString sImplName( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.cpputest") ) );

    // this reference is static to test behaviour during exiting application
    Reference < XIdlClass > r =
                ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0
                                            );

    assert( r.is() );

    {  // test the xidlclassprovider interface !
        Reference< XIdlClassProvider > rProv( r , UNO_QUERY );
        assert( rProv.is() );

        {
            Sequence < Reference < XIdlClass > > seq = rProv->getIdlClasses();

            // is always one
            assert( seq.getLength() == 1 );

            // test the weak reference
            rProv->getIdlClasses();

        }

        rProv->getIdlClasses();

    }

    assert( r->getName() == sImplName );

    // test equals
    Reference < XIdlClass > r2 =
                ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0
                                            );
    // test for implementation name
    assert( r2->equals( r ) );

    Sequence < Reference < XIdlClass > > seqIdlClass = r->getInterfaces();

    //TODO !
    // one idl class for one interface
    // this test fails, if core reflection fails !
//  assert( 1 == seqIdlClass.getLength() );
//  Reference < XIdlClass > rIdlInterface = seqIdlClass.getArray()[0];

    // check for IdlClass interface returned by Core Reflection
//  assert( rIdlInterface.is() );

    // Test all ten templates
    Reference< XIdlClass > x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );

    // Test all ten templates
    x = ::cppu::createStandardClass(
                                rSMgr ,
                                sImplName,
                                Reference < XIdlClass > () ,
                                (XMultiServiceFactory * ) 0 ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0  ,
                                (XServiceInfo * ) 0
                                            );
}
<|endoftext|>


<commit_before><commit_msg>Updated wav_ola_test. BUG=none TEST=none Review URL: http://codereview.chromium.org/165026<commit_after><|endoftext|>


<commit_before>/*

Copyright (c) 2008, Arvid Norberg
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 the author nor the names of its
      contributors 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/version.hpp>

#include "libtorrent/error_code.hpp"

namespace libtorrent
{
#if BOOST_VERSION >= 103500

	const char* libtorrent_error_category::name() const
	{
		return "libtorrent error";
	}

	std::string libtorrent_error_category::message(int ev) const
	{
		static char const* msgs[] =
		{
			"no error",
			"torrent file collides with file from another torrent",
			"hash check failed",
			"torrent file is not a dictionary",
			"missing or invalid 'info' section in torrent file",
			"'info' entry is not a dictionary",
			"invalid or missing 'piece length' entry in torrent file",
			"missing name in torrent file",
			"invalid 'name' of torrent (possible exploit attempt)",
			"invalid length of torrent",
			"failed to parse files from torrent file",
			"invalid or missing 'pieces' entry in torrent file",
			"incorrect number of piece hashes in torrent file",
			"too many pieces in torrent",
			"invalid metadata received from swarm",
			"invalid bencoding",
			"no files in torrent",
			"invalid escaped string",
			"session is closing",
			"torrent already exists in session",
			"invalid torrent handle used",
			"invalid type requested from entry",
			"missing info-hash from URI",
			"file too short",
			"unsupported URL protocol",
			"failed to parse URL",
			"peer sent 0 length piece",
			"parse failed",
			"invalid file format tag",
			"missing info-hash",
			"mismatching info-hash",
			"invalid hostname",
			"invalid port",
			"port blocked by port-filter",
			"expected closing ] for address",
			"destructing torrent",
			"timed out",
			"upload to uplaod connection",
			"uninteresting upload-only peer",
			"invalid info-hash",
			"torrent paused",
			"'have'-message with higher index than the number of pieces",
			"bitfield of invalid size",
			"too many piece requests while choked",
			"invalid piece packet",
			"out of memory",
			"torrent aborted",
			"connected to ourselves",
			"invalid piece size",
			"timed out: no interest",
			"timed out: inactivity",
			"timed out: no handshake",
			"timed out: no request",
			"invalid choke message",
			"invalid unchoke message",
			"invalid interested message",
			"invalid not-interested message",
			"invalid request message",
			"invalid hash list",
			"invalid hash piece message",
			"invalid cancel message",
			"invalid dht-port message",
			"invalid suggest piece message",
			"invalid have-all message",
			"invalid have-none message",
			"invalid reject message",
			"invalid allow-fast message",
			"invalid extended message",
			"invalid message",
			"sync hash not found",
			"unable to verify encryption constant",
			"plaintext mode not provided",
			"rc4 mode not provided",
			"unsupported encryption mode",
			"peer selected unsupported encryption mode",
			"invalid encryption pad size",
			"invalid encryption handshake",
			"incoming encrypted connections disabled",
			"incoming regular connections disabled",
			"duplicate peer-id",
			"torrent removed",
			"packet too large",
			"failed to parse HTTP response",
			"HTTP error",
			"missing location header",
			"invalid redirection",
			"redirecting",
			"invalid HTTP range",
			"missing content-length",
			"banned by IP filter",
			"too many connections",
			"peer banned",
			"stopping torrent",
			"too many corrupt pieces",
			"torrent is not ready to accept peers",
			"peer is not properly constructed",
			"session is closing",
			"optimistic disconnect",
			"torrent finished",
			"no router found",
			"metadata too large",
			"invalid metadata request",
			"invalid metadata size",
			"invalid metadata offset",
			"invalid metadata message",
			"pex message too large",
			"invalid pex message",
			"invalid lt_tracker message",

			"unsupported protocol version",
			"not authorized to create port map (enable NAT-PMP on your router)",
			"network failure",
			"out of resources",
			"unsupported opcode",
		};
		if (ev < 0 || ev >= sizeof(msgs)/sizeof(msgs[0]))
			return "Unknown error";
		return msgs[ev];
	}

	TORRENT_EXPORT libtorrent_error_category libtorrent_category;

#else

	::asio::error::error_category libtorrent_category(20);

#endif

}

<commit_msg>fixed typo<commit_after>/*

Copyright (c) 2008, Arvid Norberg
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 the author nor the names of its
      contributors 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/version.hpp>

#include "libtorrent/error_code.hpp"

namespace libtorrent
{
#if BOOST_VERSION >= 103500

	const char* libtorrent_error_category::name() const
	{
		return "libtorrent error";
	}

	std::string libtorrent_error_category::message(int ev) const
	{
		static char const* msgs[] =
		{
			"no error",
			"torrent file collides with file from another torrent",
			"hash check failed",
			"torrent file is not a dictionary",
			"missing or invalid 'info' section in torrent file",
			"'info' entry is not a dictionary",
			"invalid or missing 'piece length' entry in torrent file",
			"missing name in torrent file",
			"invalid 'name' of torrent (possible exploit attempt)",
			"invalid length of torrent",
			"failed to parse files from torrent file",
			"invalid or missing 'pieces' entry in torrent file",
			"incorrect number of piece hashes in torrent file",
			"too many pieces in torrent",
			"invalid metadata received from swarm",
			"invalid bencoding",
			"no files in torrent",
			"invalid escaped string",
			"session is closing",
			"torrent already exists in session",
			"invalid torrent handle used",
			"invalid type requested from entry",
			"missing info-hash from URI",
			"file too short",
			"unsupported URL protocol",
			"failed to parse URL",
			"peer sent 0 length piece",
			"parse failed",
			"invalid file format tag",
			"missing info-hash",
			"mismatching info-hash",
			"invalid hostname",
			"invalid port",
			"port blocked by port-filter",
			"expected closing ] for address",
			"destructing torrent",
			"timed out",
			"upload to upload connection",
			"uninteresting upload-only peer",
			"invalid info-hash",
			"torrent paused",
			"'have'-message with higher index than the number of pieces",
			"bitfield of invalid size",
			"too many piece requests while choked",
			"invalid piece packet",
			"out of memory",
			"torrent aborted",
			"connected to ourselves",
			"invalid piece size",
			"timed out: no interest",
			"timed out: inactivity",
			"timed out: no handshake",
			"timed out: no request",
			"invalid choke message",
			"invalid unchoke message",
			"invalid interested message",
			"invalid not-interested message",
			"invalid request message",
			"invalid hash list",
			"invalid hash piece message",
			"invalid cancel message",
			"invalid dht-port message",
			"invalid suggest piece message",
			"invalid have-all message",
			"invalid have-none message",
			"invalid reject message",
			"invalid allow-fast message",
			"invalid extended message",
			"invalid message",
			"sync hash not found",
			"unable to verify encryption constant",
			"plaintext mode not provided",
			"rc4 mode not provided",
			"unsupported encryption mode",
			"peer selected unsupported encryption mode",
			"invalid encryption pad size",
			"invalid encryption handshake",
			"incoming encrypted connections disabled",
			"incoming regular connections disabled",
			"duplicate peer-id",
			"torrent removed",
			"packet too large",
			"failed to parse HTTP response",
			"HTTP error",
			"missing location header",
			"invalid redirection",
			"redirecting",
			"invalid HTTP range",
			"missing content-length",
			"banned by IP filter",
			"too many connections",
			"peer banned",
			"stopping torrent",
			"too many corrupt pieces",
			"torrent is not ready to accept peers",
			"peer is not properly constructed",
			"session is closing",
			"optimistic disconnect",
			"torrent finished",
			"no router found",
			"metadata too large",
			"invalid metadata request",
			"invalid metadata size",
			"invalid metadata offset",
			"invalid metadata message",
			"pex message too large",
			"invalid pex message",
			"invalid lt_tracker message",

			"unsupported protocol version",
			"not authorized to create port map (enable NAT-PMP on your router)",
			"network failure",
			"out of resources",
			"unsupported opcode",
		};
		if (ev < 0 || ev >= sizeof(msgs)/sizeof(msgs[0]))
			return "Unknown error";
		return msgs[ev];
	}

	TORRENT_EXPORT libtorrent_error_category libtorrent_category;

#else

	::asio::error::error_category libtorrent_category(20);

#endif

}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: transliteration_commonclass.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2004-06-17 12:35:43 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include <transliteration_commonclass.hxx>
#include <com/sun/star/i18n/CollatorOptions.hpp>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::rtl;

namespace com { namespace sun { namespace star { namespace i18n {

transliteration_commonclass::transliteration_commonclass()
{
        transliterationName = "";
        implementationName = "";
        useOffset = sal_True;
}

OUString SAL_CALL transliteration_commonclass::getName() throw(RuntimeException)
{
        return OUString::createFromAscii(transliterationName);
}

void SAL_CALL transliteration_commonclass::loadModule( TransliterationModules modName, const Locale& rLocale )
        throw(RuntimeException)
{
        aLocale = rLocale;
}

void SAL_CALL
transliteration_commonclass::loadModuleNew( const Sequence < TransliterationModulesNew >& modName, const Locale& rLocale )
        throw(RuntimeException)
{
        throw RuntimeException();
}

void SAL_CALL
transliteration_commonclass::loadModuleByImplName( const OUString& implName, const Locale& rLocale )
        throw(RuntimeException)
{
        throw RuntimeException();
}

void SAL_CALL
transliteration_commonclass::loadModulesByImplNames(const Sequence< OUString >& modNamelist, const Locale& rLocale)
        throw(RuntimeException)
{
        throw RuntimeException();
}

Sequence< OUString > SAL_CALL
transliteration_commonclass::getAvailableModules( const Locale& rLocale, sal_Int16 sType )
        throw(RuntimeException)
{
        throw RuntimeException();
}

sal_Int32 SAL_CALL
transliteration_commonclass::compareSubstring(
        const OUString& str1, sal_Int32 off1, sal_Int32 len1,
        const OUString& str2, sal_Int32 off2, sal_Int32 len2)
        throw(RuntimeException)
{
        const sal_Unicode* unistr1 = NULL;
        const sal_Unicode* unistr2 = NULL;
        sal_uInt32 strlen1;
        sal_uInt32 strlen2;

        Sequence <sal_Int32> offset1(2*len1);
        Sequence <sal_Int32> offset2(2*len2);

        OUString in_str1 = this->transliterate(str1, off1, len1, offset1);
        OUString in_str2 = this->transliterate(str2, off2, len2, offset2);
        strlen1 = in_str1.getLength();
        strlen2 = in_str2.getLength();
        unistr1 = in_str1.getStr();
        unistr2 = in_str2.getStr();

        while (strlen1 && strlen2)
        {
            sal_uInt32 ret = *unistr1 - *unistr2;
            if (ret)
               return ret;

            unistr1++;
            unistr2++;
            strlen1--;
            strlen2--;
        }
        return strlen1 - strlen2;
}

sal_Int32 SAL_CALL
transliteration_commonclass::compareString( const OUString& str1, const OUString& str2 ) throw ( RuntimeException)
{
        return( this->compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength()));
}

OUString SAL_CALL
transliteration_commonclass::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) throw(RuntimeException)
{
    static Sequence < sal_Int32 > dummy_offset;
    useOffset = sal_False;
    OUString tmpStr = transliterate(inStr, startPos, nCount, dummy_offset);
    useOffset = sal_True;
    return tmpStr;
}

OUString SAL_CALL
transliteration_commonclass::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
{
    return transliteration_commonclass::transliterateString2String(OUString(&inChar, 1), 0, 1);
}

OUString SAL_CALL transliteration_commonclass::getImplementationName() throw( RuntimeException )
{
    return OUString::createFromAscii(implementationName);
}

const sal_Char cTrans[] = "com.sun.star.i18n.Transliteration.l10n";

sal_Bool SAL_CALL transliteration_commonclass::supportsService(const OUString& rServiceName) throw( RuntimeException )
{
        return rServiceName.equalsAscii(cTrans);
}

Sequence< OUString > SAL_CALL transliteration_commonclass::getSupportedServiceNames() throw( RuntimeException )
{
        Sequence< OUString > aRet(1);
        aRet[0] = OUString::createFromAscii(cTrans);
        return aRet;
}

} } } }
<commit_msg>INTEGRATION: CWS ooo19126 (1.5.60); FILE MERGED 2005/09/05 17:48:01 rt 1.5.60.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: transliteration_commonclass.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 17:36:36 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <transliteration_commonclass.hxx>
#include <com/sun/star/i18n/CollatorOptions.hpp>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::rtl;

namespace com { namespace sun { namespace star { namespace i18n {

transliteration_commonclass::transliteration_commonclass()
{
        transliterationName = "";
        implementationName = "";
        useOffset = sal_True;
}

OUString SAL_CALL transliteration_commonclass::getName() throw(RuntimeException)
{
        return OUString::createFromAscii(transliterationName);
}

void SAL_CALL transliteration_commonclass::loadModule( TransliterationModules modName, const Locale& rLocale )
        throw(RuntimeException)
{
        aLocale = rLocale;
}

void SAL_CALL
transliteration_commonclass::loadModuleNew( const Sequence < TransliterationModulesNew >& modName, const Locale& rLocale )
        throw(RuntimeException)
{
        throw RuntimeException();
}

void SAL_CALL
transliteration_commonclass::loadModuleByImplName( const OUString& implName, const Locale& rLocale )
        throw(RuntimeException)
{
        throw RuntimeException();
}

void SAL_CALL
transliteration_commonclass::loadModulesByImplNames(const Sequence< OUString >& modNamelist, const Locale& rLocale)
        throw(RuntimeException)
{
        throw RuntimeException();
}

Sequence< OUString > SAL_CALL
transliteration_commonclass::getAvailableModules( const Locale& rLocale, sal_Int16 sType )
        throw(RuntimeException)
{
        throw RuntimeException();
}

sal_Int32 SAL_CALL
transliteration_commonclass::compareSubstring(
        const OUString& str1, sal_Int32 off1, sal_Int32 len1,
        const OUString& str2, sal_Int32 off2, sal_Int32 len2)
        throw(RuntimeException)
{
        const sal_Unicode* unistr1 = NULL;
        const sal_Unicode* unistr2 = NULL;
        sal_uInt32 strlen1;
        sal_uInt32 strlen2;

        Sequence <sal_Int32> offset1(2*len1);
        Sequence <sal_Int32> offset2(2*len2);

        OUString in_str1 = this->transliterate(str1, off1, len1, offset1);
        OUString in_str2 = this->transliterate(str2, off2, len2, offset2);
        strlen1 = in_str1.getLength();
        strlen2 = in_str2.getLength();
        unistr1 = in_str1.getStr();
        unistr2 = in_str2.getStr();

        while (strlen1 && strlen2)
        {
            sal_uInt32 ret = *unistr1 - *unistr2;
            if (ret)
               return ret;

            unistr1++;
            unistr2++;
            strlen1--;
            strlen2--;
        }
        return strlen1 - strlen2;
}

sal_Int32 SAL_CALL
transliteration_commonclass::compareString( const OUString& str1, const OUString& str2 ) throw ( RuntimeException)
{
        return( this->compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength()));
}

OUString SAL_CALL
transliteration_commonclass::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) throw(RuntimeException)
{
    static Sequence < sal_Int32 > dummy_offset;
    useOffset = sal_False;
    OUString tmpStr = transliterate(inStr, startPos, nCount, dummy_offset);
    useOffset = sal_True;
    return tmpStr;
}

OUString SAL_CALL
transliteration_commonclass::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
{
    return transliteration_commonclass::transliterateString2String(OUString(&inChar, 1), 0, 1);
}

OUString SAL_CALL transliteration_commonclass::getImplementationName() throw( RuntimeException )
{
    return OUString::createFromAscii(implementationName);
}

const sal_Char cTrans[] = "com.sun.star.i18n.Transliteration.l10n";

sal_Bool SAL_CALL transliteration_commonclass::supportsService(const OUString& rServiceName) throw( RuntimeException )
{
        return rServiceName.equalsAscii(cTrans);
}

Sequence< OUString > SAL_CALL transliteration_commonclass::getSupportedServiceNames() throw( RuntimeException )
{
        Sequence< OUString > aRet(1);
        aRet[0] = OUString::createFromAscii(cTrans);
        return aRet;
}

} } } }
<|endoftext|>


<commit_before>/**
 * \file
 * \brief ThreadControlBlockList class header
 *
 * \author Copyright (C) 2014-2015 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2015-12-02
 */

#ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_
#define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_

#include "distortos/internal/containers/SortedContainer.hpp"

#include "distortos/internal/scheduler/ThreadControlBlock.hpp"

namespace distortos
{

namespace internal
{

/// functor which gives descending effective priority order of elements on the list
struct ThreadControlBlockDescendingEffectivePriority
{
	/**
	 * \brief ThreadControlBlockDescendingEffectivePriority's function call operator
	 *
	 * \param [in] left is the object on the left side of comparison
	 * \param [in] right is the object on the right side of comparison
	 *
	 * \return true if left's effective priority is less than right's effective priority
	 */

	bool operator()(const ThreadControlBlockListValueType& left, const ThreadControlBlockListValueType& right) const
	{
		return left.get().getEffectivePriority() < right.get().getEffectivePriority();
	}
};

/// base of ThreadControlBlockList
using ThreadControlBlockListBase = SortedContainer
		<
				ThreadControlBlockUnsortedList,
				ThreadControlBlockDescendingEffectivePriority
		>;

/// List of ThreadControlBlock objects in descending order of effective priority that configures state of kept objects
class ThreadControlBlockList : private ThreadControlBlockListBase
{
public:

	/// base of ThreadControlBlockList
	using Base = ThreadControlBlockListBase;

	using typename Base::iterator;
	using typename Base::value_type;

	using Base::begin;
	using Base::empty;
	using Base::end;

	/**
	 * \brief ThreadControlBlockList's constructor
	 *
	 * \param [in] allocator is a reference to ThreadControlBlockListAllocator object used to copy-construct allocator
	 * of base container
	 * \param [in] state is the state of ThreadControlBlock objects kept in this list
	 */

	constexpr ThreadControlBlockList(const ThreadControlBlockListAllocator& allocator, const ThreadState state) :
			Base{allocator},
			state_{state}
	{

	}

	/**
	 * \brief ThreadControlBlockList's destructor
	 *
	 * Clears list pointers in all elements.
	 */

	~ThreadControlBlockList();

	/**
	 * \brief Wrapper for sortedEmplace()
	 *
	 * Sets list pointer, iterator and state of emplaced element.
	 *
	 * \tparam Args are types of argument for value_type constructor
	 *
	 * \param [in] args are arguments for value_type constructor
	 *
	 * \return iterator to emplaced element
	 */

	template<typename... Args>
	iterator sortedEmplace(Args&&... args);

	/**
	 * \brief Wrapper for sortedSplice()
	 *
	 * Sets list pointer and state of transfered element.
	 *
	 * \param [in] other is the container from which the object is transfered
	 * \param [in] otherPosition is the position of the transfered object in the other container
	 */

	void sortedSplice(ThreadControlBlockList& other, iterator otherPosition);

private:

	/// state of ThreadControlBlock objects kept in this list
	const ThreadState state_;
};

template<typename... Args>
ThreadControlBlockList::iterator ThreadControlBlockList::sortedEmplace(Args&&... args)
{
	const auto it = Base::sortedEmplace(std::forward<Args>(args)...);
	auto& threadControlBlock = it->get();
	threadControlBlock.setList(this);
	threadControlBlock.setIterator(it);
	threadControlBlock.setState(state_);
	return it;
}

}	// namespace internal

}	// namespace distortos

#endif	// INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_
<commit_msg>add ThreadControlBlockList::getState()<commit_after>/**
 * \file
 * \brief ThreadControlBlockList class header
 *
 * \author Copyright (C) 2014-2015 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2015-12-02
 */

#ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_
#define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_

#include "distortos/internal/containers/SortedContainer.hpp"

#include "distortos/internal/scheduler/ThreadControlBlock.hpp"

namespace distortos
{

namespace internal
{

/// functor which gives descending effective priority order of elements on the list
struct ThreadControlBlockDescendingEffectivePriority
{
	/**
	 * \brief ThreadControlBlockDescendingEffectivePriority's function call operator
	 *
	 * \param [in] left is the object on the left side of comparison
	 * \param [in] right is the object on the right side of comparison
	 *
	 * \return true if left's effective priority is less than right's effective priority
	 */

	bool operator()(const ThreadControlBlockListValueType& left, const ThreadControlBlockListValueType& right) const
	{
		return left.get().getEffectivePriority() < right.get().getEffectivePriority();
	}
};

/// base of ThreadControlBlockList
using ThreadControlBlockListBase = SortedContainer
		<
				ThreadControlBlockUnsortedList,
				ThreadControlBlockDescendingEffectivePriority
		>;

/// List of ThreadControlBlock objects in descending order of effective priority that configures state of kept objects
class ThreadControlBlockList : private ThreadControlBlockListBase
{
public:

	/// base of ThreadControlBlockList
	using Base = ThreadControlBlockListBase;

	using typename Base::iterator;
	using typename Base::value_type;

	using Base::begin;
	using Base::empty;
	using Base::end;

	/**
	 * \brief ThreadControlBlockList's constructor
	 *
	 * \param [in] allocator is a reference to ThreadControlBlockListAllocator object used to copy-construct allocator
	 * of base container
	 * \param [in] state is the state of ThreadControlBlock objects kept in this list
	 */

	constexpr ThreadControlBlockList(const ThreadControlBlockListAllocator& allocator, const ThreadState state) :
			Base{allocator},
			state_{state}
	{

	}

	/**
	 * \brief ThreadControlBlockList's destructor
	 *
	 * Clears list pointers in all elements.
	 */

	~ThreadControlBlockList();

	/**
	 * \return state of ThreadControlBlock objects kept in this list
	 */

	ThreadState getState()
	{
		return state_;
	}

	/**
	 * \brief Wrapper for sortedEmplace()
	 *
	 * Sets list pointer, iterator and state of emplaced element.
	 *
	 * \tparam Args are types of argument for value_type constructor
	 *
	 * \param [in] args are arguments for value_type constructor
	 *
	 * \return iterator to emplaced element
	 */

	template<typename... Args>
	iterator sortedEmplace(Args&&... args);

	/**
	 * \brief Wrapper for sortedSplice()
	 *
	 * Sets list pointer and state of transfered element.
	 *
	 * \param [in] other is the container from which the object is transfered
	 * \param [in] otherPosition is the position of the transfered object in the other container
	 */

	void sortedSplice(ThreadControlBlockList& other, iterator otherPosition);

private:

	/// state of ThreadControlBlock objects kept in this list
	const ThreadState state_;
};

template<typename... Args>
ThreadControlBlockList::iterator ThreadControlBlockList::sortedEmplace(Args&&... args)
{
	const auto it = Base::sortedEmplace(std::forward<Args>(args)...);
	auto& threadControlBlock = it->get();
	threadControlBlock.setList(this);
	threadControlBlock.setIterator(it);
	threadControlBlock.setState(state_);
	return it;
}

}	// namespace internal

}	// namespace distortos

#endif	// INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCKLIST_HPP_
<|endoftext|>