libs/EDoc/TranslationUnit.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
00017 
00018 *******************************************************************************/
00019 #include "config.h"
00020 
00021 #include "EDoc/TranslationUnit.h"
00022 
00023 #include <sstream>
00024 
00025 namespace EDoc
00026 {
00027    //===========================================================================
00028    uint32_t TranslationUnit::next_id = 0;
00029    std::list<TranslationUnit> TranslationUnit::translation_units;
00030    TranslationUnit* TranslationUnit::UNKNOWN = NULL;
00031    
00032    //===========================================================================
00033    TranslationUnit::TranslationUnit()
00034    {
00035    }
00036    //===========================================================================
00037    TranslationUnit::TranslationUnit(std::string name_in, uint32_t id_in) :
00038       id(id_in),
00039       name(name_in)
00040 
00041    {
00042    }
00043    //===========================================================================
00044    TranslationUnit* TranslationUnit::GetUnknown()
00045    {
00046       if (!UNKNOWN)
00047       {
00048          translation_units.push_back(TranslationUnit("(UNKNOWN)", next_id++));
00049          UNKNOWN = &translation_units.back();
00050       }
00051       
00052       return UNKNOWN;
00053    }
00054    //===========================================================================
00055    TranslationUnit* TranslationUnit::Create(std::string name_in)
00056    {
00057       // Make sure the UNKNOWN Translation unit has been created.
00058       GetUnknown();
00059 
00060       // Create a new translation unit.
00061       translation_units.push_back(TranslationUnit(name_in, next_id++));
00062       return &translation_units.back();
00063    }
00064    //===========================================================================
00065    const std::string& TranslationUnit::GetName() const
00066    {
00067       return name;
00068    }
00069    //===========================================================================
00070    uint32_t TranslationUnit::GetID() const
00071    {
00072       return id;
00073    }
00074    //===========================================================================
00075    std::ostream& TranslationUnit::Print(std::ostream& out, 
00076       std::string prefix) const
00077    {
00078       out << prefix << "Translation Unit ID: " << id << std::endl;
00079       out << prefix << "Translation Unit Name: " << name << std::endl;
00080       return out;
00081    }
00082    //===========================================================================
00083    std::string TranslationUnit::ToString(std::string prefix) const
00084    {
00085       std::ostringstream stream;
00086       Print(stream, prefix);
00087       return stream.str();
00088    }
00089    //===========================================================================
00090 }

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1