00001 #include "stdafx.h"
00002
00003 #include "FolderRep.h"
00004 #include "Dumper.h"
00005 #include "CodeGen.h"
00006 #include "algorithm"
00007
00008 #include "globals.h"
00009 extern Globals global_vars;
00010
00011
00012 FolderRep::FolderRep( BON::FCO& ptr, BON::FCO& resp_ptr)
00013 : Any( ptr)
00014 , m_fcoList()
00015 , m_fcoCardList()
00016 , m_subFolderList()
00017 , m_subCardList()
00018 , m_respPointer( resp_ptr)
00019 , m_methods()
00020 {
00021 }
00022
00023 FolderRep::~FolderRep()
00024 {
00025 m_fcoList.clear();
00026 m_fcoCardList.clear();
00027 m_subFolderList.clear();
00028 m_subCardList.clear();
00029 m_respPointer = BON::FCO();
00030 m_methods.clear();
00031 }
00032
00033
00034 std::string FolderRep::getName() const
00035 {
00036 #if(0)
00037 if (m_respPointer == BON::FCO())
00038 {
00039 global_vars.err << "Null pointer error in getFolderName\n";
00040 return std::string("Null pointer error in getFolderName");
00041 }
00042 return m_respPointer->getName();
00043 #else
00044 if( this->m_respPointer)
00045 {
00046 std::string regname = getMIRegistry()->getValueByPath( "/" + Any::NameSelectorNode_str);
00047 if( !regname.empty()) return regname;
00048 else return m_respPointer->getName();
00049 }
00050 else if ( this->m_ptr)
00051 {
00052 return m_ptr->getName();
00053 }
00054 return "NullPtrError";
00055 #endif
00056 }
00057
00058
00059 void FolderRep::addFCO( FCO * ptr, const std::string& card)
00060 {
00061 if ( std::find( m_fcoList.begin(), m_fcoList.end(), ptr) == m_fcoList.end())
00062 {
00063 m_fcoList.push_back( ptr);
00064 m_fcoCardList.push_back( card);
00065 }
00066 else
00067 global_vars.err << "CHECK: "<< ptr->getName() << " contained by folder " << getName() << " twice. Disregarded.\n";
00068 }
00069
00070
00071 bool FolderRep::isFCOContained( FCO * ptr)
00072 {
00073 return m_fcoList.end() != std::find( m_fcoList.begin(), m_fcoList.end(), ptr);
00074 }
00075
00076
00077 void FolderRep::addSubFolderRep( FolderRep *ptr, const std::string& card)
00078 {
00079 if ( std::find( m_subFolderList.begin(), m_subFolderList.end(), ptr)
00080 == m_subFolderList.end())
00081 {
00082 m_subFolderList.push_back( ptr);
00083 m_subCardList.push_back( card);
00084 }
00085 else
00086 global_vars.err << "CHECK: Folder " << ptr->getName() << " contained by folder " << getName() << " twice. Disregarded.\n";
00087 }
00088
00089
00090 void FolderRep::extendMembership()
00091 {
00092 std::vector<FCO *> temp_list;
00093 FCO_Iterator fco_it = m_fcoList.begin();
00094 for( ; fco_it != m_fcoList.end(); ++fco_it)
00095 {
00096 FCO * fco_ptr = *fco_it;
00097 std::vector<FCO*> descendants;
00098 fco_ptr->getIntDescendants( descendants);
00099 std::vector<FCO*>::iterator desc_it = descendants.begin();
00100 for( ; desc_it != descendants.end(); ++desc_it)
00101 {
00102 FCO * new_member = *desc_it;
00103 if ( temp_list.end() ==
00104 std::find( temp_list.begin(), temp_list.end(), new_member))
00105 temp_list.push_back( new_member);
00106 }
00107 }
00108
00109 m_fcoList.insert( m_fcoList.end(), temp_list.begin(), temp_list.end());
00110 }
00111
00112
00113 void FolderRep::createMethods()
00114 {
00115 std::vector<FCO *>::iterator fco_it = m_fcoList.begin();
00116 for( ; fco_it != m_fcoList.end(); ++fco_it)
00117 {
00118 CodeGen::dumpKindGetter( *fco_it, this);
00119 }
00120
00121 std::vector<FolderRep*>::iterator fold_it = m_subFolderList.begin();
00122 for( ; fold_it != m_subFolderList.end(); ++fold_it)
00123 {
00124 CodeGen::dumpFoldGetter( *fold_it, this);
00125 }
00126 }
00127
00128
00129 std::string FolderRep::doDump()
00130 {
00131 std::string h_file, c_file;
00132
00133 dumpPre( h_file, c_file);
00134
00135 if ( !m_methods.empty())
00136 h_file += CodeGen::indent(1) + "//\n" + CodeGen::indent(1) + "// kind and subfolder getters\n";
00137
00138 MethodLexicographicSort lex;
00139 std::sort( m_methods.begin(), m_methods.end(), lex);
00140
00141 std::vector<Method>::iterator i = m_methods.begin();
00142 for( ; i != m_methods.end(); ++i)
00143 {
00144 h_file += i->getHeader() + "\n";
00145 c_file += i->getSource() + "";
00146 }
00147
00148 dumpPost( h_file, c_file);
00149
00150 sendOutH( h_file);
00151 sendOutS( c_file);
00152
00153 return "";
00154 }
00155
00156 std::string FolderRep::subFolderGetterMethodName(FolderRep * fold, const std::string& diff_nmsp)
00157 {
00158 #if(LONG_NAMES)
00159 return "get_Sub_" + fold->getValidName();
00160 #else
00161 return "get" + diff_nmsp + fold->getValidName();
00162 #endif
00163 }
00164
00165
00166 std::string FolderRep::kindGetterMethodName(FCO * fco, const std::string& diff_nmsp)
00167 {
00168 #if(LONG_NAMES)
00169 return "get_Kind_" + fco->getValidName();
00170 #else
00171 return "get" + diff_nmsp + fco->getValidName();
00172 #endif
00173 }
00174
00175