PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_outputbuffer.cpp

http://github.com/xbmc/xbmc
C++ | 100 lines | 53 code | 12 blank | 35 comment | 5 complexity | 167e283f49ac49797b539b91afc4318c MD5 | raw file
  1/*
  2   AngelCode Scripting Library
  3   Copyright (c) 2003-2007 Andreas Jonsson
  4
  5   This software is provided 'as-is', without any express or implied 
  6   warranty. In no event will the authors be held liable for any 
  7   damages arising from the use of this software.
  8
  9   Permission is granted to anyone to use this software for any 
 10   purpose, including commercial applications, and to alter it and 
 11   redistribute it freely, subject to the following restrictions:
 12
 13   1. The origin of this software must not be misrepresented; you 
 14      must not claim that you wrote the original software. If you use
 15      this software in a product, an acknowledgment in the product 
 16      documentation would be appreciated but is not required.
 17
 18   2. Altered source versions must be plainly marked as such, and 
 19      must not be misrepresented as being the original software.
 20
 21   3. This notice may not be removed or altered from any source 
 22      distribution.
 23
 24   The original version of this library can be located at:
 25   http://www.angelcode.com/angelscript/
 26
 27   Andreas Jonsson
 28   andreas@angelcode.com
 29*/
 30
 31
 32//
 33// as_outputbuffer.cpp
 34//
 35// This class appends strings to one large buffer that can later
 36// be sent to the real output stream
 37//
 38
 39#include "as_config.h"
 40#include "as_outputbuffer.h"
 41#include "as_scriptengine.h"
 42
 43BEGIN_AS_NAMESPACE
 44
 45asCOutputBuffer::~asCOutputBuffer()
 46{
 47	Clear();
 48}
 49
 50void asCOutputBuffer::Clear()
 51{
 52	for( asUINT n = 0; n < messages.GetLength(); n++ )
 53	{
 54		if( messages[n] ) 
 55		{
 56			asDELETE(messages[n],message_t);
 57		}
 58	}
 59	messages.SetLength(0);
 60}
 61
 62void asCOutputBuffer::Callback(asSMessageInfo *msg)
 63{
 64	message_t *msgInfo = asNEW(message_t);
 65	msgInfo->section = msg->section;
 66	msgInfo->row = msg->row;
 67	msgInfo->col = msg->col;
 68	msgInfo->type = msg->type;
 69	msgInfo->msg = msg->message;
 70
 71	messages.PushLast(msgInfo);
 72}
 73
 74void asCOutputBuffer::Append(asCOutputBuffer &in)
 75{
 76	for( asUINT n = 0; n < in.messages.GetLength(); n++ )
 77		messages.PushLast(in.messages[n]);
 78	in.messages.SetLength(0);
 79}
 80
 81void asCOutputBuffer::SendToCallback(asCScriptEngine *engine, asSSystemFunctionInterface *func, void *obj)
 82{
 83	for( asUINT n = 0; n < messages.GetLength(); n++ )
 84	{
 85		asSMessageInfo msg;
 86		msg.section = messages[n]->section.AddressOf();
 87		msg.row     = messages[n]->row;
 88		msg.col     = messages[n]->col;
 89		msg.type    = messages[n]->type;
 90		msg.message = messages[n]->msg.AddressOf();
 91
 92		if( func->callConv < ICC_THISCALL )
 93			engine->CallGlobalFunction(&msg, obj, func, 0);
 94		else
 95			engine->CallObjectMethod(obj, &msg, func, 0);
 96	}
 97	Clear();
 98}
 99
100END_AS_NAMESPACE