void PropertyRow::setNames(const char* name, const char* label, const char* typeName)
{
	name_ = name;
	YASLI_ASSERT(name);
	label_ = label ? label : "";
	YASLI_ASSERT(strlen(typeName));
	typeName_ = typeName;
}
int PropertyRow::childIndex(const PropertyRow* row) const
{
	YASLI_ASSERT(row);
	Rows::const_iterator it = std::find(children_.begin(), children_.end(), row);
	YASLI_ESCAPE(it != children_.end(), return -1);
	return (int)std::distance(children_.begin(), it);
}
Exemplo n.º 3
0
bool TextOArchive::joinLinesIfPossible()
{
    YASLI_ASSERT(!stack_.empty());
    std::size_t startPosition = stack_.back().startPosition;
    YASLI_ASSERT(startPosition < buffer_->size());
    int indentCount = stack_.back().indentCount;
    //YASLI_ASSERT(startPosition >= indentCount);
    if(buffer_->position() - startPosition - indentCount < std::size_t(textWidth_)) {
        char* buffer = buffer_->buffer();
        char* start = buffer + startPosition;
        char* end = buffer + buffer_->position();
        end = joinLines(start, end);
        std::size_t newPosition = end - buffer;
        YASLI_ASSERT(newPosition <= buffer_->position());
        buffer_->setPosition(newPosition);
        return true;
    }
    return false;
}
Exemplo n.º 4
0
static char* joinLines(char* start, char* end)
{
    YASLI_ASSERT(start <= end);
    char* next = start;
    while(next != end) {
        if(*next != '\t' && *next != '\r') {
            if(*next != '\n')
                *start = *next;
            else
                *start = ' ';
            ++start;
        }
        ++next;
    }
    return start;
}
void PropertyTreeModel::selectRow(PropertyRow* row, bool select, bool exclusive)
{
	if(exclusive)
		deselectAll();

	row->setSelected(select);

	Selection::iterator it = std::find(selection_.begin(), selection_.end(), pathFromRow(row));
	if(select){
		if(it == selection_.end())
			selection_.push_back(pathFromRow(row));
		setFocusedRow(row);
	}
	else if(it != selection_.end()){
		PropertyRow* it_row = rowFromPath(*it);
		YASLI_ASSERT(it_row->refCount() > 0 && it_row->refCount() < 0xFFFF);
		selection_.erase(it);
	}
}
Exemplo n.º 6
0
bool BinIArchive::Block::get(const char* name, Block& block) 
{
	if(begin_ == end_)
		return false;
	complex_ = true;
	unsigned short hashName = calcHash(name);

#ifdef YASLI_BIN_ARCHIVE_CHECK_HASH_COLLISION
	HashMap::iterator i = hashMap_.find(hashName);
	if(i != hashMap_.end() && i->second != name)
		YASLI_ASSERT(0, "BinArchive hash colliding: %s - %s", i->second.c_str(), name);
	hashMap_[hashName] = name;
#endif

	const char* currInitial = curr_;
	bool restarted = false;
	if(curr_ >= end_){
		curr_ = begin_;
		restarted = true;
	}
	for(;;){
		unsigned short hash;
		read(hash);
		unsigned int size = readPackedSize();
		
		const char* currPrev = curr_;
		if((curr_ += size) >= end_){
			if(restarted)
				return false;
			curr_ = begin_;
			restarted = true;
		}

		if(hash == hashName){
			block = Block(currPrev, size);
			return true;
		}

		if(curr_ == currInitial)
			return false;
	}
}
Exemplo n.º 7
0
bool TextOArchive::operator()(const Serializer& ser, const char* name, const char* label)
{
    placeIndent();
    placeName(name);
    std::size_t position = buffer_->position();
    openBracket();
    stack_.push_back(Level(false, position, int(strlen(name) + 2 * (name[0] & 1) + (stack_.size() - 1) * TAB_WIDTH + 2)));

    YASLI_ASSERT(ser);
    ser(*this);

    bool joined = joinLinesIfPossible();
    stack_.pop_back();
    if(!joined)
        placeIndent();
    else
        *buffer_ << " ";
    closeBracket();
    return true;
}
Exemplo n.º 8
0
inline void BinOArchive::closeNode(const char* name, bool size8)
{
#ifdef YASLI_BIN_ARCHIVE_CHECK_EMPTY_NAME_MIX
	blockTypes_.pop_back();
#endif

	if(!strlen(name))
		return;

	unsigned int offset = blockSizeOffsets_.back();
	unsigned int size = (unsigned int)(stream_.position() - offset - sizeof(unsigned char) - (size8 ? 0 : sizeof(unsigned short)));
	blockSizeOffsets_.pop_back();
	unsigned char* sizePtr = (unsigned char*)(stream_.buffer() + offset);

	if(size < SIZE16){
		*sizePtr = size;
		if(!size8){
			unsigned char* buffer = sizePtr + 3;
			memmove(buffer - 2, buffer, size);
			stream_.setPosition(stream_.position() - 2);
		}
	}
	else{
		YASLI_ASSERT(!size8);
		if(size < 0x10000){
			*sizePtr = SIZE16;
			*((unsigned short*)(sizePtr + 1)) = size;
		}
		else{
			unsigned char* buffer = sizePtr + 3;
			stream_.write((unsigned short)0);
			*sizePtr = SIZE32;
			memmove(buffer + 2, buffer, size);
			*((unsigned int*)(sizePtr + 1)) = size;
		}
	}
}
Exemplo n.º 9
0
bool BinOArchive::operator()(PointerInterface& ptr, const char* name, const char* label)
{
	openNode(name, false);

	const char* typeName = ptr.registeredTypeName();
	if (!typeName)
		typeName = "";
	if (typeName[0] == '\0' && ptr.get()) {
		YASLI_ASSERT(0 && "Writing unregistered class. Use YASLI_CLASS_NAME macro for registration.");
	}

	TypeID baseType = ptr.baseType();

	if(ptr.get()){
		stream_ << typeName;
		stream_.write(char(0));
		ptr.serializer()(*this);
	}
	else
		stream_.write(char(0));

	closeNode(name, false);
	return true;
}
bool PropertyRowBool::assignToPrimitive(void* object, size_t size) const
{
	YASLI_ASSERT(size == sizeof(bool));
	*reinterpret_cast<bool*>(object) = value_;
	return true;
}
Exemplo n.º 11
0
void BinIArchive::closeNode(const char* name, bool check) 
{
	YASLI_ASSERT(!check || currentBlock().validToClose());
	blocks_.pop_back();
}