Пример #1
0
/// Initialize the static type information for the "GameObject" class.
///
/// @return  Static "GameObject" type.
const GameObjectType* GameObject::InitStaticType()
{
    HELIUM_ASSERT( s_Class );
    if ( !s_Class->m_Tag )
    {
        // To resolve interdependencies between the GameObject type information and other objects (i.e. the owner
        // package, its type, etc.), we will create and register all the dependencies here manually as well.
        Name nameObject( TXT( "GameObject" ) );
        Name namePackage( TXT( "Package" ) );

        RenameParameters nameParamsObject, nameParamsPackage, nameParamsEngine, nameParamsTypes;
        nameParamsEngine.name.Set( TXT( "Engine" ) );
        nameParamsTypes.name.Set( TXT( "Types" ) );

        Package* pTypesPackage = new Package();
        HELIUM_ASSERT( pTypesPackage );
        HELIUM_VERIFY( RegisterObject( pTypesPackage ) );
        HELIUM_VERIFY( pTypesPackage->Rename( nameParamsTypes ) );

        GameObjectType::SetTypePackage( pTypesPackage );

        nameParamsEngine.spOwner = pTypesPackage;

        Package* pEnginePackage = new Package();
        HELIUM_ASSERT( pEnginePackage );
        HELIUM_VERIFY( RegisterObject( pEnginePackage ) );
        HELIUM_VERIFY( pEnginePackage->Rename( nameParamsEngine ) );

        // Don't set up templates here; they're initialized during type registration.
        GameObjectPtr spObjectTemplate = Helium::Reflect::AssertCast< GameObject >( s_Class->m_Default );
        HELIUM_ASSERT( spObjectTemplate );

        PackagePtr spPackageTemplate = new Package();
        HELIUM_ASSERT( spPackageTemplate );

        // Package flag is set automatically by the Package constructor, but it shouldn't be set for the Package
        // type template.
        spPackageTemplate->ClearFlags( FLAG_PACKAGE );

        // Initialize and register all types.
        GameObjectType::Create(
            Reflect::GetClass< GameObject >(),
            pEnginePackage,
            NULL,
            spObjectTemplate,
            GameObjectType::FLAG_ABSTRACT );

        HELIUM_VERIFY( GameObjectType::Create(
            Reflect::GetClass< Package >(),
            pEnginePackage,
            static_cast< const GameObjectType* >( s_Class->m_Tag ),
            spPackageTemplate,
            0 ) );

        // Force initialization of Package so it can report its static type information.
        HELIUM_VERIFY( Package::InitStaticType() );
    }

    return static_cast< const GameObjectType* >( s_Class->m_Tag );
}
Пример #2
0
//throw on error
static ResolutionResult checkImport(const PackageManager& pm, const ParseResultPtr& pr, const std::string& pkgName, const CustomTypeExprNode* tnode, const std::string& type)
{
    PackagePtr pkg = pm.package(pkgName);
    NodePtr node = pkg->getExport(type);
    TypeKind kind;
    if (node) {
        switch (node->type()) {
        case NodeType_InterfaceDecl:
            kind = TypeKind_Interface;
            break;
        case NodeType_EnumDecl:
            kind = TypeKind_Enum;
            break;
        case NodeType_StructDecl:
            kind = TypeKind_Struct;
            break;
        default:
            pr->addDiag(Diagnostic(DiagnosticType_Error, "'" + type + "' in package '" + pkgName + "' is not a type", tnode->loc()));
            throw std::runtime_error("Not a type");
            break;
        }
        return ResolutionResult(pkgName, type, kind);
    }
    pr->addDiag(Diagnostic(DiagnosticType_Error, "Can't find '" + type + "' in package '" + pkgName + "'", tnode->loc()));
    throw std::runtime_error("Can't find import");
}
Пример #3
0
void Package::install()
{
    if(m_packageManager != nullptr)
    {
        //Check if the package already exists. 
        PackagePtr package = m_packageManager->getPackageFromName(getConfigVar(Name));
        
        //Compare the versions if older version exist.
        if(package)
        {
            LOG(INFO) << "The package named \"" << getConfigVar(Name) << "\" is already installed. (Version: " << package->getVersion().asString() << ").";
            packaging::Version oldVersion = package->getVersion();
            if(oldVersion < getVersion())
            {
                LOG(INFO) << "Replacing older version " << package->getVersion().asString() << " of package \"" << getConfigVar(Name) << "\" with newer version " << getVersion().asString() << ".";
            }
            else
            {
                LOG(INFO) << "Replacing newer version " << package->getVersion().asString() << " of package \"" << getConfigVar(Name) << "\" with older version " << getVersion().asString() << ".";
            }
        }
    }
    
    if(flagActive(IsLoadedFromPPK))
    {
        //Install from archive
        archiveInstall();
    }
    else
    {
        //Install from directory
        directoryInstall();
    }
}
Пример #4
0
std::string ReadiumJSApi::getBookTitle()
{
	if (pkg)
	{
		pkg->BasePath();
		return pkg->Title().c_str();
	}
	return "";
}
Пример #5
0
bool ReadiumJSApi::getByteResp(std::string sURI, BYTE** bytes, ULONGLONG* pSize)
{
//	CSingleLock lock(&g_cs, TRUE);
	//QByteArray byteArr;
	//sURI = sURI.mid(1);
	//qDebug() << "Getting URI:" << sURI;
		
	unique_ptr<ByteStream> stream = pkg->ReadStreamForRelativePath(sURI.substr(1));
	if (stream)
	{
		ByteStream::size_type bytesAvailable = stream->BytesAvailable();
		if (bytesAvailable > 0)
		{
			char* buf = new char[bytesAvailable * 2];
			//memset(buf, 0, bytesAvailable);

			stream->ReadBytes(buf, bytesAvailable);
			*pSize = bytesAvailable;
			*bytes = (BYTE*)buf;
			return true;

		}
	}
	return false;
}
Пример #6
0
std::list<std::pair<std::string, std::string> > ReadiumJSApi::getSpineList()
{
//	CSingleLock lock(&g_cs, TRUE);

	std::list<std::pair<std::string, std::string> > ret;
	if (!pkg)
		return ret;
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	size_t idx = 0;
	shared_ptr<SpineItem>   pSpineItem = pkg->SpineItemAt(idx++);
	//listTOC->clear();
	//listTOC->addItem(new QListWidgetItem());
	while (pSpineItem != 0)
	{
		QJsonObject curItem;
		shared_ptr<ManifestItem>    manifestItem = pSpineItem->ManifestItem();
		//qDebug() << pSpineItem->Title().c_str();
		//pSpineItem->Title();	// TOC title
		if (manifestItem)
		{
			//qDebug() << QString(manifestItem->BaseHref().c_str());
			ret.push_back(std::make_pair(manifestItem->BaseHref().c_str(), manifestItem->BaseHref().c_str()));
			//listTOC->addItem(QString(manifestItem->BaseHref().c_str()));
			//curItem["href"] = QString(manifestItem->BaseHref().c_str());	//[dict setObject : _href forKey : @"href"];
		}
		//else
		//curItem["href"] = QString("");


		//curItem["idref"] = QString(pSpineItem->Idref().c_str());	//[dict setObject : _idref forKey : @"idref"];
		pSpineItem = pkg->SpineItemAt(idx++);
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	return ret;
	// TOC TOC TOC
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//shared_ptr<NavigationTable> toc = pkg->TableOfContents();
	//const NavigationList& list = toc->Children();
	////qDebug() << toc->SourceHref().c_str();
	//for (NavigationList::const_iterator v = list.begin(); v != list.end(); ++v)
	//{
	//	//qDebug() << (*v)->Title().c_str();
	//}
}
Пример #7
0
std::string ReadiumJSApi::getBasePath()
{
	if (pkg)
	{
		return pkg->BasePath().c_str();
	}
	return "";
}
Пример #8
0
void importExportDeclVisitor(const NodePtr& parent, const NodePtr& node, PackagePtr& pkg) {
    //we care only about toplevel decl
    if (parent)
        return;

    switch (node->type()) {
    // EXPORT
    case NodeType_InterfaceDecl: {
        InterfaceDeclNode* tnode = static_cast<InterfaceDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_StructDecl: {
        StructDeclNode* tnode = static_cast<StructDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_FnDecl: {
        FnDeclNode* tnode = static_cast<FnDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_ConstDecl: {
        ConstDeclNode* tnode = static_cast<ConstDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_ObjectDef: {
        ObjectDefNode* tnode = static_cast<ObjectDefNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_TypeDefDecl: {
        TypeDefDeclNode* tnode = static_cast<TypeDefDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }
    case NodeType_EnumDecl: {
        EnumDeclNode* tnode = static_cast<EnumDeclNode*>(node.get());
        pkg->addMember(tnode->name, node);
        return;
    }

    // IMPORT
    case NodeType_Import: {
        ImportNode* tnode = static_cast<ImportNode*>(node.get());
        pkg->addImport(tnode->name, node);
        return;
    }
    default: {
        return;
    }
    }
}
Пример #9
0
int main(int argc, char **argv) {
  if (argc < 2) {
    std::cerr << "Syntax: cpp_introspection_test <filename or path> [<message type>]" << std::endl;
    exit(1);
  }

  load(argv[1]);
  if (packages().empty()) return 1;

  if (argc < 3) {
    PackagePtr package = packages().back();
    std::cout << "Introspecting package " << package->getName() << "..." << std::endl;
    for(Package::const_iterator it = package->begin(); it != package->end(); ++it) {
      MessagePtr message = *it;
      std::cout << std::endl << "Creating an instance of " << message->getName() << "..." << std::endl;
      VoidPtr instance = message->createInstance();
      MessagePtr introspected = message->introspect(instance.get());
      print_introspection(introspected);
      std::cout << std::endl << "...and expanded ..." << std::endl;
      print_introspection(expand(introspected));
    }

  } else {
    std::cout << std::endl << "Introspecting " << argv[2] << ":" << std::endl;
    MessagePtr introspected = messageByDataType(argv[2]);
    if (!introspected) {
      std::cout << "I am sorry, I don't know that message type." << std::endl;
    } else {
      V_string fields, types;
      introspected->getFields(fields, true);
      introspected->getTypes(types, true);
      assert(fields.size() == types.size());
      for(size_t i = 0; i < fields.size(); ++i) {
        std::cout << "  " << types[i] << "\t" << fields[i] << std::endl;
      }
    }
  }

  exit(0);
}
Пример #10
0
void ReadiumJSApi::getTOCList(TOCEntry &rOut)
{
	std::list<std::pair<std::string, std::string> > lst;
	if (!pkg)
		return;

	rOut = TOCEntry("TOC", "");

	shared_ptr<NavigationTable> toc = pkg->TableOfContents();
	const NavigationList& list = toc->Children();

	digInto(list, rOut);
}
Пример #11
0
//throw on error
ResolutionResult PackageManager::resolveImport(const ParseResultPtr& pr, const PackagePtr& pkg, const CustomTypeExprNode* tnode)
{
    const std::string type = tnode->value;
    qiLogVerbose() << "Resolving: " << type << " from package: " << pkg->_name;
    const auto lastDot = type.find_last_of('.');
    const std::string pkgName = (lastDot == std::string::npos) ? "" : type.substr(0, lastDot);
    const auto valueBegins = pkgName.empty() ? 0 : (pkgName.size() + 1);
    std::string value = type.substr(valueBegins);

    //package name provided
    if (!pkgName.empty() && pkgName != type)
        return checkImport(*this, pr, pkgName, tnode, value);
    value = type;

    //no package name. find the package name
    NodePtr exportnode = pkg->getExport(type);
    if (exportnode)
        return checkImport(*this, pr, pkg->_name, tnode, type);

    ASTMap::const_iterator it;
    for (it = pkg->_imports.begin(); it != pkg->_imports.end(); ++it) {
        const NodePtrVector& v = it->second;
        for (unsigned i = 0; i < v.size(); ++i) {
            ImportNode* inode = static_cast<ImportNode*>(v.at(i).get());
            switch (inode->importType) {
            case ImportType_All: {
                return checkImport(*this, pr, inode->name, tnode, type);
            }
            case ImportType_List: {
                StringVector::iterator it = std::find(inode->imports.begin(), inode->imports.end(), type);
                if (it != inode->imports.end()) {
                    return checkImport(*this, pr, inode->name, tnode, type);
                }
                break;
            }
            case ImportType_Package:
                break;
            }
        }
    }
    pr->addDiag(Diagnostic(DiagnosticType_Error, "cant resolve id '" + type + "' from package '" + pkg->_name + "'", tnode->loc()));
    throw std::runtime_error("cant resolve id");
}
Пример #12
0
}

static void PrintNavTable(NavigationTablePtr nav)
{
    std::cerr << "Title: " << nav->Title() << std::endl;
    std::cerr << "Type:  " << nav->Type()  << std::endl;

    for (auto& child : nav->Children())
    {
        PrintNavElement(child, 1);
    }
}

TEST_CASE("ePub2 files should have a Table of Contents", "")
{
    PackagePtr pkg = GetEPUB2Container()->DefaultPackage();
    auto toc = pkg->TableOfContents();
    REQUIRE(bool(toc));

    //PrintNavTable(toc);
}

TEST_CASE("ePub3 files should have a Table of Contents", "")
{
    PackagePtr pkg = GetEPUB3Container()->DefaultPackage();
    auto toc = pkg->TableOfContents();
    REQUIRE(bool(toc));

    //PrintNavTable(toc);
}
Пример #13
0
//

#include <ePub3/container.h>
#include <ePub3/package.h>
#include <ePub3/spine.h>
#include "catch.hpp"

#define LR_SPREAD_EPUB_PATH "TestData/page-blanche.epub"
#define NO_SPREAD_EPUB_PATH "TestData/cole-voyage-of-life-20120320.epub"

using namespace ePub3;

TEST_CASE("Page spread comes back correctly", "")
{
    ContainerPtr c = Container::OpenContainer(LR_SPREAD_EPUB_PATH);
    PackagePtr pkg = c->DefaultPackage();
    
    SpineItemPtr item = pkg->FirstSpineItem();
    REQUIRE(item->Spread() == PageSpread::Right);
    
    item = item->Next();
    REQUIRE(item->Spread() == PageSpread::Left);
}

TEST_CASE("Multiple spine item properties should work", "")
{
    ContainerPtr c = Container::OpenContainer(NO_SPREAD_EPUB_PATH);
    PackagePtr pkg = c->DefaultPackage();
    
    SpineItemPtr item = pkg->SpineItemWithIDRef("s1b");
    REQUIRE(bool(item));
Пример #14
0
json::Object ReadiumJSApi::getPackageJSON(PackagePtr pckg)
{
    json::Object obj;

    // Level 0
    {
        obj["rootUrl"] = std::string("/");			//[dict setObject : @"/" forKey:@"rootUrl"];
        obj["rendition_layout"] = std::string("");	//[dict setObject : _rendition_layout forKey : @"rendition_layout"];
        obj["rendition_flow"] = std::string("");	//[dict setObject : _rendition_flow forKey : @"rendition_flow"];

        json::Object spine;

        json::Array spineItems;

        size_t idx = 0;
        shared_ptr<SpineItem>   pSpineItem = pckg->SpineItemAt(idx++);
        while (pSpineItem != 0)
        {
            json::Object curItem;
            shared_ptr<ManifestItem>    manifestItem = pSpineItem->ManifestItem();
            if (manifestItem)
            {
                 curItem["href"] = std::string(manifestItem->BaseHref().c_str());	//[dict setObject : _href forKey : @"href"];
            }
            else
                curItem["href"] = std::string("");


            curItem["idref"] = std::string(pSpineItem->Idref().c_str());	//[dict setObject : _idref forKey : @"idref"];
            curItem["media_type"] = std::string(pSpineItem->ManifestItem()->MediaType().c_str());	//[dict setObject : _idref forKey : @"idref"];

            //pSpineItem->Spread()
            //enum class PageSpread
            //{
            //	Automatic,              ///< No value specified by the author.
            //	Left,                   ///< This is the left page of a spread.
            //	Right,                  ///< This is the right page of a spread.
            //	Center,                 ///< This is a double-width page, spread across both left & right.
            //};


            curItem["page_spread"] = std::string("");       //[dict setObject : _page_spread forKey : @"page_spread"];
            curItem["rendition_layout"] = std::string("");  //[dict setObject : _rendition_layout forKey : @"rendition_layout"];
            curItem["rendition_spread"] = std::string("");  //[dict setObject : _rendition_spread forKey : @"rendition_spread"];
            curItem["rendition_flow"] = std::string("");    //[dict setObject : _rendition_flow forKey : @"rendition_flow"];
            curItem["media_overlay_id"] = std::string("");  //[dict setObject : _media_overlay_id forKey : @"media_overlay_id"];
            spineItems.push_back(curItem);

            pSpineItem = pckg->SpineItemAt(idx++);
        }

        spine["items"] = spineItems;
        spine["direction"] = std::string("default"); //[dict setObject : _direction forKey : @"direction"];
        obj["spine"] = spine;                        //[dict setObject : [_spine toDictionary] forKey : @"spine"];


        json::Object media_overlay;

        {
            std::shared_ptr<MediaOverlaysSmilModel>   smilModel = pckg->MediaOverlaysSmilModel();
            std::vector<std::shared_ptr<SMILData>>::size_type n = smilModel->GetSmilCount();
            json::Array smil_models;
            std::vector<std::shared_ptr<SMILData>>::size_type i = 0;
            for (i = 0; i < n; ++i)
            {
                std::shared_ptr<SMILData> curSmil = smilModel->GetSmil(i);
                json::Object smilModel;

                if (curSmil->XhtmlSpineItem())
                    smilModel["spineItemId"] = std::string(curSmil->XhtmlSpineItem()->Idref().c_str());
                else
                    smilModel["spineItemId"] = std::string("");

                //smilModel["id"]

                std::ostringstream stringStream;
                stringStream << curSmil->DurationMilliseconds_Calculated() / 1000.;
                std::string copyOfStr = stringStream.str();

                smilModel["duration"] = copyOfStr;

                if (curSmil->SmilManifestItem())
                {
                    smilModel["id"] = std::string(curSmil->SmilManifestItem()->Identifier().c_str());
                    smilModel["href"] = std::string(curSmil->SmilManifestItem()->Href().c_str());
                }
                else
                {
                    smilModel["id"] = std::string("");
                    smilModel["href"] = std::string("fake.smil");
                }

                smilModel["smilVersion"] = std::string("3.0");
                //[dict setObject : self.children forKey : @"children"];


                shared_ptr<const ePub3::SMILData::Sequence> seqBody = curSmil->Body();
                json::Array arrChildren = getJSON(seqBody);
                smilModel["children"] = arrChildren;
                smil_models.push_back(smilModel);
            }

            /*
            [dict setObject : smilDictionaries forKey : @"smil_models"];
            {
            for (DNSmilModel *mo in _smilModels) {
            [smilDictionaries addObject : [mo toDictionary]];
            }
            [
            [dict setObject : self.id forKey : @"id"];
            [dict setObject : self.spineItemId forKey : @"spineItemId"];
            [dict setObject : self.href forKey : @"href"];
            [dict setObject : self.smilVersion forKey : @"smilVersion"];

            [dict setObject : self.duration forKey : @"duration"];

            [dict setObject : self.children forKey : @"children"];
            ]
            }*/
            media_overlay["smil_models"] = smil_models;

            json::Array skippables;
            json::Array escapables;

            smilModel = pckg->MediaOverlaysSmilModel();
            
            if (smilModel)
            {
                std::vector<string>::size_type nCount = smilModel->GetSkippablesCount();
                for (std::vector<string>::size_type i = 0; i < nCount; ++i)
                {
                    string sSkippable = smilModel->GetSkippable(i);
                    skippables.push_back(sSkippable.c_str());
                }

                nCount = smilModel->GetEscapablesCount();
                for (std::vector<string>::size_type i = 0; i < nCount; ++i)
                {
                    string sEsc = smilModel->GetEscapable(i);
                    escapables.push_back(sEsc.c_str());
                }

            }
            media_overlay["skippables"] = skippables;//[dict setObject : self.skippables forKey : @"skippables"];
            media_overlay["escapables"] = escapables;//[dict setObject : self.escapables forKey : @"escapables"];
            media_overlay["duration"] = std::string(pckg->MediaOverlays_DurationTotal().c_str()); //[dict setObject : self.duration forKey : @"duration"]; = 1403.5
            media_overlay["narrator"] = std::string(pckg->MediaOverlays_Narrator().c_str());//[dict setObject : self.narrator forKey : @"narrator"];
            media_overlay["activeClass"] = std::string(pckg->MediaOverlays_ActiveClass().c_str());//[dict setObject : self.activeClass forKey : @"activeClass"];, "activeClass" : "-epub-media-overlay-active",
            media_overlay["playbackActiveClass"] = std::string(pckg->MediaOverlays_PlaybackActiveClass().c_str());//[dict setObject : self.playbackActiveClass forKey : @"playbackActiveClass"];
        }
        obj["media_overlay"] = media_overlay; //[dict setObject : [_mediaOverlay toDictionary] forKey : @"media_overlay"];

        return obj;
    }
		
    return obj;
}