Example #1
0
ErrorCode MeshTag::get_data(const SequenceManager*,
                            Error* /* error */,
                            const EntityHandle* entities,
                            size_t num_entities,
                            const void** data_ptrs,
                            int* data_lengths) const
{
  const void* ptr;
  int len;

  if (!mValue.empty()) {
    ptr = &mValue[0];
    len = mValue.size();
  }
  else if (get_default_value()) {
    ptr = get_default_value();
    len = get_default_value_size();
  }
  else {
    return not_found(get_name());
  }

  for (size_t i = 0; i < num_entities; ++i) {
    if (entities[i])
      return not_root_set(get_name(), entities[i]); // Not root set
    data_ptrs[i] = ptr;
    if (data_lengths)
      data_lengths[i] = len;
  }

  return MB_SUCCESS;
}
Example #2
0
ErrorCode DenseTag::get_data( const SequenceManager* seqman,
                              Error* error,
                              const EntityHandle* entities,
                              size_t num_entities,
                              const void** pointers,
                              int* data_lengths ) const
{
  ErrorCode result;
  const EntityHandle *const end = entities + num_entities;
  size_t junk;
  const unsigned char* ptr = NULL; // initialize to get rid of warning

  if (data_lengths) {
    const int len = get_size();
    SysUtil::setmem( data_lengths, &len, sizeof(int), num_entities );
  }

  for (const EntityHandle* i = entities; i != end; ++i, ++pointers) {
    result = get_array( seqman, error, *i, ptr, junk );
    if (MB_SUCCESS != result)
      return result;
  
    if (ptr)
      *pointers = ptr;
    else if (get_default_value())
      *pointers = get_default_value();
    else
      return not_found( error, get_name(), *i );
  }
  
  return MB_SUCCESS;
}
Example #3
0
ErrorCode DenseTag::get_data( const SequenceManager* seqman,
                              Error* error,
                              const Range& entities,
                              void* values ) const
{
  ErrorCode rval;
  size_t avail;
  const unsigned char* array = NULL; // initialize to get rid of warning
  unsigned char* data = reinterpret_cast<unsigned char*>(values);

  for (Range::const_pair_iterator p = entities.const_pair_begin(); 
       p != entities.const_pair_end(); ++p) {
       
    EntityHandle start = p->first;
    while (start <= p->second) {
      rval = get_array( seqman, error, start, array, avail );
      if (MB_SUCCESS != rval)
        return rval;
      
      const size_t count = std::min<size_t>(p->second - start + 1, avail);
      if (array) 
        memcpy( data, array, get_size() * count );
      else if (get_default_value())
        SysUtil::setmem( data, get_default_value(), get_size(), count );
      else
        return not_found( error, get_name(), start );
      
      data += get_size() * count;
      start += count;
    }
  }
  
  return MB_SUCCESS;
}
Example #4
0
ErrorCode DenseTag::get_data( const SequenceManager* seqman,
                              Error* error,
                              const EntityHandle* entities,
                              size_t num_entities,
                              void* adata ) const
{
  size_t junk;
  unsigned char* ptr = reinterpret_cast<unsigned char*>(adata);
  const EntityHandle *const end = entities + num_entities;
  for (const EntityHandle* i = entities; i != end; ++i, ptr += get_size()) {
    const unsigned char* data = 0;
    ErrorCode rval = get_array( seqman, error, *i, data, junk );
    if (MB_SUCCESS != rval)
      return rval;
       
    if (data)
      memcpy( ptr, data, get_size() );
    else if (get_default_value())
      memcpy( ptr, get_default_value(), get_size() );
    else
     return not_found( error, get_name(), *i );
  }

  return MB_SUCCESS;
}
Example #5
0
ErrorCode MeshTag::get_data(const SequenceManager*,
                            Error* /* error */,
                            const EntityHandle* entities,
                            size_t num_entities,
                            void* data) const
{
  if (!all_root_set(get_name(), entities, num_entities))
    return MB_TAG_NOT_FOUND;

  const void* ptr;
  int len;

  if (!mValue.empty()) {
    ptr = &mValue[0];
    len = mValue.size();
  }
  else if (get_default_value()) {
    ptr = get_default_value();
    len = get_default_value_size();
  }
  else {
    return not_found(get_name());
  }

  SysUtil::setmem(data, ptr, len, num_entities);
  return MB_SUCCESS;
}
Example #6
0
// Load the variable from EEPROM, if supported
//
bool AP_Param::load(void)
{
    uint32_t group_element = 0;
    const struct GroupInfo *ginfo;
    uint8_t idx;
    const struct AP_Param::Info *info = find_var_info(&group_element, &ginfo, &idx);
    if (info == NULL) {
        // we don't have any info on how to load it
        return false;
    }

    struct Param_header phdr;

    // create the header we will use to match the variable
    if (ginfo != NULL) {
        phdr.type = PGM_UINT8(&ginfo->type);
    } else {
        phdr.type = PGM_UINT8(&info->type);
    }
    phdr.key  = PGM_UINT8(&info->key);
    phdr.group_element = group_element;

    // scan EEPROM to find the right location
    uint16_t ofs;
    if (!scan(&phdr, &ofs)) {
        // if the value isn't stored in EEPROM then set the default value
        if (ginfo != NULL) {
            uintptr_t base = PGM_POINTER(&info->ptr);
            set_value((enum ap_var_type)phdr.type, (void*)(base + PGM_UINT16(&ginfo->offset)),
                      get_default_value(&ginfo->def_value));
        } else {
            set_value((enum ap_var_type)phdr.type, (void*)PGM_POINTER(&info->ptr), 
                      get_default_value(&info->def_value));
        }
        return false;
    }

    if (phdr.type != AP_PARAM_VECTOR3F && idx != 0) {
        // only vector3f can have non-zero idx for now
        return false;
    }

    AP_Param *ap;
    ap = this;
    if (idx != 0) {
        ap = (AP_Param *)((uintptr_t)ap) - (idx*sizeof(float));
    }

    // found it
    _storage.read_block(ap, ofs+sizeof(phdr), type_size((enum ap_var_type)phdr.type));
    return true;
}
Example #7
0
 std::string format(context* c) {
     typedef typename unwrap<BOOST_DEDUCED_TYPENAME mpl::at<Signature,mpl::int_<Iarg+4> >::type>::result_type result_type;
     std::string format = c->type_name(type_id<result_type>());
     if(name().size()>0) format+= " " + name();
     if(valueP default_value=get_default_value(c)) {
         format +=" = " + unwrap<std::string const&>(default_value["toString"]())();
     }
     return format;
 }
Example #8
0
ErrorCode DenseTag::get_array( SequenceManager* seqman, 
                               Error* error,
                               EntityHandle h, 
                               unsigned char*& ptr,
                               size_t& count,
                               bool allocate ) 
{
  EntitySequence* seq = 0;
  ErrorCode rval = seqman->find( h, seq );
  if (MB_SUCCESS != rval) {
    if (!h) { // root set
      if (!meshValue && allocate) 
        meshValue = new unsigned char[get_size()];
      ptr = meshValue;
      count = 1;
      return MB_SUCCESS;
    }
    else { // not root set
      ptr = 0;
      count = 0;
      return ent_not_found( error, get_name(), h );
    }
  }
  
  void* mem = seq->data()->get_tag_data( mySequenceArray );
  if (!mem && allocate) {
    mem = seq->data()->allocate_tag_array( mySequenceArray, get_size(), get_default_value() );
    if (!mem) {
      error->set_last_error("Memory allocation failed for tag data");
      return MB_MEMORY_ALLOCATION_FAILED;
    }
    
    if (!get_default_value()) 
      memset( mem, 0, get_size() * seq->data()->size() );
  }
  
  ptr = reinterpret_cast<unsigned char*>(mem);
  count = seq->data()->end_handle() - h + 1;
  if (ptr)
    ptr += get_size() * (h - seq->data()->start_handle());
  return MB_SUCCESS;

}
Example #9
0
// load default values for all scalars in a sketch. This does not
// recurse into sub-objects
void AP_Param::setup_sketch_defaults(void)
{
    setup();
    for (uint8_t i=0; i<_num_vars; i++) {
        uint8_t type = PGM_UINT8(&_var_info[i].type);
        if (type <= AP_PARAM_FLOAT) {
            void *ptr = (void*)PGM_POINTER(&_var_info[i].ptr);
            set_value((enum ap_var_type)type, ptr, get_default_value(&_var_info[i].def_value));
        }
    }
}
Example #10
0
ErrorCode DenseTag::remove_data( SequenceManager* seqman,
                                 Error* error,
                                 const Range& entities )
{
  std::vector<unsigned char> zeros;
  const void* value = get_default_value();
  if (!value) {
    zeros.resize( get_size(), 0 );
    value = &zeros[0];
  }
  return clear_data( false, seqman, error, entities, value );
}
Example #11
0
// load default values for scalars in a group. This does not recurse
// into other objects. This is a static function that should be called
// in the objects constructor
void AP_Param::setup_object_defaults(const void *object_pointer, const struct GroupInfo *group_info)
{
    uintptr_t base = (uintptr_t)object_pointer;
    uint8_t type;
    for (uint8_t i=0;
         (type=PGM_UINT8(&group_info[i].type)) != AP_PARAM_NONE;
         i++) {
        if (type <= AP_PARAM_FLOAT) {
            void *ptr = (void *)(base + PGM_UINT16(&group_info[i].offset));
            set_value((enum ap_var_type)type, ptr, get_default_value(&group_info[i].def_value));
        }
    }
}
Example #12
0
ErrorCode DenseTag::get_data( const SequenceManager* seqman,
                              Error* error,
                              const Range& entities,
                              const void** pointers,
                              int* data_lengths ) const
{
  ErrorCode rval;
  size_t avail;
  const unsigned char* array = 0;

  if (data_lengths) {
    int len = get_size();
    SysUtil::setmem( data_lengths, &len, sizeof(int), entities.size() );
  }
  
  for (Range::const_pair_iterator p = entities.const_pair_begin(); 
       p != entities.const_pair_end(); ++p) {
       
    EntityHandle start = p->first;
    while (start <= p->second) {
      rval = get_array( seqman, error, start, array, avail );
      if (MB_SUCCESS != rval)
        return rval;
      
      const size_t count = std::min<size_t>(p->second - start + 1, avail);
      if (array) {
        for (EntityHandle end = start + count; start != end; ++start) {
          *pointers = array;
          array += get_size();
          ++pointers;
        }
      }
      else if (const void* val = get_default_value()) {
        SysUtil::setmem( pointers, &val, sizeof(void*), count );
        pointers += count;
        start += count;
      }
      else {
        return not_found( error, get_name(), start );;
      }
    }
  }
  
  return MB_SUCCESS;
}
Example #13
0
inline void *SparseTag::allocate_data(EntityHandle h,
#ifdef MOAB_HAVE_UNORDERED_MAP
                                      MapType::const_iterator iter,
#else
                                      MapType::const_iterator,
#endif
                                      bool copy_default) 
{
  void* new_data = mAllocator.allocate(get_size());
#ifdef MOAB_HAVE_UNORDERED_MAP
  mData.insert(iter, std::pair<const EntityHandle,void*>(h, new_data));
#else
  mData[h] = new_data;
#endif
  if (copy_default)
    memcpy(new_data, get_default_value(), get_size());
  return new_data;
}
Example #14
0
	checksum float_setting::get_default_value_checksum() const {
		return checksum().add_float(get_default_value());
	}
Example #15
0
// Save the variable to EEPROM, if supported
//
bool AP_Param::save(bool force_save)
{
    uint32_t group_element = 0;
    const struct GroupInfo *ginfo;
    uint8_t idx;
    const struct AP_Param::Info *info = find_var_info(&group_element, &ginfo, &idx);
    const AP_Param *ap;

    if (info == NULL) {
        // we don't have any info on how to store it
        return false;
    }

    struct Param_header phdr;

    // create the header we will use to store the variable
    if (ginfo != NULL) {
        phdr.type = PGM_UINT8(&ginfo->type);
    } else {
        phdr.type = PGM_UINT8(&info->type);
    }
    phdr.key  = PGM_UINT8(&info->key);
    phdr.group_element = group_element;

    ap = this;
    if (phdr.type != AP_PARAM_VECTOR3F && idx != 0) {
        // only vector3f can have non-zero idx for now
        return false;
    }
    if (idx != 0) {
        ap = (const AP_Param *)((uintptr_t)ap) - (idx*sizeof(float));
    }

    // scan EEPROM to find the right location
    uint16_t ofs;
    if (scan(&phdr, &ofs)) {
        // found an existing copy of the variable
        eeprom_write_check(ap, ofs+sizeof(phdr), type_size((enum ap_var_type)phdr.type));
        return true;
    }
    if (ofs == (uint16_t) ~0) {
        return false;
    }

    // if the value is the default value then don't save
    if (phdr.type <= AP_PARAM_FLOAT) {
        float v1 = cast_to_float((enum ap_var_type)phdr.type);
        float v2;
        if (ginfo != NULL) {
            v2 = get_default_value(&ginfo->def_value);
        } else {
            v2 = get_default_value(&info->def_value);
        }
        if (is_equal(v1,v2) && !force_save) {
            return true;
        }
        if (phdr.type != AP_PARAM_INT32 &&
            (fabsf(v1-v2) < 0.0001f*fabsf(v1))) {
            // for other than 32 bit integers, we accept values within
            // 0.01 percent of the current value as being the same
            return true;
        }
    }

    if (ofs+type_size((enum ap_var_type)phdr.type)+2*sizeof(phdr) >= _storage.size()) {
        // we are out of room for saving variables
        hal.console->println_P(PSTR("EEPROM full"));
        return false;
    }

    // write a new sentinal, then the data, then the header
    write_sentinal(ofs + sizeof(phdr) + type_size((enum ap_var_type)phdr.type));
    eeprom_write_check(ap, ofs+sizeof(phdr), type_size((enum ap_var_type)phdr.type));
    eeprom_write_check(&phdr, ofs, sizeof(phdr));
    return true;
}
Example #16
0
int main(int argc, const char* argv[]) {
  if (argc != 4) {
    std::cerr << "Usage: " << argv[0] << " system_xml_directory private_xml_directory command" << std::endl
              << std::endl
              << "Example: " << argv[0]
              << " /Applications/Karabiner.app/Contents/Resources"
              << " ~/Library/Application\\ Support/Karabiner"
              << " dump_data"
              << std::endl;
    exit(1);
  }

  pqrs::xml_compiler xml_compiler(argv[1], argv[2]);
  xml_compiler.reload();
  if (xml_compiler.get_error_information().get_count() > 0) {
    std::cerr << xml_compiler.get_error_information().get_message() << std::endl;
    exit(1);
  }

  std::string command(argv[3]);

  if (command == "dump_data") {
    auto v = xml_compiler.get_remapclasses_initialize_vector().get();
    for (auto& it : v) {
      std::cout << it << std::endl;
    }

  } else if (command == "dump_tree") {
    dump_tree(xml_compiler.get_preferences_checkbox_node_tree(), false);
    std::cout << std::endl;
    std::cout << std::endl;
    std::cout << "Total items: " << total_identifier_count_ << std::endl;

  } else if (command == "dump_tree_all") {
    dump_tree(xml_compiler.get_preferences_checkbox_node_tree(), true);
    std::cout << std::endl;
    std::cout << std::endl;
    std::cout << "Total items: " << total_identifier_count_ << std::endl;

  } else if (command == "dump_number") {
    dump_number(xml_compiler.get_preferences_number_node_tree());

  } else if (command == "dump_identifier_except_essential") {
    for (int i = 0;; ++i) {
      auto identifier = xml_compiler.get_identifier(i);
      if (!identifier) break;

      std::cout << *identifier << std::endl;
    }

  } else if (command == "dump_symbol_map") {
    xml_compiler.get_symbol_map().dump();

  } else if (command == "output_bridge_essential_configuration_enum_h") {
    std::cout << "enum {" << std::endl;

    for (size_t i = 0;; ++i) {
      auto essential_configuration = xml_compiler.get_essential_configuration(i);
      if (!essential_configuration) {
        std::cout << "BRIDGE_ESSENTIAL_CONFIG_INDEX__END__ = " << i << std::endl;
        break;
      }

      std::cout << "BRIDGE_ESSENTIAL_CONFIG_INDEX_" << essential_configuration->get_identifier()
                << " = " << i << ","
                << std::endl;
    }

    std::cout << "};" << std::endl;

  } else if (command == "output_bridge_essential_configuration_default_values_c") {
    for (size_t i = 0;; ++i) {
      auto essential_configuration = xml_compiler.get_essential_configuration(i);
      if (!essential_configuration) {
        break;
      }
      std::cout << essential_configuration->get_default_value()
                << ","
                << std::endl;
    }

  } else if (command == "output_bridge_essential_configuration_identifiers_m") {
    for (size_t i = 0;; ++i) {
      auto essential_configuration = xml_compiler.get_essential_configuration(i);
      if (!essential_configuration) {
        std::cout << "nil" << std::endl;
        break;
      }

      std::cout << "@\"" << essential_configuration->get_raw_identifier() << "\""
                << ","
                << std::endl;
    }
  }

  return 0;
}
Example #17
0
static int export_main(int argc, char **argv)
{
	char *p;
	char buffer[NVRAM_SPACE];
	int eq;
	int mode;
	int all, n, skip;
	char *bk, *bv, *v;

	// C, set, quote
	static const char *start[4] = { "\"", "nvram set ", "{ \"", "" };
	static const char *stop[4] = { "\"", "\"", "\" },", "" };


	getall(buffer);
	p = buffer;

	all = 1;
	for (n = 1; n < argc; ++n) {
		if (strcmp(argv[n], "--nodefaults") == 0) {
			if (argc < 3) help();
			all = 0;
			if (n == 1) ++argv;
			break;
		}
	}

	if (strcmp(argv[1], "--dump") == 0) {
		if (!all) help();
		for (p = buffer; *p; p += strlen(p) + 1) {
			puts(p);
		}
		return 0;
	}
	if (strcmp(argv[1], "--dump0") == 0) {
		if (!all) help();
		for (p = buffer; *p; p += strlen(p) + 1) { }
		fwrite(buffer, p - buffer, 1, stdout);
		return 0;
	}

	if (strcmp(argv[1], "--c") == 0) mode = X_C;
	else if (strcmp(argv[1], "--set") == 0) mode = X_SET;
	else if (strcmp(argv[1], "--tab") == 0) mode = X_TAB;
	else if (strcmp(argv[1], "--quote") == 0) mode = X_QUOTE;
	else help();

	while (*p) {
		eq = 0;

		if (!all) {
			skip = 0;
			bk = p;
			p += strlen(p) + 1;
			bv = strchr(bk, '=');
			*bv++ = 0;

			if ((v = (char *)get_default_value(bk)) != NULL) {
				skip = (strcmp(bv, v) == 0);
			}

			*(bv - 1) = '=';
			if (skip)
				continue;
			else
				p = bk;
		}

		printf("%s", start[mode]);
		do {
			switch (*p) {
			case 9:
				if (mode == X_SET) putchar(*p);
				else printf("\\t");
				break;
			case 13:
				if (mode == X_SET) putchar(*p);
				else printf("\\r");
				break;
			case 10:
				if (mode == X_SET) putchar(*p);
				else printf("\\n");
				break;
			case '"':
			case '\\':
				printf("\\%c", *p);
				break;
			case '$':
			case '`':
				if (mode != X_SET) putchar(*p);
				else printf("\\$");
				break;
			case '=':
				if ((eq == 0) && (mode > X_QUOTE)) {
					printf((mode == X_C) ? "\", \"" :
						((mode == X_SET) ? "=\"" : "\t"));
					eq = 1;
					break;
				}
				eq = 1;
			default:
				if (!isprint(*p)) printf("\\x%02x", *p);
					else putchar(*p);
				break;
			}
			++p;
		} while (*p);
		printf("%s\n", stop[mode]);
		++p;
	}
	return 0;
}