// since in gcc 4.7 construction delegation does not work - provide a work around
//		whitelist_static_app::whitelist_static_app(cppcms::service &srv, const string& folder, const value& whitelist, hash_algorithm algo) 
//			: whitelist_static_app(srv, folder, signature::hash_function(algo)) {}
		whitelist_static_app::whitelist_static_app(cppcms::service &srv, const fs::path& folder, const value& whitelist, hash_algorithm algo) 
			: base_app(srv), whitelist_(whitelist), hash_function_(signature::hash_function(algo)), folder_(folder)
		{
			mapper().assign("");
		}
Exemple #2
0
int main(int argc, char** argv)
{
  utils::mpi_world mpi_world(argc, argv);
  
  const int mpi_rank = MPI::COMM_WORLD.Get_rank();
  const int mpi_size = MPI::COMM_WORLD.Get_size();
  
  try {
    if (getoptions(argc, argv) != 0) 
      return 1;

    if (command.empty())
      throw std::runtime_error("no command?");

    typedef MapReduce map_reduce_type;
      
    typedef map_reduce_type::id_type         id_type;
    typedef map_reduce_type::value_type      value_type;
    typedef map_reduce_type::queue_type      queue_type;
    typedef map_reduce_type::queue_id_type   queue_id_type;
    typedef map_reduce_type::subprocess_type subprocess_type;

    typedef Mapper  mapper_type;
    typedef Reducer reducer_type;
    
    typedef Consumer consumer_type;
    typedef Merger   merger_type;
    
    if (mpi_rank == 0) {
      subprocess_type subprocess(command);
      
      queue_type    queue_is(mpi_size);
      queue_type    queue_send(1);
      queue_id_type queue_id;
      queue_type    queue_recv;
      
      const bool flush_output = (output_file == "-"
				 || (boost::filesystem::exists(output_file)
				     && ! boost::filesystem::is_regular_file(output_file)));
      
      utils::compress_istream is(input_file, 1024 * 1024);
      utils::compress_ostream os(output_file, 1024 * 1024 * (! flush_output));

      boost::thread consumer(consumer_type(queue_is, is));
      boost::thread merger(merger_type(queue_recv, os, mpi_size));

      boost::thread mapper(mapper_type(queue_send, queue_id, subprocess));
      boost::thread reducer(reducer_type(queue_recv, queue_id, subprocess));
      
      typedef utils::mpi_ostream        ostream_type;
      typedef utils::mpi_istream_simple istream_type;

      typedef boost::shared_ptr<ostream_type> ostream_ptr_type;
      typedef boost::shared_ptr<istream_type> istream_ptr_type;
      
      typedef std::vector<ostream_ptr_type, std::allocator<ostream_ptr_type> > ostream_ptr_set_type;
      typedef std::vector<istream_ptr_type, std::allocator<istream_ptr_type> > istream_ptr_set_type;
      
      ostream_ptr_set_type ostream(mpi_size);
      istream_ptr_set_type istream(mpi_size);
      
      for (int rank = 1; rank < mpi_size; ++ rank) {
	ostream[rank].reset(new ostream_type(rank, line_tag, 4096));
	istream[rank].reset(new istream_type(rank, line_tag, 4096));
      }
      
      std::string line;
      value_type value(0, std::string());
      value_type value_recv(0, std::string());
      
      int non_found_iter = 0;
      
      while (value.first != id_type(-1)) {
	bool found = false;
	
	for (int rank = 1; rank < mpi_size && value.first != id_type(-1); ++ rank)
	  if (ostream[rank]->test() && queue_is.pop(value, true) && value.first != id_type(-1)) {
	    ostream[rank]->write(utils::lexical_cast<std::string>(value.first) + ' ' + value.second);
	    
	    found = true;
	  }
	
	if (queue_send.empty() && queue_is.pop(value, true) && value.first != id_type(-1)) {
	  queue_send.push(value);
	  
	  found = true;
	}
	
	// reduce...
	for (int rank = 1; rank < mpi_size; ++ rank)
	  if (istream[rank] && istream[rank]->test()) {
	    if (istream[rank]->read(line)) {
	      tokenize(line, value_recv);
	      
	      queue_recv.push_swap(value_recv);
	    } else {
	      queue_recv.push(std::make_pair(id_type(-1), std::string()));
	      istream[rank].reset();
	    }
	    
	    found = true;
	  }
	
	non_found_iter = loop_sleep(found, non_found_iter);
      }
      
      bool terminated = false;
      
      for (;;) {
	bool found = false;
	
	if (! terminated && queue_send.push(std::make_pair(id_type(-1), std::string()), true)) {
	  terminated = true;
	  
	  found = true;
	}
	
	// termination...
	for (int rank = 1; rank < mpi_size; ++ rank)
	  if (ostream[rank] && ostream[rank]->test()) {
	    if (! ostream[rank]->terminated())
	      ostream[rank]->terminate();
	    else
	      ostream[rank].reset();
	    
	    found = true;
	  }
	
	// reduce...
	for (int rank = 1; rank < mpi_size; ++ rank)
	  if (istream[rank] && istream[rank]->test()) {
	    if (istream[rank]->read(line)) {
	      tokenize(line, value_recv);
	      
	      queue_recv.push_swap(value_recv);
	    } else {
	      queue_recv.push(std::make_pair(id_type(-1), std::string()));
	      istream[rank].reset();
	    }
	    
	    found = true;
	  }
	
	// termination condition!
	if (std::count(istream.begin(), istream.end(), istream_ptr_type()) == mpi_size
	    && std::count(ostream.begin(), ostream.end(), ostream_ptr_type()) == mpi_size
	    && terminated) break;
	
	non_found_iter = loop_sleep(found, non_found_iter);
      }
      
      mapper.join();
      reducer.join();
      consumer.join();
      merger.join();
    } else {
      subprocess_type subprocess(command);
      
      queue_type    queue_send(1);
      queue_id_type queue_id;
      queue_type    queue_recv;
      
      boost::thread mapper(mapper_type(queue_send, queue_id, subprocess));
      boost::thread reducer(reducer_type(queue_recv, queue_id, subprocess));

      typedef utils::mpi_istream        istream_type;
      typedef utils::mpi_ostream_simple ostream_type;
      
      boost::shared_ptr<istream_type> is(new istream_type(0, line_tag, 4096));
      boost::shared_ptr<ostream_type> os(new ostream_type(0, line_tag, 4096));
      
      std::string line;
      value_type value;

      bool terminated = false;
      
      int non_found_iter = 0;
      for (;;) {
	bool found = false;
	
	if (is && is->test() && queue_send.empty()) {
	  if (is->read(line))
	    tokenize(line, value);
	  else {
	    value.first  = id_type(-1);
	    value.second = std::string();
	    
	    is.reset();
	  }
	  
	  queue_send.push_swap(value);
	  
	  found = true;
	}
	
	if (! terminated) {
	  if (os && os->test() && queue_recv.pop_swap(value, true)) {
	    if (value.first == id_type(-1))
	      terminated = true;
	    else
	      os->write(utils::lexical_cast<std::string>(value.first) + ' ' + value.second);
	    
	    found = true;
	  }
	} else {
	  if (os && os->test()) {
	    if (! os->terminated())
	      os->terminate();
	    else
	      os.reset();
	    found = true;
	  }
	}
	
	if (! is && ! os) break;
	
	non_found_iter = loop_sleep(found, non_found_iter);
      }
      
      mapper.join();
      reducer.join();
    }
    
    // synchronize...
    if (mpi_rank == 0) {
      std::vector<MPI::Request, std::allocator<MPI::Request> > request_recv(mpi_size);
      std::vector<MPI::Request, std::allocator<MPI::Request> > request_send(mpi_size);
      std::vector<bool, std::allocator<bool> > terminated_recv(mpi_size, false);
      std::vector<bool, std::allocator<bool> > terminated_send(mpi_size, false);
    
      terminated_recv[0] = true;
      terminated_send[0] = true;
      for (int rank = 1; rank != mpi_size; ++ rank) {
	request_recv[rank] = MPI::COMM_WORLD.Irecv(0, 0, MPI::INT, rank, notify_tag);
	request_send[rank] = MPI::COMM_WORLD.Isend(0, 0, MPI::INT, rank, notify_tag);
      }
    
      int non_found_iter = 0;
      for (;;) {
	bool found = false;
      
	for (int rank = 1; rank != mpi_size; ++ rank)
	  if (! terminated_recv[rank] && request_recv[rank].Test()) {
	    terminated_recv[rank] = true;
	    found = true;
	  }
      
	for (int rank = 1; rank != mpi_size; ++ rank)
	  if (! terminated_send[rank] && request_send[rank].Test()) {
	    terminated_send[rank] = true;
	    found = true;
	  }
      
	if (std::count(terminated_send.begin(), terminated_send.end(), true) == mpi_size
	    && std::count(terminated_recv.begin(), terminated_recv.end(), true) == mpi_size) break;
      
	non_found_iter = loop_sleep(found, non_found_iter);
      }
    } else {
      MPI::Request request_send = MPI::COMM_WORLD.Isend(0, 0, MPI::INT, 0, notify_tag);
      MPI::Request request_recv = MPI::COMM_WORLD.Irecv(0, 0, MPI::INT, 0, notify_tag);
    
      bool terminated_send = false;
      bool terminated_recv = false;
    
      int non_found_iter = 0;
      for (;;) {
	bool found = false;
      
	if (! terminated_send && request_send.Test()) {
	  terminated_send = true;
	  found = true;
	}
      
	if (! terminated_recv && request_recv.Test()) {
	  terminated_recv = true;
	  found = true;
	}
      
	if (terminated_send && terminated_recv) break;
      
	non_found_iter = loop_sleep(found, non_found_iter);
      }
    }
  }
  catch (const std::exception& err) {
    std::cerr << "error: " << argv[0] << " "<< err.what() << std::endl;
    MPI::COMM_WORLD.Abort(1);
    return 1;
  }
  return 0;
}
	/*}}}*/
};
int
xchar_length (xchar_t ch) /*{{{*/
{
	return utf8_length_tab[ch];
}/*}}}*/
int
xchar_strict_length (xchar_t ch) /*{{{*/
{
	return utf8_strict_length_tab[ch];
}/*}}}*/
int
xchar_valid_position (const xchar_t *s, int length) /*{{{*/
{
# define	VALID(ccc)	(((ccc) & 0xc0) == 0x80)
	int	len, n;
	
	if (((len = xchar_strict_length (*s)) > 0) && (length >= len))
		for (n = len; n > 1; ) {
			--n;
			if (! VALID (*(s + n))) {
				len = -1;
				break;
			}
		}
	else
		len = -1;
	return len;
# undef		VALID	
}/*}}}*/
bool_t
xchar_valid (const xchar_t *s, int length) /*{{{*/
{
	int	n;
	
	while (length > 0)
		if ((n = xchar_valid_position (s, length)) > 0) {
			s += n;
			length -= n;
		} else
			break;
	return length == 0 ? true : false;
}/*}}}*/
const char *
xchar_to_char (const xchar_t *s) /*{{{*/
{
	return (const char *) s;
}/*}}}*/
const xchar_t *
char_2_xchar (const char *s) /*{{{*/
{
	return (const xchar_t *) s;
}/*}}}*/
const char *
byte_to_char (const byte_t *b) /*{{{*/
{
	return (const char *) b;
}/*}}}*/
int
xstrlen (const xchar_t *s) /*{{{*/
{
	int	len, clen;
	
	for (len = 0; *s; ++len) {
		clen = xchar_length (*s);
		while ((clen-- > 0) && *s)
			++s;
	}
	return len;
}/*}}}*/
int
xstrcmp (const xchar_t *s1, const char *s2) /*{{{*/
{
	return strcmp (xchar_to_char (s1), s2);
}/*}}}*/
int
xstrncmp (const xchar_t *s1, const char *s2, size_t n) /*{{{*/
{
	return strncmp (xchar_to_char (s1), s2, n);
}/*}}}*/
bool_t
xmlbuf_equal (xmlbuf_t *b1, xmlbuf_t *b2) /*{{{*/
{
	if ((! b1) && (! b2))
		return true;
	if (b1 && b2 && (b1 -> length == b2 -> length) &&
	    ((! b1 -> length) || (! memcmp (b1 -> buffer, b2 -> buffer, b1 -> length))))
		return true;
	return false;
}/*}}}*/
char *
xmlbuf_to_string (xmlbuf_t *b) /*{{{*/
{
	return buffer_copystring ((buffer_t *) b);
}/*}}}*/
long
xmlbuf_to_long (xmlbuf_t *b) /*{{{*/
{
	const char	*s = b ? buffer_string (b) : NULL;

	return s ? strtol (s, NULL, 0) : -1;
}/*}}}*/

static inline unsigned long
mkcp (const xchar_t *s, int *len) /*{{{*/
{
	unsigned long	cp;
	int		n;
	
	*len = xchar_length (*s);
	for (n = 0, cp = 0; n < *len; ++n) {
		cp <<= 8;
		cp |= s[n];
	}
	return cp;
}/*}}}*/
static inline const utfmap_t *
mapfind (const xchar_t *s, int *len, const utfmap_t *map, int msize) /*{{{*/
{
	unsigned long	cp;
	int		low, high, pos;
	int		dummy;

	cp = mkcp (s, len ? len : & dummy);
	for (low = 0, high = msize; low < high; ) {
		pos = (low + high) >> 1;
		if (map[pos].cp == cp)
			return & map[pos];
		else if (map[pos].cp < cp)
			low = pos + 1;
		else
			high = pos;
	}
	return NULL;
}/*}}}*/
static inline bool_t
isword (const xchar_t *s) /*{{{*/
{
	unsigned long	cp;
	int		len;
	
	cp = mkcp (s, & len);
	if (len == 1)
		return isalnum (s[0]) ? true : false;
	else {
		int	low, high, pos;
		
		for (low = 0, high = is_word_length; low < high;) {
			pos = (low + high) >> 1;
			if (is_word[pos] == cp)
				return true;
			if (is_word[pos] < cp)
				low = pos + 1;
			else
				high = pos;
		}
	}
	return false;
}/*}}}*/
static inline const xchar_t *
mapper (const utfmap_t *map, int msize, const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	const utfmap_t	*m = mapfind (s, slen, map, msize);
	
	if (m) {
		if (olen)
			*olen = m -> dlen;
		return m -> dst;
	}
	return NULL;
}/*}}}*/
const xchar_t *
xtolower (const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	return mapper (utflower, utflower_length, s, slen, olen);
}/*}}}*/
const xchar_t *
xtoupper (const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	return mapper (utfupper, utfupper_length, s, slen, olen);
}/*}}}*/
InputGroup::InputGroup(unsigned category_, const char *label_) : category(category_), label(label_) {
  mapper().add(this);
}
void InputSettingsWindow::inputEvent(uint16_t scancode) {
  if(!activeInput) return;
  if(!isActiveWindow() || isMinimized()) return;
  int16_t state = mapper().state(scancode);

  if(dynamic_cast<DigitalInput*>(activeInput)) {
    if(Keyboard::isAnyKey(scancode) && mapper().state(scancode)) {
      for(unsigned i = 0; i < Keyboard::Count; i++) {
        //don't map escape key, as it is reserved by the user interface
        if(scancode == keyboard(i)[Keyboard::Escape]) return;
      }

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    } else if(Keyboard::isAnyModifier(scancode) && optionAssignModifiers->isChecked()) {
      setAssignment(string() << Scancode::encode(scancode));
    } else if(Mouse::isAnyButton(scancode) && mapper().state(scancode)) {
      //ensure button was clicked inside list box
      unsigned wx = 0, wy = 0;
      QWidget *widget = message;
      while(widget) {
        wx += widget->geometry().x();
        wy += widget->geometry().y();
        widget = widget->parentWidget();
      }
      unsigned px = QCursor::pos().x();
      unsigned py = QCursor::pos().y();
      if(px < wx || px >= wx + message->size().width()) return;
      if(py < wy || py >= wy + message->size().height()) return;

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    } else if(Joypad::isAnyHat(scancode)) {
      string position;
      if(state == Joypad::HatUp) position = ".Up";
      else if(state == Joypad::HatDown) position = ".Down";
      else if(state == Joypad::HatLeft) position = ".Left";
      else if(state == Joypad::HatRight) position = ".Right";
      else return;

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << position);
    } else if(Joypad::isAnyAxis(scancode) && mapper().distance(scancode) > 64) {
      if(mapper().calibrated == false) {
        MappedInput *temp = activeInput;
        activeInput = 0;
        mapper().calibrate();
        activeInput = temp;
      }

      if(mapper().isTrigger[Joypad::numberDecode(scancode)][Joypad::axisDecode(scancode)] == false) {
        string position;
        if(state < -24576) position = ".Lo";
        else if(state > +24576) position = ".Hi";
        else return;

        setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << position);
      } else {
        if(state >= 0) return;

        setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << ".Trigger");
      }
    } else if(Joypad::isAnyButton(scancode) && mapper().state(scancode)) {
      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    }
  } else if(dynamic_cast<AnalogInput*>(activeInput)) {
    if(Mouse::isAnyButton(scancode)) {
      //ensure button was clicked inside list box
      unsigned wx = 0, wy = 0;
      QWidget *widget = message;
      while(widget) {
        wx += widget->geometry().x();
        wy += widget->geometry().y();
        widget = widget->parentWidget();
      }
      unsigned px = QCursor::pos().x();
      unsigned py = QCursor::pos().y();
      if(px < wx || px >= wx + message->size().width()) return;
      if(py < wy || py >= wy + message->size().height()) return;

      unsigned number = Mouse::numberDecode(scancode);
      unsigned button = Mouse::buttonDecode(scancode);
      if(button == 0) setAssignment(string() << Scancode::encode(mouse(number).axis(0)));
      if(button == 2) setAssignment(string() << Scancode::encode(mouse(number).axis(1)));
    } else if(Joypad::isAnyAxis(scancode) && mapper().distance(scancode) > 64) {
      if(mapper().calibrated == false) {
        MappedInput *temp = activeInput;
        activeInput = 0;
        mapper().calibrate();
        activeInput = temp;
      }

      if(mapper().isTrigger[Joypad::numberDecode(scancode)][Joypad::axisDecode(scancode)] == false) {
        if(state < -24576 || state > +24576) {
          setAssignment(string() << Scancode::encode(scancode));
        }
      }
    }
  }
}
Exemple #6
0
ElfReader::Result ElfReader::readIt()
{
    if (!m_elfData.sectionHeaders.isEmpty())
        return Ok;
    if (!m_elfData.programHeaders.isEmpty())
        return Ok;

    ElfMapper mapper(this);
    if (!mapper.map())
        return Corrupt;

    const quint64 fdlen = mapper.fdlen;

    if (fdlen < 64) {
        m_errorString = QLibrary::tr("'%1' is not an ELF object (%2)")
            .arg(m_binary).arg(QLatin1String("file too small"));
        return NotElf;
    }

    if (strncmp(mapper.start, "\177ELF", 4) != 0) {
        m_errorString = QLibrary::tr("'%1' is not an ELF object")
                .arg(m_binary);
        return NotElf;
    }

    // 32 or 64 bit
    m_elfData.elfclass = ElfClass(mapper.start[4]);
    const bool is64Bit = m_elfData.elfclass == Elf_ELFCLASS64;
    if (m_elfData.elfclass != Elf_ELFCLASS32 && m_elfData.elfclass != Elf_ELFCLASS64) {
        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
            .arg(m_binary).arg(QLatin1String("odd cpu architecture"));
        return Corrupt;
    }

    // int bits = (data[4] << 5);
    // If you remove this check to read ELF objects of a different arch,
    // please make sure you modify the typedefs
    // to match the _plugin_ architecture.
    // if ((sizeof(void*) == 4 && bits != 32)
    //     || (sizeof(void*) == 8 && bits != 64)) {
    //     if (errorString)
    //         *errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
    //         .arg(m_binary).arg(QLatin1String("wrong cpu architecture"));
    //     return Corrupt;
    // }

    // Read Endianess.
    m_elfData.endian = ElfEndian(mapper.ustart[5]);
    if (m_elfData.endian != Elf_ELFDATA2LSB && m_elfData.endian != Elf_ELFDATA2MSB) {
        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
            .arg(m_binary).arg(QLatin1String("odd endianess"));
        return Corrupt;
    }

    const uchar *data = mapper.ustart + 16; // e_ident
    m_elfData.elftype    = ElfType(getHalfWord(data, m_elfData));
    m_elfData.elfmachine = ElfMachine(getHalfWord(data, m_elfData));
    /* e_version = */   getWord(data, m_elfData);
    m_elfData.entryPoint = getAddress(data, m_elfData);

    quint64 e_phoff   = getOffset(data, m_elfData);
    quint64 e_shoff   = getOffset(data, m_elfData);
    /* e_flags = */     getWord(data, m_elfData);

    quint32 e_shsize  = getHalfWord(data, m_elfData);

    if (e_shsize > fdlen) {
        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
            .arg(m_binary).arg(QLatin1String("unexpected e_shsize"));
        return Corrupt;
    }

    quint32 e_phentsize = getHalfWord(data, m_elfData);
    QTC_CHECK(e_phentsize == (is64Bit ? 56 : 32));
    quint32 e_phnum     = getHalfWord(data, m_elfData);

    quint32 e_shentsize = getHalfWord(data, m_elfData);

    if (e_shentsize % 4) {
        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
            .arg(m_binary).arg(QLatin1String("unexpected e_shentsize"));
        return Corrupt;
    }

    quint32 e_shnum     = getHalfWord(data, m_elfData);
    quint32 e_shtrndx   = getHalfWord(data, m_elfData);
    QTC_CHECK(data == mapper.ustart + (is64Bit ? 64 : 52));

    if (quint64(e_shnum) * e_shentsize > fdlen) {
        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
            .arg(m_binary)
            .arg(QLatin1String("announced %2 sections, each %3 bytes, exceed file size"))
            .arg(e_shnum).arg(e_shentsize);
        return Corrupt;
    }

    quint64 soff = e_shoff + e_shentsize * e_shtrndx;

//    if ((soff + e_shentsize) > fdlen || soff % 4 || soff == 0) {
//        m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
//           .arg(m_binary)
//           .arg(QLatin1String("shstrtab section header seems to be at %1"))
//           .arg(QString::number(soff, 16));
//        return Corrupt;
//    }

    if (e_shoff) {
        ElfSectionHeader strtab;
        parseSectionHeader(mapper.ustart + soff, &strtab, m_elfData);
        const quint64 stringTableFileOffset = strtab.offset;

        if (quint32(stringTableFileOffset + e_shentsize) >= fdlen
                || stringTableFileOffset == 0) {
            m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
                .arg(m_binary)
                .arg(QLatin1String("string table seems to be at %1"))
                .arg(QString::number(soff, 16));
            return Corrupt;
        }

        for (quint32 i = 0; i < e_shnum; ++i) {
            const uchar *s = mapper.ustart + e_shoff + i * e_shentsize;
            ElfSectionHeader sh;
            parseSectionHeader(s, &sh, m_elfData);

            if (stringTableFileOffset + sh.index > fdlen) {
                m_errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)")
                    .arg(m_binary)
                    .arg(QLatin1String("section name %2 of %3 behind end of file"))
                    .arg(i).arg(e_shnum);
                return Corrupt;
            }

            sh.name = mapper.start + stringTableFileOffset + sh.index;
            if (sh.name == ".gdb_index") {
                m_elfData.symbolsType = FastSymbols;
            } else if (sh.name == ".debug_info") {
                m_elfData.symbolsType = PlainSymbols;
            } else if (sh.name == ".gnu_debuglink") {
                m_elfData.debugLink = QByteArray(mapper.start + sh.offset);
                m_elfData.symbolsType = LinkedSymbols;
            } else if (sh.name == ".note.gnu.build-id") {
                m_elfData.symbolsType = BuildIdSymbols;
                if (sh.size > 16)
                    m_elfData.buildId = QByteArray(mapper.start + sh.offset + 16,
                                                   sh.size - 16).toHex();
            }
            m_elfData.sectionHeaders.append(sh);
        }
    }

    if (e_phoff) {
        for (quint32 i = 0; i < e_phnum; ++i) {
            const uchar *s = mapper.ustart + e_phoff + i * e_phentsize;
            ElfProgramHeader ph;
            parseProgramHeader(s, &ph, m_elfData);
            m_elfData.programHeaders.append(ph);
        }
    }
    return Ok;
}
Exemple #7
0
reply::reply(cppcms::service &srv) : thread_shared(srv)
{
	dispatcher().assign(".*",&reply::prepare,this,0);
	mapper().assign("{1}");
}
static void _testEPRs(void)
{
    const String NAMESPACE = "aa/bb";
    const String CLASSNAME = "MyClass";

    CIMRepository r(repositoryRoot, CIMRepository::MODE_XML);
    WsmToCimRequestMapper mapper(&r);

    // Test mapping of EPRs
    CIMObjectPath objectPath;
    WsmEndpointReference epr;
    epr.address = "http://www.acme.com:5988/wsman";
    epr.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr.selectorSet->selectors.
        append(WsmSelector("prop1", "value1"));
    epr.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", NAMESPACE));
    mapper.convertEPRToObjectPath(epr, objectPath);
    PEGASUS_TEST_ASSERT(objectPath.toString() ==
        "//www.acme.com/aa/bb:MyClass.prop1=\"value1\"");

    // Test mapping of EPR values
    WsmValue wsmEprValue(epr);
    CIMValue cimObjpathValue(CIMTYPE_REFERENCE, false);
    mapper.convertWsmToCimValue(wsmEprValue, NAMESPACE, cimObjpathValue);
    CIMObjectPath objectPath1;
    cimObjpathValue.get(objectPath1);
    PEGASUS_TEST_ASSERT(objectPath1.toString() ==
        "//www.acme.com/aa/bb:MyClass.prop1=\"value1\"");

    // Test mapping of EPR array values
    WsmEndpointReference epr1;
    epr1.address = "http://www.acme1.com:5988/wsman";
    epr1.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr1.selectorSet->selectors.
        append(WsmSelector("prop1", "value2"));
    epr1.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", NAMESPACE));
    Array<WsmEndpointReference> eprArray;
    eprArray.append(epr);
    eprArray.append(epr1);
    WsmValue wsmEprArrayValue(eprArray);
    CIMValue cimObjpathArrayValue(CIMTYPE_REFERENCE, true);
    mapper.convertWsmToCimValue(
        wsmEprArrayValue, NAMESPACE, cimObjpathArrayValue);
    Array<CIMObjectPath> objectPathArray;
    cimObjpathArrayValue.get(objectPathArray);
    PEGASUS_TEST_ASSERT(objectPathArray[0].toString() ==
        "//www.acme.com/aa/bb:MyClass.prop1=\"value1\"");
    PEGASUS_TEST_ASSERT(objectPathArray[1].toString() ==
        "//www.acme1.com/aa/bb:MyClass.prop1=\"value2\"");

    // Test invalid __cimnamespace selector type
    WsmEndpointReference epr2;
    epr2.address = "http://www.acme.com:5988/wsman";
    epr2.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr2.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", epr1));
    ASSERT_FAULT(
        mapper.convertEPRToObjectPath(epr2, objectPath),
        "wsman:InvalidSelectors");

    // Test illegal __cimnamespace name
    WsmEndpointReference epr3;
    epr3.address = "http://www.acme.com:5988/wsman";
    epr3.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr3.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", "garbage namespace #@!"));
    ASSERT_FAULT(
        mapper.convertEPRToObjectPath(epr3, objectPath),
        "wsman:InvalidSelectors");

    // Test illegal property name
    WsmEndpointReference epr4;
    epr4.address = "http://www.acme.com:5988/wsman";
    epr4.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr4.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", NAMESPACE));
    epr4.selectorSet->selectors.
        append(WsmSelector("prop 1", "value"));
    ASSERT_FAULT(
        mapper.convertEPRToObjectPath(epr4, objectPath),
        "wsman:InvalidSelectors");

    // Test non-existent property name
    WsmEndpointReference epr5;
    epr5.address = "http://www.acme.com:5988/wsman";
    epr5.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr5.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", NAMESPACE));
    epr5.selectorSet->selectors.
        append(WsmSelector("prop3", "value"));
    ASSERT_FAULT(
        mapper.convertEPRToObjectPath(epr5, objectPath),
        "wsman:InvalidSelectors");

    // Test type mismatch in key types
    WsmEndpointReference epr6;
    epr6.address = "https://www.acme.com:5988/wsman";
    epr6.resourceUri = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    epr6.selectorSet->selectors.
        append(WsmSelector("__cimnamespace", NAMESPACE));
    epr6.selectorSet->selectors.
        append(WsmSelector("prop3", epr1));
    ASSERT_FAULT(
        mapper.convertEPRToObjectPath(epr6, objectPath),
        "wsman:InvalidSelectors");

    // Test anonymous address in EPR
    String addr1 = mapper.convertEPRAddressToHostname(WSM_ADDRESS_ANONYMOUS);
    PEGASUS_TEST_ASSERT(addr1 == String::EMPTY);

    // Test malformed EPR addresses
    ASSERT_FAULT(
        mapper.convertEPRAddressToHostname("garbage"),
        "wsa:InvalidMessageInformationHeader");

    ASSERT_FAULT(
        mapper.convertEPRAddressToHostname("http://blah"),
        "wsa:InvalidMessageInformationHeader");

    ASSERT_FAULT(
        mapper.convertEPRAddressToHostname("http://bsa#@^&sa/wsman"),
        "wsa:InvalidMessageInformationHeader");
}
void MSWidgetResourceMapper::WidgetDestroyCallback::process(void)
{
  mapper().widgetDestroyed(this);
}
Exemple #10
0
static void _testConversionErrors(void)
{
    WsmToCimRequestMapper mapper((CIMRepository*) 0);

    // Invalid boolean
    {
        CIMValue cimValue(CIMTYPE_BOOLEAN, false);
        WsmValue wsmValue("test");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Invalid uint/sint
    {
        CIMValue cimValue(CIMTYPE_UINT8, false);
        WsmValue wsmValue("test");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_SINT8, false);
        WsmValue wsmValue("test");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Uint/sint out of bounds errors
    {
        CIMValue cimValue(CIMTYPE_SINT8, false);
        WsmValue wsmValue("-222");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_SINT16, false);
        WsmValue wsmValue("-777777");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_SINT32, false);
        WsmValue wsmValue("-4444444444");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_UINT8, false);
        WsmValue wsmValue("333");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_UINT16, false);
        WsmValue wsmValue("777777");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_UINT32, false);
        WsmValue wsmValue("4444444444");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Invalid real values
    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("35.54.32");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_REAL64, false);
        WsmValue wsmValue("35.54.32");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Test special floating point values. The only special values allowed
    // are INF, -INF and NaN
    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("+INF");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("0x2");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("nan");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("inf");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    {
        CIMValue cimValue(CIMTYPE_REAL32, false);
        WsmValue wsmValue("i");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Invalid char16
    {
        CIMValue cimValue(CIMTYPE_CHAR16, false);
        WsmValue wsmValue("35.54.32");
        ASSERT_FAULT(
            mapper.convertWsmToCimValue(wsmValue, CIMNamespaceName(), cimValue),
            "wxf:InvalidRepresentation");
    }

    // Invalid class URI
    {
        ASSERT_FAULT(
            mapper.convertResourceUriToClassName("garbage"),
            "wsa:DestinationUnreachable");
    }

    {
        String classURI = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/My{}Class";
        ASSERT_FAULT(
            mapper.convertResourceUriToClassName(classURI),
            "wsa:DestinationUnreachable");
    }

    // Invalid date/time
    {
        CIMDateTime cimDT;

        // Invalid dates
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("-2004-12-01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("+2004-12-01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-+2-01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12- 1", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("322004-12-01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-112-01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-00", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12:01", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01ZX", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01Z+01:30", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01+001:30", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01+01:030", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-0101:30", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01+25:30", cimDT),
            "wxf:InvalidRepresentation");
         ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01+22:66", cimDT),
            "wxf:InvalidRepresentation");
       ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01+++1:3", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01-01:-6", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01-01:66", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01Z+:.", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("4324g432", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("a-e-3Z", cimDT),
            "wxf:InvalidRepresentation");

        // Invalid Datetimes
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22:33X", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22:33.Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22:33.44Z0", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22:33.44Z+0", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("004-12-01T11:22:33.44Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11Z22:33.44Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22:133.44Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-01T11:22.133Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("--T::", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("1-1-1T1:1:1", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime(" 004-12-01T11:22:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-+2-01T11:22:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12- 1T11:22:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-1T11:22:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T-1:22:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:+2:33Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22: 3Z", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22:33.X", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22:33.+1", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22:33.+1S", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22:33+25:00", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("2004-12-11T11:22:33+22:66", cimDT),
            "wxf:InvalidRepresentation");


        // Invalid intervals
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P100", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT100", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT100K", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT100Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT100D", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1M1Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1D1M", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1DT1M1H", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1DTM", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT1Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT1M1.S", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT1M1S.0", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT1H1.2M", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1YT1HT1M", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P-1Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P-1M", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P-1D", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT-1H", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT-1M", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT-1S", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P 1Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P~Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P22.33S", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("PT22.33S1Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P999999999Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P9999999999Y", cimDT),
            "wxf:InvalidRepresentation");
        ASSERT_FAULT(
            mapper.convertWsmToCimDatetime("P1Y9999999999S", cimDT),
            "wxf:InvalidRepresentation");
    }
}
Exemple #11
0
static void _testInstances(void)
{
    const String NAMESPACE = "aa/bb";
    const String CLASSNAME = "MyClass";

    CIMRepository r(repositoryRoot, CIMRepository::MODE_XML);
    WsmToCimRequestMapper mapper(&r);

    // Create a repository entry
    r.createNameSpace(NAMESPACE);
    CIMClass cimClass(CLASSNAME);
    cimClass.addProperty(CIMProperty(CIMName("prop1"), String::EMPTY));
    cimClass.addProperty(CIMProperty(CIMName("prop2"), String::EMPTY));
    r.createClass(NAMESPACE, cimClass);

    CIMInstance cimInst;
    WsmInstance wsmInst(CLASSNAME);
    WsmValue val1("value1");
    WsmValue val2("value2");

    // Test mapping of instances
    wsmInst.addProperty(WsmProperty(String("prop1"), val1));
    wsmInst.addProperty(WsmProperty(String("prop2"), val2));
    mapper.convertWsmToCimInstance(wsmInst, NAMESPACE, cimInst);

    String str1, str2;
    PEGASUS_TEST_ASSERT(cimInst.getClassName().getString() == CLASSNAME);
    PEGASUS_TEST_ASSERT(
        cimInst.getProperty(0).getName().getString() == "prop1");
    PEGASUS_TEST_ASSERT(cimInst.getProperty(0).getType() == CIMTYPE_STRING);
    cimInst.getProperty(0).getValue().get(str1);
    PEGASUS_TEST_ASSERT(str1 == "value1");
    PEGASUS_TEST_ASSERT(
        cimInst.getProperty(1).getName().getString() == "prop2");
    PEGASUS_TEST_ASSERT(cimInst.getProperty(1).getType() == CIMTYPE_STRING);
    cimInst.getProperty(1).getValue().get(str2);
    PEGASUS_TEST_ASSERT(str2 == "value2");

    // Test mapping of instance values
    WsmValue wsmInstValue(wsmInst);
    CIMValue cimInstValue(CIMTYPE_INSTANCE, false);
    mapper.convertWsmToCimValue(wsmInstValue, NAMESPACE, cimInstValue);
    CIMInstance cimInst1;
    cimInstValue.get(cimInst1);
    PEGASUS_TEST_ASSERT(cimInst1.getClassName().getString() == CLASSNAME);
    PEGASUS_TEST_ASSERT(
        cimInst1.getProperty(0).getName().getString() == "prop1");
    PEGASUS_TEST_ASSERT(cimInst1.getProperty(0).getType() == CIMTYPE_STRING);
    cimInst1.getProperty(0).getValue().get(str1);
    PEGASUS_TEST_ASSERT(str1 == "value1");
    PEGASUS_TEST_ASSERT(
        cimInst1.getProperty(1).getName().getString() == "prop2");
    PEGASUS_TEST_ASSERT(cimInst1.getProperty(1).getType() == CIMTYPE_STRING);
    cimInst1.getProperty(1).getValue().get(str2);
    PEGASUS_TEST_ASSERT(str2 == "value2");

    // Test mapping of instance array values
    WsmInstance wsmInst1(CLASSNAME);
    WsmValue val3("value3");
    WsmValue val4("value4");
    wsmInst1.addProperty(WsmProperty(String("prop1"), val3));
    wsmInst1.addProperty(WsmProperty(String("prop2"), val4));
    Array<WsmInstance> wsmInstArray;
    wsmInstArray.append(wsmInst);
    wsmInstArray.append(wsmInst1);
    WsmValue wsmInstArrayValue(wsmInstArray);
    CIMValue cimInstArrayValue(CIMTYPE_INSTANCE, true);
    mapper.convertWsmToCimValue(
        wsmInstArrayValue, NAMESPACE, cimInstArrayValue);
    Array<CIMInstance> cimInstArray;
    cimInstArrayValue.get(cimInstArray);
    PEGASUS_TEST_ASSERT(cimInstArray.size() == 2);

    PEGASUS_TEST_ASSERT(
        cimInstArray[0].getClassName().getString() == CLASSNAME);
    PEGASUS_TEST_ASSERT(
        cimInstArray[0].getProperty(0).getName().getString() == "prop1");
    PEGASUS_TEST_ASSERT(
        cimInstArray[0].getProperty(0).getType() == CIMTYPE_STRING);
    cimInstArray[0].getProperty(0).getValue().get(str1);
    PEGASUS_TEST_ASSERT(str1 == "value1");
    PEGASUS_TEST_ASSERT(
        cimInstArray[0].getProperty(1).getName().getString() == "prop2");
    PEGASUS_TEST_ASSERT(
        cimInstArray[0].getProperty(1).getType() == CIMTYPE_STRING);
    cimInstArray[0].getProperty(1).getValue().get(str2);
    PEGASUS_TEST_ASSERT(str2 == "value2");

    PEGASUS_TEST_ASSERT(
        cimInstArray[1].getClassName().getString() == CLASSNAME);
    PEGASUS_TEST_ASSERT(
        cimInstArray[1].getProperty(0).getName().getString() == "prop1");
    PEGASUS_TEST_ASSERT(
        cimInstArray[1].getProperty(0).getType() == CIMTYPE_STRING);
    cimInstArray[1].getProperty(0).getValue().get(str1);
    PEGASUS_TEST_ASSERT(str1 == "value3");
    PEGASUS_TEST_ASSERT(
        cimInstArray[1].getProperty(1).getName().getString() == "prop2");
    PEGASUS_TEST_ASSERT(
        cimInstArray[1].getProperty(1).getType() == CIMTYPE_STRING);
    cimInstArray[1].getProperty(1).getValue().get(str2);
    PEGASUS_TEST_ASSERT(str2 == "value4");

    // Test non-existent class
    try
    {
        wsmInst.setClassName("garbage");
        mapper.convertWsmToCimInstance(wsmInst, NAMESPACE, cimInst);
        PEGASUS_TEST_ASSERT(0);
    }
    catch (CIMException& e)
    {
        PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND);
    }

    // Test non-existent property
    {
        WsmValue val("value3");
        wsmInst.setClassName(CLASSNAME);
        wsmInst.addProperty(WsmProperty(String("prop3"), val));
        ASSERT_FAULT(
            mapper.convertWsmToCimInstance(wsmInst, NAMESPACE, cimInst),
            "wsman:SchemaValidationError");
    }
}
Exemple #12
0
static void _testValues(void)
{
    WsmToCimRequestMapper mapper((CIMRepository*) 0);

    // Test simple data types
    testSimpleType(Boolean(true));
    testSimpleType(Boolean(false));
    testSimpleType((Sint8)-4);
    testSimpleType((Sint16)-44);
    testSimpleType((Sint32)-444);
    testSimpleType((Sint64)-4444);
    testSimpleType((Uint8)4);
    testSimpleType((Uint16)44);
    testSimpleType((Uint32)444);
    testSimpleType((Uint64)4444);
    testSimpleType(Char16('Z'));
    testSimpleType(Real32(1.5));
    testSimpleType(Real64(55.5));
    testSimpleType(Uint64(123456789));
    testSimpleType(Sint64(-123456789));
    testSimpleType(String("Hello world"));

    // Test special floating point values: NaN, INF, -INF
    WsmValue wsmf1("NaN");
    CIMValue cimf1((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf1, CIMNamespaceName(), cimf1);
    PEGASUS_TEST_ASSERT(cimf1.toString() == PEGASUS_NAN);

    WsmValue wsmf2("INF");
    CIMValue cimf2((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf2, CIMNamespaceName(), cimf2);
    PEGASUS_TEST_ASSERT(cimf2.toString() == PEGASUS_INF);

    WsmValue wsmf3("-INF");
    CIMValue cimf3((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf3, CIMNamespaceName(), cimf3);
    PEGASUS_TEST_ASSERT(cimf3.toString() == PEGASUS_NEG_INF);

    WsmValue wsmd1("NaN");
    CIMValue cimd1((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd1, CIMNamespaceName(), cimd1);
    PEGASUS_TEST_ASSERT(cimd1.toString() == PEGASUS_NAN);

    WsmValue wsmd2("INF");
    CIMValue cimd2((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd2, CIMNamespaceName(), cimd2);
    PEGASUS_TEST_ASSERT(cimd2.toString() == PEGASUS_INF);

    WsmValue wsmd3("-INF");
    CIMValue cimd3((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd3, CIMNamespaceName(), cimd3);
    PEGASUS_TEST_ASSERT(cimd3.toString() == PEGASUS_NEG_INF);

    // Test datetime
    CIMDateTime cimDT;

    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0012345678901234S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.001234:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.12345678901234S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.123456:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055555555S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005555:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.00500000S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005000:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.9999999S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.999999:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.000000:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005500:000"));
    mapper.convertWsmToCimDatetime("PT10H5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000100544.005500:000"));
    mapper.convertWsmToCimDatetime("P10Y", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00003652000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004201000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40D", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004241000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242100000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111220.000000:000"));
    mapper.convertWsmToCimDatetime("PT70M140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000011220.000000:000"));
    mapper.convertWsmToCimDatetime("PT140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000220.000000:000"));
    mapper.convertWsmToCimDatetime("PT5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000544.005500:000"));

    mapper.convertWsmToCimDatetime("2004-12-01", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000"));
    mapper.convertWsmToCimDatetime("2004-12-01Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000"));
    mapper.convertWsmToCimDatetime("2004-12-01+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+120"));
    mapper.convertWsmToCimDatetime("2004-12-01-11:30", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******-690"));

    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012-04:15", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200-255"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+000"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+000"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.00+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000000+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000009+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.000001+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000001+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.1+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.100000+120"));

    mapper.convertWsmToCimDatetime("20041201122334.001200+360", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+360"));


    // Test arrays of simple types
    Array<Sint8> s8_arr;
    s8_arr.append(-11);
    s8_arr.append(-22);
    testArrayType(s8_arr);

    Array<Sint16> s16_arr;
    s16_arr.append(-111);
    s16_arr.append(-222);
    testArrayType(s16_arr);

    Array<Sint32> s32_arr;
    s32_arr.append(-1111);
    s32_arr.append(-2222);
    testArrayType(s32_arr);

    Array<Sint64> s64_arr;
    s64_arr.append(-11111);
    s64_arr.append(-22222);
    testArrayType(s64_arr);

    Array<Uint8> u8_arr;
    u8_arr.append(11);
    u8_arr.append(22);
    testArrayType(u8_arr);

    Array<Uint16> u16_arr;
    u16_arr.append(111);
    u16_arr.append(222);
    testArrayType(u16_arr);

    Array<Uint32> u32_arr;
    u32_arr.append(1111);
    u32_arr.append(2222);
    testArrayType(u32_arr);

    Array<Uint64> u64_arr;
    u64_arr.append(11111);
    u64_arr.append(22222);
    testArrayType(u64_arr);

    Array<Boolean> b_arr;
    b_arr.append(true);
    b_arr.append(false);
    testArrayType(b_arr);

    Array<Real32> r32_arr;
    r32_arr.append(Real32(1.5));
    r32_arr.append(Real32(2.5));
    testArrayType(r32_arr);

    Array<Real64> r64_arr;
    r64_arr.append(Real64(11.5));
    r64_arr.append(Real64(12.5));
    testArrayType(r64_arr);

    Array<Char16> c16_arr;
    c16_arr.append(Char16('Z'));
    c16_arr.append(Char16('X'));
    testArrayType(c16_arr);

    Array<CIMDateTime> dt_arr;
    dt_arr.append(CIMDateTime("19991224120000.000000+360"));
    dt_arr.append(CIMDateTime("20001224120000.000000+360"));
    testArrayType(dt_arr);

    Array<String> str_arr;
    str_arr.append("Test string 1");
    str_arr.append("Test string 2");
    testArrayType(str_arr);

    // Test class URI to class name conversion
    String classURI = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    CIMName cimName = mapper.convertResourceUriToClassName(classURI);
    PEGASUS_TEST_ASSERT(cimName.getString() == "MyClass");
}
Exemple #13
0
/*===========================================================================*/
const bool Main::exec( void )
{
    // GLUT viewer application.
    kvs::glut::Application app( m_argc, m_argv );

    // Parse specified arguments.
    kvsview::OrthoSlice::Argument arg( m_argc, m_argv );
    if( !arg.parse() ) return( false );

    // Create screen.
    kvs::glut::Screen screen( &app );
    screen.setSize( 512, 512 );
    screen.setTitle( kvsview::CommandName + " - " + kvsview::OrthoSlice::CommandName );

    // Check the input point data.
    m_input_name = arg.value<std::string>();
    if ( !kvsview::FileChecker::ImportableStructuredVolume( m_input_name ) &&
         !kvsview::FileChecker::ImportableUnstructuredVolume( m_input_name ) )
    {
        kvsMessageError("%s is not volume data.", m_input_name.c_str());
        return( false );
    }

    // Visualization pipeline.
    kvs::VisualizationPipeline pipe( m_input_name );
    pipe.import();

    // Verbose information.
    if ( arg.verboseMode() )
    {
        std::cout << "IMPORTED OBJECT" << std::endl;
        std::cout << kvsview::ObjectInformation( pipe.object() ) << std::endl;
        std::cout << std::endl;
    }

    // Pointer to the volume object data.
    const kvs::VolumeObjectBase* volume = kvs::VolumeObjectBase::DownCast( pipe.object() );

    // Transfer function.
    const kvs::TransferFunction tfunc = arg.transferFunction( volume );

    // Legend bar.
    kvsview::Widget::LegendBar legend_bar( &screen );
    legend_bar.setColorMap( tfunc.colorMap() );
    if ( !tfunc.hasRange() )
    {
        const kvs::VolumeObjectBase* object = kvs::VolumeObjectBase::DownCast( pipe.object() );
        const kvs::Real32 min_value = static_cast<kvs::Real32>( object->minValue() );
        const kvs::Real32 max_value = static_cast<kvs::Real32>( object->maxValue() );
        legend_bar.setRange( min_value, max_value );
    }
    legend_bar.show();

    // Orientation axis.
    kvsview::Widget::OrientationAxis orientation_axis( &screen );
    orientation_axis.show();

    // Set up the slice plane class.
    kvs::PipelineModule mapper( new kvs::OrthoSlice );
    const float position = arg.hasOption("p") ? arg.position() : pipe.object()->objectCenter().z();
    const kvs::OrthoSlice::AlignedAxis axis( arg.axis() );
    mapper.get<kvs::OrthoSlice>()->setPlane( position, axis );
    mapper.get<kvs::OrthoSlice>()->setTransferFunction( tfunc );
    pipe.connect( mapper );

    // Construct the visualization pipeline.
    if ( !pipe.exec() )
    {
        kvsMessageError("Cannot execute the visulization pipeline.");
        return( false );
    }

    screen.registerObject( &pipe );

    // Disable shading.
    pipe.renderer()->disableShading();

    // Verbose information.
    if ( arg.verboseMode() )
    {
        std::cout << "RENDERERED OBJECT" << std::endl;
        std::cout << kvsview::ObjectInformation( pipe.object() ) << std::endl;
        std::cout << std::endl;
        std::cout << "VISUALIZATION PIPELINE" << std::endl;
        std::cout << pipe << std::endl;
    }

    // Apply the specified parameters to the global and the visualization pipeline.
    arg.applyTo( screen, pipe );
    arg.applyTo( screen );

    // Show the screen.
    screen.show();

    // Create a plane slider.
    kvsview::OrthoSlice::PlaneSlider slider( &screen );
    slider.setMargin( 10 );
    slider.setCaption("Slice");
    slider.setVolumeObject( volume );
    slider.setTransferFunction( tfunc );
    slider.setAxis( axis );
    slider.setValue( position );
    slider.setRange( volume->minObjectCoord()[axis], volume->maxObjectCoord()[axis] );
    slider.show();

    return( arg.clear(), app.run() );
}
		whitelist_static_app::whitelist_static_app(cppcms::service &srv, const fs::path& folder, const value& whitelist, const hash_function_t hash_function) 
			: base_app(srv), whitelist_(whitelist), hash_function_(hash_function), folder_(folder)
		{
			mapper().assign("");
		}
void RectObject::renderOnto(RenderedImage &image) {
	CoordinateMapper mapper(image);
	
	image.painter().drawRect(mapper.dataToPixel(bound()).toQRect());
}
Exemple #16
0
void test_sectionalize(std::string const& caseid, G const& g, std::size_t section_count,
        std::string const& index_check, std::string const& dir_check,
        std::size_t max_count = 10)
{
    boost::ignore_unused_variable_warning(caseid);

    static const std::size_t dimension_count = boost::mpl::size<DimensionVector>::value;


    typedef typename bg::point_type<G>::type point;
    typedef bg::model::box<point> box;
    typedef bg::sections<box, dimension_count> sections;

    sections s;
    bg::sectionalize<Reverse, DimensionVector>(g,
            bg::detail::no_rescale_policy(), s, 0, max_count);

    BOOST_CHECK_EQUAL(s.size(), section_count);

    // Check if sections are consecutive and consistent
    int previous_index = -1;
    BOOST_FOREACH(typename sections::value_type const& sec, s)
    {
        if (sec.begin_index > 0)
        {
            BOOST_CHECK_EQUAL(previous_index, sec.begin_index);
        }
        BOOST_CHECK_EQUAL(int(sec.count), int(sec.end_index - sec.begin_index));
        previous_index = sec.end_index;
    }

    // Output streams for sections, boxes, other
    std::ostringstream out_sections;
    std::ostringstream out_boxes;
    std::ostringstream out_dirs;


    for (typename sections::size_type i = 0; i < s.size(); i++)
    {
        box const& b = s[i].bounding_box;

        if (i > 0)
        {
            out_sections << "|";
            out_dirs << "|";
            out_boxes << "|";
        }

        out_sections << s[i].begin_index << ".." << s[i].end_index;
        out_boxes << bg::get<0,0>(b) << " " << bg::get<0,1>(b)
            << ".." << bg::get<1,0>(b) << " " << bg::get<1,1>(b);
        for (std::size_t d = 0; d < dimension_count; d++)
        {
            out_dirs << (d == 0 ? "" : " ");
            switch(s[i].directions[d])
            {
                case -99: out_dirs << "DUP"; break;
                case -1 : out_dirs << "-"; break;
                case  0 : out_dirs << "."; break;
                case +1 : out_dirs << "+"; break;
            }
        }
    }

    if (! index_check.empty())
    {
        BOOST_CHECK_EQUAL(out_sections.str(), index_check);
    }
    if (! dir_check.empty())
    {
        BOOST_CHECK_EQUAL(out_dirs.str(), dir_check);
    }

#if defined(TEST_WITH_SVG)
    {
        std::ostringstream filename;
        filename << "sectionalize_"
            << caseid << ".svg";

        std::ofstream svg(filename.str().c_str());

        typedef typename bg::point_type<G>::type point_type;
        bg::svg_mapper<point_type> mapper(svg, 500, 500);

        mapper.add(g);

        static const bool is_line = bg::geometry_id<G>::type::value == 2;
        mapper.map(g, is_line
            ? "opacity:0.6;stroke:rgb(0,0,255);stroke-width:5"
            : "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:0.5");


        for (typename sections::size_type i = 0; i < s.size(); i++)
        {
            box b = s[i].bounding_box;
            bg::buffer(b, b, 0.01);
            mapper.map(b, s[i].duplicate
                ? "fill-opacity:0.4;stroke-opacity:0.6;fill:rgb(0,128,0);stroke:rgb(0,255,0);stroke-width:2.0"
                : "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);stroke:rgb(255,0,0);stroke-width:0.5");

            std::ostringstream out;

            for (int d = 0; d < dimension_count; d++)
            {
                out << (d == 0 ? "[" : " ");
                switch(s[i].directions[d])
                {
                    case -99: out << "DUP"; break;
                    case -1 : out << "-"; break;
                    case  0 : out << "."; break;
                    case +1 : out << "+"; break;
                }
            }
            out << "] " << s[i].begin_index << ".." << s[i].end_index;


            point_type p;
            bg::centroid(b, p);
            mapper.text(p, out.str(), "");
        }
    }
#endif

}
static bool test_overlay_p_q(std::string const& caseid, G1 const& p, G2 const& q, bool svg, double tolerance)
{
    bool result = true;

    typedef typename boost::geometry::coordinate_type<G1>::type coordinate_type;
    typedef typename boost::geometry::point_type<G1>::type point_type;
    typedef boost::geometry::detail::intersection::intersection_point<point_type> ip_type;

    typedef boost::geometry::strategy_intersection
        <
            typename boost::geometry::cs_tag<point_type>::type,
            G1,
            G2,
            ip_type,
            CalculationType
        > strategy;

    std::vector<OutputType> out_i, out_u;

    CalculationType area_p = boost::geometry::area(p);
    CalculationType area_q = boost::geometry::area(q);

    CalculationType area_i = 0;
    CalculationType area_u = 0;

    boost::geometry::intersection_inserter<OutputType>(p, q, std::back_inserter(out_i), strategy());
    for (typename std::vector<OutputType>::iterator it = out_i.begin();
            it != out_i.end();
            ++it)
    {
        area_i += boost::geometry::area(*it);
    }
    boost::geometry::union_inserter<OutputType>(p, q, std::back_inserter(out_u), strategy());
    for (typename std::vector<OutputType>::iterator it = out_u.begin();
            it != out_u.end();
            ++it)
    {
        area_u += boost::geometry::area(*it);
    }

    double diff = (area_p + area_q) - area_u - area_i;
    if (std::abs(diff) > tolerance
        // for creating SVG-selection: || area_i > 2.0e+006
        )
    {
        result = false;
        svg = true;

        std::cout
            << "type: " << string_from_type<CalculationType>::name()
            << " id: " << caseid
            << " area i: " << area_i
            << " area u: " << area_u
            << " area p: " << area_p
            << " area q: " << area_q
            << " diff: " << diff
            << std::endl
            << std::setprecision(20)
            << " p: " << boost::geometry::wkt(p) << std::endl
            << " q: " << boost::geometry::wkt(q) << std::endl
            ;

    }


    if(svg)
    {
        std::ostringstream filename;
        filename << "overlay_" << caseid << "_"
            << string_from_type<coordinate_type>::name()
            << string_from_type<CalculationType>::name()
            << ".svg";

        std::ofstream svg(filename.str().c_str());

        boost::geometry::svg_mapper<point_type> mapper(svg, 500, 500);

        mapper.add(p);
        mapper.add(q);

        mapper.map(p, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");
        mapper.map(q, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");

        for (typename std::vector<OutputType>::const_iterator it = out_i.begin();
                it != out_i.end(); ++it)
        {
            mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:3");
        }
        for (typename std::vector<OutputType>::const_iterator it = out_u.begin();
                it != out_u.end(); ++it)
        {
            mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,255);stroke-width:3");
        }
    }
    return result;
}
Exemple #18
0
// map a x-value float to the plot object
uint16_t Plotter::getScreenX(float x) {
	if (x < xMin) { return xo; }
	if (x > xMax) { return xo + width; }
	return (uint16_t)mapper(x, xMin, xMax, xo, xo + width);
}
Exemple #19
0
 size_t map(T& val, const char* base_address, uint64_t flags = 0, const char* friendly_name = "<TOP>")
 {
     detail::map_visitor mapper(base_address, flags);
     mapper(val, friendly_name);
     return mapper.bytes_read();
 }
Exemple #20
0
// map a y-value float to the plot object
uint16_t Plotter::getScreenY(float y) {
	if (y < yMin) { return yo; }
	if (y > yMax) { return yo+height; }
	return (uint16_t)round(mapper(y, yMin, yMax, yo + height, yo));
}
Exemple #21
0
flat_thread::flat_thread(cppcms::service &s) : thread_shared(s)
{
	dispatcher().assign(".*",&flat_thread::prepare,this,0);
	mapper().assign("{1}");
}
void test_union(std::string const& caseid, G1 const& g1, G2 const& g2,
        std::size_t expected_count, std::size_t expected_hole_count,
        int expected_point_count, double expected_area,
        double percentage)
{
    typedef typename bg::coordinate_type<G1>::type coordinate_type;
    std::vector<OutputType> clip;
    bg::union_(g1, g2, clip);

    typename bg::default_area_result<G1>::type area = 0;
    std::size_t n = 0;
    std::size_t holes = 0;
    for (typename std::vector<OutputType>::iterator it = clip.begin();
            it != clip.end(); ++it)
    {
        area += bg::area(*it);
        holes += bg::num_interior_rings(*it);
        n += bg::num_points(*it, true);
    }

    {
        // Test inserter functionality
        // Test if inserter returns output-iterator (using Boost.Range copy)
        std::vector<OutputType> inserted, array_with_one_empty_geometry;
        array_with_one_empty_geometry.push_back(OutputType());
        boost::copy(array_with_one_empty_geometry, bg::detail::union_::union_insert<OutputType>(g1, g2, std::back_inserter(inserted)));

        typename bg::default_area_result<G1>::type area_inserted = 0;
        int index = 0;
        for (typename std::vector<OutputType>::iterator it = inserted.begin();
                it != inserted.end();
                ++it, ++index)
        {
            // Skip the empty polygon created above to avoid the empty_input_exception
            if (bg::num_points(*it) > 0)
            {
                area_inserted += bg::area(*it);
            }
        }
        BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1);
        BOOST_CHECK_CLOSE(area_inserted, expected_area, percentage);
    }



    /***
    std::cout << "case: " << caseid
        << " n: " << n
        << " area: " << area
        << " polygons: " << boost::size(clip)
        << " holes: " << holes
        << std::endl;
    ***/

    if (expected_point_count >= 0)
    {
        BOOST_CHECK_MESSAGE(n == std::size_t(expected_point_count),
                "union: " << caseid
                << " #points expected: " << expected_point_count
                << " detected: " << n
                << " type: " << (type_for_assert_message<G1, G2>())
                );
    }

    BOOST_CHECK_EQUAL(clip.size(), expected_count);
    BOOST_CHECK_EQUAL(holes, expected_hole_count);
    BOOST_CHECK_CLOSE(area, expected_area, percentage);

#if defined(TEST_WITH_SVG)
    {
        bool const ccw =
            bg::point_order<G1>::value == bg::counterclockwise
            || bg::point_order<G2>::value == bg::counterclockwise;
        bool const open =
            bg::closure<G1>::value == bg::open
            || bg::closure<G2>::value == bg::open;

        std::ostringstream filename;
        filename << "union_"
            << caseid << "_"
            << string_from_type<coordinate_type>::name()
            << (ccw ? "_ccw" : "")
            << (open ? "_open" : "")
            << ".svg";

        std::ofstream svg(filename.str().c_str());

        bg::svg_mapper
            <
                typename bg::point_type<G2>::type
            > mapper(svg, 500, 500);
        mapper.add(g1);
        mapper.add(g2);

        mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);"
                "stroke:rgb(153,204,0);stroke-width:3");
        mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);"
                "stroke:rgb(51,51,153);stroke-width:3");
        //mapper.map(g1, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1");
        //mapper.map(g2, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1");

        for (typename std::vector<OutputType>::const_iterator it = clip.begin();
                it != clip.end(); ++it)
        {
            mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);"
                    "stroke:rgb(255,0,255);stroke-width:8");
            //mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5");
        }
    }
#endif
}
Exemple #23
0
forums::forums(cppcms::service &srv) : master(srv)
{
	mapper().assign("{1}"); // with id
	mapper().assign("");    // default
	dispatcher().assign(".*",&forums::prepare,this,0);
}
typename bg::default_area_result<G1>::type test_intersection(std::string const& caseid,
        G1 const& g1, G2 const& g2,
        std::size_t expected_count = 0, int expected_point_count = 0,
        double expected_length_or_area = 0,
        double percentage = 0.0001,
        bool debug = false)
{
    bool const is_line = bg::geometry_id<OutputType>::type::value == 2;

    if (debug)
    {
        std::cout << std::endl << "case " << caseid << std::endl;
    }


    typedef typename bg::coordinate_type<G1>::type coordinate_type;
    typedef typename bg::point_type<G1>::type point_type;

    typedef bg::strategy_intersection
        <
            typename bg::cs_tag<point_type>::type,
            G1,
            G2,
            point_type,
            CalculationType
        > strategy;

    // Check both normal behaviour, and _inserter behaviour
    if (! debug)
    {
        std::vector<OutputType> out;
        bg::intersection(g1, g2, out);
    }
    std::vector<OutputType> clip;
    bg::detail::intersection::intersection_insert<OutputType>(g1, g2, std::back_inserter(clip), strategy());


    typename bg::default_area_result<G1>::type length_or_area = 0;
    int n = 0;
    for (typename std::vector<OutputType>::iterator it = clip.begin();
            it != clip.end();
            ++it)
    {
        if (expected_point_count > 0)
        {
            n += bg::num_points(*it, true);
        }

        // instead of specialization we check it run-time here
        length_or_area += is_line 
            ? bg::length(*it)
            : bg::area(*it);

        if (debug)
        {
            std::cout << std::setprecision(20) << bg::wkt(*it) << std::endl;
        }
    }


#if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST)
    if (expected_point_count > 0)
    {
        BOOST_CHECK_MESSAGE(bg::math::abs(n - expected_point_count) < 3,
                "intersection: " << caseid
                << " #points expected: " << expected_point_count
                << " detected: " << n
                << " type: " << (type_for_assert_message<G1, G2>())
                );
    }

    if (expected_count > 0)
    {
        BOOST_CHECK_MESSAGE(clip.size() == expected_count,
                "intersection: " << caseid
                << " #outputs expected: " << expected_count
                << " detected: " << clip.size()
                << " type: " << (type_for_assert_message<G1, G2>())
                );
    }

    double const detected_length_or_area = boost::numeric_cast<double>(length_or_area);
    BOOST_CHECK_CLOSE(detected_length_or_area, expected_length_or_area, percentage);
#endif


#if defined(TEST_WITH_SVG)
    {
        bool const ccw =
            bg::point_order<G1>::value == bg::counterclockwise
            || bg::point_order<G2>::value == bg::counterclockwise;
        bool const open =
            bg::closure<G1>::value == bg::open
            || bg::closure<G2>::value == bg::open;

        std::ostringstream filename;
        filename << "intersection_"
            << caseid << "_"
            << string_from_type<coordinate_type>::name()
            << string_from_type<CalculationType>::name()
            << (ccw ? "_ccw" : "")
            << (open ? "_open" : "")
            << ".svg";

        std::ofstream svg(filename.str().c_str());

        bg::svg_mapper<point_type> mapper(svg, 500, 500);

        mapper.add(g1);
        mapper.add(g2);

        mapper.map(g1, is_line
            ? "opacity:0.6;stroke:rgb(0,255,0);stroke-width:5"
            : "fill-opacity:0.5;fill:rgb(153,204,0);"
                    "stroke:rgb(153,204,0);stroke-width:3");
        mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);"
                    "stroke:rgb(51,51,153);stroke-width:3");

        for (typename std::vector<OutputType>::const_iterator it = clip.begin();
                it != clip.end(); ++it)
        {
            mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);"
                        "stroke:rgb(255,0,255);stroke-width:8");
        }
    }
#endif

    if (debug)
    {
        std::cout << "end case " << caseid << std::endl;
    }

    return length_or_area;
}
Exemple #25
0
InputSettingsWindow::InputSettingsWindow() {
  activeInput = 0;

  layout = new QVBoxLayout;
  layout->setMargin(Style::WindowMargin);
  layout->setSpacing(Style::WidgetSpacing);
  setLayout(layout);

  list = new QTreeWidget;
  list->setColumnCount(2);
  list->setAllColumnsShowFocus(true);
  list->setSortingEnabled(false);
  list->header()->hide();
  list->header()->setResizeMode(QHeaderView::ResizeToContents);
  layout->addWidget(list);

  controlLayout = new QHBoxLayout;
  layout->addLayout(controlLayout);

  message = new QLabel;
  message->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  controlLayout->addWidget(message);

  optionButton = new QPushButton("Options");
  controlLayout->addWidget(optionButton);

  optionMenu = new QMenu;
  optionButton->setMenu(optionMenu);

  optionAssignModifiers = new QbCheckAction("Assign Modifiers as Keys", 0);
  optionMenu->addAction(optionAssignModifiers);

  assignButton = new QPushButton("Assign");
  controlLayout->addWidget(assignButton);

  unassignButton = new QPushButton("Unassign");
  controlLayout->addWidget(unassignButton);

  connect(list, SIGNAL(itemSelectionChanged()), this, SLOT(synchronize()));
  connect(list, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(assign()));
  connect(assignButton, SIGNAL(released()), this, SLOT(assign()));
  connect(unassignButton, SIGNAL(released()), this, SLOT(unassign()));

  connect(optionAssignModifiers, SIGNAL(triggered()), this, SLOT(toggleAssignModifiers()));

  //initialize list

  port1 = new QTreeWidgetItem(list);
  port1->setData(0, Qt::UserRole, QVariant(-1));
  port1->setText(0, "Controller Port 1");

  port2 = new QTreeWidgetItem(list);
  port2->setData(0, Qt::UserRole, QVariant(-1));
  port2->setText(0, "Controller Port 2");

  userInterface = new QTreeWidgetItem(list);
  userInterface->setData(0, Qt::UserRole, QVariant(-1));
  userInterface->setText(0, "User Interface");

  for(unsigned i = 0; i < mapper().size(); i++) {
    InputGroup &group = *(mapper()[i]);

    QTreeWidgetItem *grandparent = 0;
    if(group.category == InputCategory::Port1) { grandparent = port1; }
    if(group.category == InputCategory::Port2) { grandparent = port2; }
    if(group.category == InputCategory::UserInterface) { grandparent = userInterface; }
    if(!grandparent) continue;

    QTreeWidgetItem *parent = new QTreeWidgetItem(grandparent);
    parent->setData(0, Qt::UserRole, QVariant(-1));
    parent->setText(0, group.label);

    for(unsigned i = 0; i < group.size(); i++) {
      QTreeWidgetItem *child = new QTreeWidgetItem(parent);
      child->setData(0, Qt::UserRole, QVariant(inputTable.size()));
      inputTable.add(group[i]);
    }
  }

  updateList();
  synchronize();
}
Exemple #26
0
void Session::validateMessage(NetworkMessage m)
{
    if(validator().validate(m))
        mapper().map(m);
}
double test_growth(Geometry const& geometry, int n, int d, double distance)
{
    namespace bg = boost::geometry;

    typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
    typedef typename bg::point_type<Geometry>::type point_type;

    // extern int point_buffer_count;
    std::ostringstream complete;
    complete
        << "point" << "_"
        << "growth" << "_"
        << string_from_type<coordinate_type>::name()
        << "_" << "r"
        << "_" << n
        << "_" << d
         // << "_" << point_buffer_count
        ;

    //std::cout << complete.str() << std::endl;

    std::ostringstream filename;
    filename << "buffer_" << complete.str() << ".svg";

    std::ofstream svg(filename.str().c_str());

#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
    bg::svg_mapper<point_type> mapper(svg, 500, 500);

    {
        bg::model::box<point_type> box;
        bg::envelope(geometry, box);

        bg::buffer(box, box, distance * 1.01);
        mapper.add(box);
    }
#endif

    JoinStrategy
        <
            point_type,
            typename bg::point_type<GeometryOut>::type
        > join_strategy;
    EndStrategy
        <
            point_type,
            typename bg::point_type<GeometryOut>::type
        > end_strategy;

    typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type;
    distance_strategy_type distance_strategy(distance);

    std::vector<GeometryOut> buffered;

    typedef typename bg::rescale_policy_type<point_type>::type
        rescale_policy_type;
    rescale_policy_type rescale_policy
            = bg::get_rescale_policy<rescale_policy_type>(geometry);

    bg::detail::buffer::buffer_inserter<GeometryOut>(geometry,
                        std::back_inserter(buffered),
                        distance_strategy, 
                        join_strategy,
                        end_strategy,
                        rescale_policy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
                        , mapper
#endif
                                );

    typename bg::default_area_result<GeometryOut>::type area = 0;
    BOOST_FOREACH(GeometryOut const& polygon, buffered)
    {
        area += bg::area(polygon);
    }
Exemple #28
0
void test_traverse(std::string const& caseid, G1 const& g1, G2 const& g2)
{
    typedef bg::detail::intersection::intersection_point
        <typename bg::point_type<G2>::type> ip;
    typedef typename boost::range_const_iterator<std::vector<ip> >::type iterator;
    typedef std::vector<ip> ip_vector;
    ip_vector ips;

    typedef typename bg::strategy::side::services::default_strategy
            <
                typename bg::cs_tag<G1>::type
            >::type strategy_type;


    typedef bg::detail::overlay::traversal_turn_info
        <
            typename bg::point_type<G2>::type
        > turn_info;
    typedef typename boost::range_iterator<const std::vector<turn_info> >::type iterator;
    std::vector<turn_info> ips;

    bg::get_turns<false, false, bg::detail::overlay::assign_null_policy>(g1, g2, ips);
    bg::enrich_intersection_points(ips, g1, g2, strategy_type());

    typedef bg::model::ring<typename bg::point_type<G2>::type> ring_type;
    typedef std::vector<ring_type> out_vector;
    out_vector v;



    bg::traverse
        <
            strategy_type,
            ring_type
        >
        (
            g1, g2, -1, ips, std::back_inserter(v)
        );



#if defined(TEST_WITH_SVG)
    {
        std::ostringstream filename;
        filename << "intersection_" << caseid << ".svg";

        std::ofstream svg(filename.str().c_str());

        // Trick to have this always LongDouble
        //typedef bg::model::d2::point_xy<long double> P;
        typedef typename bg::point_type<G1>::type P;
        //typename bg::replace_point_type<G1, P>::type rg1;
        //typename bg::replace_point_type<G2, P>::type rg2;

        bg::svg_mapper<P> mapper(svg, 1000, 800);

        mapper.add(g1);
        mapper.add(g2);

        // Input shapes in green/blue
        mapper.map(g1, "opacity:0.8;fill:rgb(0,255,0);"
                "stroke:rgb(0,0,0);stroke-width:1");
        mapper.map(g2, "opacity:0.8;fill:rgb(0,0,255);"
                "stroke:rgb(0,0,0);stroke-width:1");

        // Traversal rings in red
        for (typename out_vector::const_iterator it = boost::begin(v);
            it != boost::end(v);
            ++it)
        {
            mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.9;"
                "fill:rgb(255,0,0);stroke:rgb(255,0,0);stroke-width:5");

            std::cout << bg::wkt(*it) << std::endl;
            std::cout << bg::area(*it) << std::endl;
        }

        // IP's in orange
        for (iterator it = boost::begin(ips); it != boost::end(ips); ++it)
        {
            mapper.map(it->point, "fill:rgb(255,128,0);"
                    "stroke:rgb(0,0,100);stroke-width:1");
        }
    }
#endif
}
	/*}}}*/
};
int
xchar_length (xchar_t ch) /*{{{*/
{
	return utf8_length_tab[ch];
}/*}}}*/
int
xchar_strict_length (xchar_t ch) /*{{{*/
{
	return utf8_strict_length_tab[ch];
}/*}}}*/
int
xchar_valid_position (const xchar_t *s, int length) /*{{{*/
{
# define	VALID(ccc)	(((ccc) & 0xc0) == 0x80)
	int	len, n;
	
	if (((len = xchar_strict_length (*s)) > 0) && (length >= len))
		for (n = len; n > 1; ) {
			--n;
			if (! VALID (*(s + n))) {
				len = -1;
				break;
			}
		}
	else
		len = -1;
	return len;
# undef		VALID	
}/*}}}*/
bool_t
xchar_valid (const xchar_t *s, int length) /*{{{*/
{
	int	n;
	
	while (length > 0)
		if ((n = xchar_valid_position (s, length)) > 0) {
			s += n;
			length -= n;
		} else
			break;
	return length == 0 ? true : false;
}/*}}}*/
const char *
xchar_to_char (const xchar_t *s) /*{{{*/
{
	return (const char *) s;
}/*}}}*/
const xchar_t *
char_2_xchar (const char *s) /*{{{*/
{
	return (const xchar_t *) s;
}/*}}}*/
const char *
byte_to_char (const byte_t *b) /*{{{*/
{
	return (const char *) b;
}/*}}}*/
int
xstrlen (const xchar_t *s) /*{{{*/
{
	int	len, clen;
	
	for (len = 0; *s; ++len) {
		clen = xchar_length (*s);
		while ((clen-- > 0) && *s)
			++s;
	}
	return len;
}/*}}}*/
int
xstrcmp (const xchar_t *s1, const char *s2) /*{{{*/
{
	return strcmp (xchar_to_char (s1), s2);
}/*}}}*/
int
xstrncmp (const xchar_t *s1, const char *s2, size_t n) /*{{{*/
{
	return strncmp (xchar_to_char (s1), s2, n);
}/*}}}*/
bool_t
xmlbuf_equal (xmlbuf_t *b1, xmlbuf_t *b2) /*{{{*/
{
	if ((! b1) && (! b2))
		return true;
	if (b1 && b2 && (b1 -> length == b2 -> length) &&
	    ((! b1 -> length) || (! memcmp (b1 -> buffer, b2 -> buffer, b1 -> length))))
		return true;
	return false;
}/*}}}*/
char *
xmlbuf_to_string (xmlbuf_t *b) /*{{{*/
{
	return buffer_copystring ((buffer_t *) b);
}/*}}}*/
long
xmlbuf_to_long (xmlbuf_t *b) /*{{{*/
{
	const char	*s = b ? buffer_string (b) : NULL;

	return s ? strtol (s, NULL, 0) : -1;
}/*}}}*/

static inline unsigned long
mkcp (const xchar_t *s, int *len) /*{{{*/
{
	unsigned long	cp;
	int		n;
	
	*len = xchar_length (*s);
	for (n = 0, cp = 0; n < *len; ++n) {
		cp <<= 8;
		cp |= s[n];
	}
	return cp;
}/*}}}*/
static inline const utfmap_t *
mapfind (const xchar_t *s, int *len, const utfmap_t *map, int msize) /*{{{*/
{
	unsigned long	cp;
	int		low, high, pos;
	int		dummy;

	cp = mkcp (s, len ? len : & dummy);
	for (low = 0, high = msize; low < high; ) {
		pos = (low + high) >> 1;
		if (map[pos].cp == cp)
			return & map[pos];
		else if (map[pos].cp < cp)
			low = pos + 1;
		else
			high = pos;
	}
	return NULL;
}/*}}}*/
static inline bool_t
isword (const xchar_t *s) /*{{{*/
{
	unsigned long	cp;
	int		len;
	
	cp = mkcp (s, & len);
	if (len == 1)
		return isalnum (s[0]) ? true : false;
	else {
		int	low, high, pos;
		
		for (low = 0, high = is_word_length; low < high;) {
			pos = (low + high) >> 1;
			if (is_word[pos] == cp)
				return true;
			if (is_word[pos] < cp)
				low = pos + 1;
			else
				high = pos;
		}
	}
	return false;
}/*}}}*/
static inline const xchar_t *
mapper (const utfmap_t *map, int msize, const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	const utfmap_t	*m = mapfind (s, slen, map, msize);
	
	if (m) {
		if (olen)
			*olen = m -> dlen;
		return m -> dst;
	}
	return NULL;
}/*}}}*/
const xchar_t *
xtolower (const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	return mapper (utflower, utflower_length, s, slen, olen);
}/*}}}*/
const xchar_t *
xtoupper (const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	return mapper (utfupper, utfupper_length, s, slen, olen);
}/*}}}*/
const xchar_t *
xtotitle (const xchar_t *s, int *slen, int *olen) /*{{{*/
{
	return mapper (utftitle, utftitle_length, s, slen, olen);
}/*}}}*/
Exemple #30
0
typename bg::default_area_result<G1>::type test_intersection(std::string const& caseid,
        G1 const& g1, G2 const& g2,
        std::size_t expected_count = 0, int expected_point_count = 0,
        double expected_length_or_area = 0,
        double percentage = 0.0001,
        bool debug = false)
{
    if (debug)
    {
        std::cout << std::endl << "case " << caseid << std::endl;
    }

    typedef typename bg::point_type<G1>::type point_type;

    if (! debug)
    {
        // Check _inserter behaviour with stratey
        typedef bg::strategy_intersection
            <
                typename bg::cs_tag<point_type>::type,
                G1,
                G2,
                point_type,
                typename bg::rescale_policy_type<point_type>::type,
                CalculationType
            > strategy;
        std::vector<OutputType> clip;
        bg::detail::intersection::intersection_insert<OutputType>(g1, g2, std::back_inserter(clip), strategy());
    }

    typename bg::default_area_result<G1>::type length_or_area = 0;

    // Check normal behaviour
    std::vector<OutputType> intersection_output;
    bg::intersection(g1, g2, intersection_output);

    check_result<G1, G2>(intersection_output, caseid, expected_count, expected_point_count,
        expected_length_or_area, percentage, debug);

    // Check variant behaviour
    intersection_output.clear();
    bg::intersection(boost::variant<G1>(g1), g2, intersection_output);

    check_result<G1, G2>(intersection_output, caseid, expected_count, expected_point_count,
        expected_length_or_area, percentage, debug);

    intersection_output.clear();
    bg::intersection(g1, boost::variant<G2>(g2), intersection_output);

    check_result<G1, G2>(intersection_output, caseid, expected_count, expected_point_count,
        expected_length_or_area, percentage, debug);

    intersection_output.clear();
    bg::intersection(boost::variant<G1>(g1), boost::variant<G2>(g2), intersection_output);

    check_result<G1, G2>(intersection_output, caseid, expected_count, expected_point_count,
        expected_length_or_area, percentage, debug);

#if defined(TEST_WITH_SVG)
    {
        bool const is_line = bg::geometry_id<OutputType>::type::value == 2;
        typedef typename bg::coordinate_type<G1>::type coordinate_type;

        bool const ccw =
            bg::point_order<G1>::value == bg::counterclockwise
            || bg::point_order<G2>::value == bg::counterclockwise;
        bool const open =
            bg::closure<G1>::value == bg::open
            || bg::closure<G2>::value == bg::open;

        std::ostringstream filename;
        filename << "intersection_"
            << caseid << "_"
            << string_from_type<coordinate_type>::name()
            << string_from_type<CalculationType>::name()
            << (ccw ? "_ccw" : "")
            << (open ? "_open" : "")
#if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
            << "_no_rob"
#endif
            << ".svg";

        std::ofstream svg(filename.str().c_str());

        bg::svg_mapper<point_type> mapper(svg, 500, 500);

        mapper.add(g1);
        mapper.add(g2);

        mapper.map(g1, is_line
            ? "opacity:0.6;stroke:rgb(0,255,0);stroke-width:5"
            : "fill-opacity:0.5;fill:rgb(153,204,0);"
                    "stroke:rgb(153,204,0);stroke-width:3");
        mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);"
                    "stroke:rgb(51,51,153);stroke-width:3");

        for (typename std::vector<OutputType>::const_iterator it = intersection_output.begin();
                it != intersection_output.end(); ++it)
        {
            mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);"
                        "stroke:rgb(255,0,255);stroke-width:8");
        }
    }
#endif


    if (debug)
    {
        std::cout << "end case " << caseid << std::endl;
    }

    return length_or_area;
}