Ejemplo n.º 1
0
bool Foam::functionEntries::includeEntry::execute
(
    dictionary& parentDict,
    Istream& is
)
{
    const fileName rawFName(is);
    const fileName fName
    (
        includeFileName(is.name().path(), rawFName, parentDict)
    );
    IFstream ifs(fName);

    if (ifs)
    {
        if (Foam::functionEntries::includeEntry::log)
        {
            Info<< fName << endl;
        }
        parentDict.read(ifs);
        return true;
    }
    else
    {
        FatalIOErrorInFunction
        (
            is
        )   << "Cannot open include file "
            << (ifs.name().size() ? ifs.name() : rawFName)
            << " while reading dictionary " << parentDict.name()
            << exit(FatalIOError);

        return false;
    }
}
Ejemplo n.º 2
0
bool Foam::functionEntries::includeIfPresentEntry::execute
(
    dictionary& parentDict,
    Istream& is
)
{
    IFstream ifs(includeFileName(is));

    if (ifs)
    {
        parentDict.read(ifs);
    }

    return true;
}
Ejemplo n.º 3
0
bool Foam::functionEntries::includeIfPresentEntry::execute
(
    const dictionary& parentDict,
    primitiveEntry& entry,
    Istream& is
)
{
    IFstream ifs(includeFileName(is));

    if (ifs)
    {
        entry.read(parentDict, ifs);
    }

    return true;
}
Ejemplo n.º 4
0
void WizardsPlugin::CreateClass(const NewClassInfo &info)
{
    // Start by finding the best choice for tabs/spaces.
    // Use the preference for the target VirtualDir, not the active project, in case the user perversely adds to an inactive one.
    OptionsConfigPtr options = EditorConfigST::Get()->GetOptions();	// Globals first
    wxString TargetProj = info.virtualDirectory.BeforeFirst(wxT(':'));
    if (!TargetProj.empty()) {
        LocalWorkspaceST::Get()->GetOptions(options, TargetProj);	// Then override with any local ones
    }

    wxString separator(wxT("\t"));
    if (!options->GetIndentUsesTabs()) {
        separator = wxString(wxT(' '), wxMax(1, options->GetTabWidth()));
    }

    wxString macro(info.blockGuard);
    if( macro.IsEmpty() ) {
        // use the name instead
        macro = info.name;
        macro.MakeUpper();
        macro << (info.hppHeader ? wxT("_HPP") : wxT("_H"));
    }

    wxString headerExt = (info.hppHeader ? wxT(".hpp") : wxT(".h"));

    wxString srcFile;
    srcFile << info.path << wxFileName::GetPathSeparator() << info.fileName << wxT(".cpp");

    wxString hdrFile;
    hdrFile << info.path << wxFileName::GetPathSeparator() << info.fileName << headerExt;

    //create cpp + h file
    wxString cpp;
    wxString header;

    //----------------------------------------------------
    // header file
    //----------------------------------------------------
    header << wxT("#ifndef ") << macro << wxT("\n");
    header << wxT("#define ") << macro << wxT("\n");
    header << wxT("\n");

    wxString closeMethod;
    if (info.isInline)
        closeMethod << wxT('\n') << separator << wxT("{\n") << separator << wxT("}\n");
    else
        closeMethod = wxT(";\n");

    // Add include for base classes
    if (info.parents.empty() == false) {
        for (size_t i=0; i< info.parents.size(); i++) {

            ClassParentInfo pi = info.parents.at(i);

            // Include the header name only (no paths)
            wxFileName includeFileName(pi.fileName);
            header << wxT("#include \"") << includeFileName.GetFullName() << wxT("\" // Base class: ") << pi.name << wxT("\n");
        }
        header << wxT("\n");
    }

    // Open namespace
    if (!info.namespacesList.IsEmpty()) {
        WriteNamespacesDeclaration (info.namespacesList, header);
    }

    header << wxT("class ") << info.name;

    if (info.parents.empty() == false) {
        header << wxT(" : ");
        for (size_t i=0; i< info.parents.size(); i++) {
            ClassParentInfo pi = info.parents.at(i);
            header << pi.access << wxT(" ") << pi.name << wxT(", ");
        }
        header = header.BeforeLast(wxT(','));
    }
    header << wxT("\n{\n");

    if (info.isSingleton) {
        header << separator << wxT("static ") << info.name << wxT("* ms_instance;\n\n");
    }

    if (info.isAssingable == false) {
        //declare copy constructor & assingment operator as private
        header << wxT("private:\n");
        header << separator << info.name << wxT("(const ") << info.name << wxT("& rhs)") << closeMethod;
        header << separator << info.name << wxT("& operator=(const ") << info.name << wxT("& rhs)") << closeMethod;
        header << wxT("\n");
    }

    if (info.isSingleton) {
        header << wxT("public:\n");
        header << separator << wxT("static ") << info.name << wxT("* Instance();\n");
        header << separator << wxT("static void Release();\n\n");

        header << wxT("private:\n");
        header << separator << info.name << wxT("();\n");

        if (info.isVirtualDtor) {
            header << separator << wxT("virtual ~") << info.name << wxT("();\n\n");
        } else {
            header << separator << wxT('~') << info.name << wxT("();\n\n");
        }
    } else {
        header << wxT("public:\n");
        header << separator << info.name << wxT("()") << closeMethod;
        if (info.isVirtualDtor) {
            header << separator << wxT("virtual ~") << info.name << wxT("()") << closeMethod << wxT("\n");
        } else {
            header << separator << wxT('~') << info.name << wxT("()") << closeMethod << wxT("\n");
        }

    }

    //add virtual function declaration
    wxString v_decl = DoGetVirtualFuncDecl(info, separator);
    if (v_decl.IsEmpty() == false) {
        header << wxT("public:\n");
        header << v_decl;
    }

    header << wxT("};\n\n");

    // Close namespaces
    for (unsigned int i = 0; i < info.namespacesList.Count(); i++) {
        header << wxT("}\n\n");
    }

    header << wxT("#endif // ") << macro << wxT("\n");

    wxFFile file;

    file.Open(hdrFile, wxT("w+b"));
    file.Write(header);
    file.Close();

    //if we have a selected virtual folder, add the files to it
    wxArrayString paths;
    paths.Add(hdrFile);

    //----------------------------------------------------
    // source file
    //----------------------------------------------------
    if (!info.isInline) {
        cpp << wxT("#include \"") << info.fileName << headerExt << wxT("\"\n\n");

        // Open namespace
        if (!info.namespacesList.IsEmpty()) {
            WriteNamespacesDeclaration (info.namespacesList, cpp);
        }

        if (info.isSingleton) {
            cpp << info.name << wxT("* ") << info.name << wxT("::ms_instance = 0;\n\n");
        }
        //ctor/dtor
        cpp << info.name << wxT("::") << info.name << wxT("()\n");
        cpp << wxT("{\n}\n\n");
        cpp << info.name << wxT("::~") << info.name << wxT("()\n");
        cpp << wxT("{\n}\n\n");
        if (info.isSingleton) {
            cpp << info.name << wxT("* ") << info.name << wxT("::Instance()\n");
            cpp << wxT("{\n");
            cpp << separator << wxT("if (ms_instance == 0) {\n");
            cpp << separator << separator << wxT("ms_instance = new ") << info.name << wxT("();\n");
            cpp << separator << wxT("}\n");
            cpp << separator << wxT("return ms_instance;\n");
            cpp << wxT("}\n\n");

            cpp << wxT("void ") << info.name << wxT("::Release()\n");
            cpp << wxT("{\n");
            cpp << separator << wxT("if (ms_instance) {\n");
            cpp << separator << separator << wxT("delete ms_instance;\n");
            cpp << separator << wxT("}\n");
            cpp << separator << wxT("ms_instance = 0;\n");
            cpp << wxT("}\n\n");
        }

        cpp << DoGetVirtualFuncImpl(info);

        // Close namespaces
        if (info.namespacesList.Count()) {
            cpp << wxT('\n');	// Thow in an initial \n to separate the first namespace '}' from the previous function's one
        }

        for (unsigned int i = 0; i < info.namespacesList.Count(); i++) {
            cpp << wxT("}\n\n");
        }

        file.Open(srcFile, wxT("w+b"));
        file.Write(cpp);
        file.Close();

        paths.Add(srcFile);
    }

    // We have a .cpp and an .h file, and there may well be a :src and an :include folder available
    // So try to place the files appropriately. If that fails, dump both in the selected folder
    bool smartAddFiles = EditorConfigST::Get()->GetOptions()->GetOptions() & OptionsConfig::Opt_SmartAddFiles;
    if (!smartAddFiles || ! m_mgr->AddFilesToVirtualFolderIntelligently(info.virtualDirectory, paths) )
        m_mgr->AddFilesToVirtualFolder(info.virtualDirectory, paths);

    // Open the newly created classes in codelite
    for(size_t i=0; i<paths.GetCount(); i++) {
        m_mgr->OpenFile(paths.Item(i));
    }

    // Notify codelite to parse the files
    wxCommandEvent parseEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("retag_workspace"));
    EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent(parseEvent);
}