NCBI C++ ToolKit
filecode.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: filecode.cpp 78421 2017-06-19 13:23:59Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * File generator
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbifile.hpp>
35 #include "exceptions.hpp"
36 #include "generate.hpp"
37 #include "filecode.hpp"
38 #include "type.hpp"
39 #include "typestr.hpp"
40 #include "fileutil.hpp"
41 #include "namespace.hpp"
42 #include "module.hpp"
43 #include "code.hpp"
44 #include <serial/error_codes.hpp>
45 #include <util/checksum.hpp>
46 #include <typeinfo>
47 
48 
49 #define NCBI_USE_ERRCODE_X Serial_FileCode
50 
51 
53 
55 
56 CFileCode::CFileCode(const CCodeGenerator* codeGenerator,
57  const string& baseName)
58  : m_CodeGenerator(codeGenerator),m_BaseName(baseName)
59 {
60  m_UseQuotedForm = false;
61  return;
62 }
63 
64 
66 {
67  return;
68 }
69 
70 
71 const string& CFileCode::ChangeFileBaseName(void)
72 {
73  m_BaseName += "x";
74  return GetFileBaseName();
75 }
76 
77 
79 {
80 // _ASSERT(BaseName(GetFileBaseName()).size() + 5 <= MAX_FILE_NAME_LENGTH);
81  return GetFileBaseName() + "_";
82 }
83 
84 
86 {
87  return GetFileBaseName();
88 }
89 
90 
91 string CFileCode::GetBaseHPPName(void) const
92 {
93  return GetBaseFileBaseName() + ".hpp";
94 }
95 
96 
97 string CFileCode::GetUserHPPName(void) const
98 {
99  return GetUserFileBaseName() + ".hpp";
100 }
101 
102 
103 string CFileCode::GetBaseCPPName(void) const
104 {
105  return GetBaseFileBaseName() + ".cpp";
106 }
107 
108 
109 string CFileCode::GetUserCPPName(void) const
110 {
111  return GetUserFileBaseName() + ".cpp";
112 }
113 
114 
115 string CFileCode::GetDefineBase(void) const
116 {
117  string s;
118  if (!m_Classes.empty()) {
119  const CNamespace& ns = m_Classes.begin()->ns;
120  if (!ns.InNCBI()) {
121  string t(ns);
122  ITERATE ( string, i, t ) {
123  s += (isalnum((unsigned char)*i) ? (*i) : '_');
124  }
125  }
126  }
127  ITERATE ( string, i, GetFileBaseName() ) {
128  char c = *i;
129  if ( c >= 'a' && c <= 'z' )
130  c = (char)(c + ('A' - 'a'));
131  else if ( (c < 'A' || c > 'Z') &&
132  (c < '0' || c > '9') )
133  c = '_';
134  s += c;
135  }
136  return s;
137 }
138 
139 
140 string CFileCode::GetBaseHPPDefine(void) const
141 {
142  return GetDefineBase() + "_BASE_HPP";
143 }
144 
145 
146 string CFileCode::GetUserHPPDefine(void) const
147 {
148  return GetDefineBase() + "_HPP";
149 }
150 
151 
152 string CFileCode::Include(const string& s, bool addExt) const
153 {
154  if ( s.empty() ) {
155  NCBI_THROW(CDatatoolException,eInvalidData,"Empty file name");
156  }
157 
158  switch ( s[0] ) {
159  case '<':
160  case '"':
161  return s[0] + GetStdPath(s.substr(1, s.length()-2)) + s[s.length()-1];
162  default:
163  {
164  string result(1, m_UseQuotedForm ? '\"' : '<');
165  result += GetStdPath(addExt ? (s + ".hpp") : s);
166  result += m_UseQuotedForm ? '\"' : '>';
167  return result;
168  }
169  }
170 }
171 
172 
173 string CFileCode::GetMethodPrefix(void) const
174 {
175  return kEmptyStr;
176 }
177 
178 
180 {
181  return m_HPPIncludes;
182 }
183 
184 
186 {
187  return m_CPPIncludes;
188 }
189 
190 
191 void CFileCode::AddForwardDeclaration(const string& cls, const CNamespace& ns)
192 {
194 }
195 
196 
198 {
199  _ASSERT(m_CurrentClass != 0);
200  return m_CurrentClass->ns;
201 }
202 
203 
205 {
208 }
209 
210 
212 {
215 }
216 
217 
219 {
222 }
223 
225 {
226  m_UseQuotedForm = use;
227 }
228 
229 void CFileCode::CreateFileFolder(const string& fileName) const
230 {
231  CDirEntry entry(fileName);
232  CDir dir(entry.GetDir());
233  dir.CreatePath();
234 }
235 
237 {
238  if ( !m_Classes.empty() ) {
240  m_CurrentClass = &*i;
242  }
243  m_CurrentClass = 0;
244  }
247 }
248 
249 
251 {
252  return out <<
253  "/* $""Id$\n"
254  " * ===========================================================================\n"
255  " *\n"
256  " * PUBLIC DOMAIN NOTICE\n"
257  " * National Center for Biotechnology Information\n"
258  " *\n"
259  " * This software/database is a \"United States Government Work\" under the\n"
260  " * terms of the United States Copyright Act. It was written as part of\n"
261  " * the author's official duties as a United States Government employee and\n"
262  " * thus cannot be copyrighted. This software/database is freely available\n"
263  " * to the public for use. The National Library of Medicine and the U.S.\n"
264  " * Government have not placed any restriction on its use or reproduction.\n"
265  " *\n"
266  " * Although all reasonable efforts have been taken to ensure the accuracy\n"
267  " * and reliability of the software and data, the NLM and the U.S.\n"
268  " * Government do not and cannot warrant the performance or results that\n"
269  " * may be obtained by using this software or data. The NLM and the U.S.\n"
270  " * Government disclaim all warranties, express or implied, including\n"
271  " * warranties of performance, merchantability or fitness for any particular\n"
272  " * purpose.\n"
273  " *\n"
274  " * Please cite the author in any work or product based on this material.\n"
275  " *\n"
276  " * ===========================================================================\n"
277  " *\n";
278 }
279 
280 
282 {
284  if ( i != m_SourceFiles.begin() )
285  out << ", ";
286  {
287  CDirEntry entry(*i);
288  out << '\'' << entry.GetName() << '\'';
289  }
290  }
291  return out;
292 }
293 
294 
296 {
297  string docroot = CClassCode::GetDocRootURL();
298  string rootdir = MakeAbsolutePath(m_CodeGenerator->GetRootDir());
299  if (docroot.empty()) {
300  out << "/// ";
301  WriteSourceFile(out) << ".\n";
302  } else {
303  out << "/// <a href=\"";
305  CDirEntry entry(MakeAbsolutePath(*i));
306  string link;
307  if (!rootdir.empty()) {
308  link = NStr::Replace(entry.GetPath(),rootdir,docroot);
309  } else {
310  link = Path( docroot, entry.GetPath());
311  }
312  out << GetStdPath(link) << "\">" << entry.GetName() << "</a>\n";
313  }
314  string deffile = m_CodeGenerator->GetDefFile();
315  if (!deffile.empty()) {
316  CDirEntry entry(MakeAbsolutePath(deffile));
317  out
318  << "/// and additional tune-up parameters:\n";
319  string link;
320  if (!rootdir.empty()) {
321  link = NStr::Replace(entry.GetPath(),rootdir,docroot);
322  } else {
323  link = Path( docroot, entry.GetPath());
324  }
325  out << "/// <a href=\"" << GetStdPath(link) << "\">" << entry.GetName() << "</a>\n";
326  }
327  }
328  return out;
329 }
330 
331 
333 {
334  if (header) {
336  << " */\n\n"
337  << "/// @file " << CDirEntry(GetBaseHPPName()).GetName() << "\n"
338  << "/// Data storage class.\n"
339  << "///\n"
340  << "/// This file was generated by application DATATOOL\n"
341  << "/// using the following specifications:\n";
342  WriteSpecRefs(out) <<
343  "///\n"
344  "/// ATTENTION:\n"
345  "/// Don't edit or commit this file into CVS as this file will\n"
346  "/// be overridden (by DATATOOL) without warning!\n";
347  } else {
349  " * File Description:\n"
350  " * This code was generated by application DATATOOL\n"
351  " * using the following specifications:\n"
352  " * ";
353  WriteSourceFile(out) << ".\n"
354  " *\n"
355  " * ATTENTION:\n"
356  " * Don't edit or commit this file into CVS as this file will\n"
357  " * be overridden (by DATATOOL) without warning!\n"
358  " * ===========================================================================\n"
359  " */\n";
360  }
361  return out;
362 }
363 
364 
366 {
367  if (header) {
369  << " */\n\n"
370  << "/// @file " << CDirEntry(GetUserHPPName()).GetName() << "\n"
371  << "/// User-defined methods of the data storage class.\n"
372  << "///\n"
373  << "/// This file was originally generated by application DATATOOL\n"
374  << "/// using the following specifications:\n";
375  WriteSpecRefs(out) <<
376  "///\n"
377  "/// New methods or data members can be added to it if needed.\n";
378  string name = CDirEntry(GetBaseHPPName()).GetName();
380  out << "/// See also: " << name << "\n\n";
381  } else {
382  string base = CDirEntry(GetBaseHPPName()).GetBase();
383 // Doxygen magic
384  base = NStr::Replace(base, "_", "__");
385  base += "_8hpp.html";
386 
387  out << "/// See also: <a href=\"" << base << "\">" << name << "</a>\n\n";
388  }
389  } else {
391  " * Author: .......\n"
392  " *\n"
393  " * File Description:\n"
394  " * .......\n"
395  " *\n"
396  " * Remark:\n"
397  " * This code was originally generated by application DATATOOL\n"
398  " * using the following specifications:\n"
399  " * ";
400  WriteSourceFile(out) << ".\n"
401  " */\n";
402  }
403  return out;
404 }
405 
406 
408 {
409 #if 0
410  out << "\n"
411  "/*\n"
412  "* ===========================================================================\n"
413  "*\n"
414  "* $""Log$\n"
415  "*\n"
416  "* ===========================================================================\n"
417  "*/\n";
418 #endif
419  return out;
420 }
421 
422 void CFileCode::GenerateHPP(const string& path, string& fileName) const
423 {
424  fileName = Path(path, GetBaseHPPName());
425  CreateFileFolder(fileName);
426  CDelayedOfstream header(fileName);
427  if ( !header ) {
428  ERR_POST_X(1, Fatal << "Cannot create file: " << fileName);
429  return;
430  }
431 
432  string hppDefine = GetBaseHPPDefine();
433  WriteCopyright(header, true) <<
434  "\n"
435  "#ifndef " << hppDefine << "\n"
436  "#define " << hppDefine << "\n"
437  "\n";
438  string extra = m_CodeGenerator->GetConfig().Get("-","_extra_headers");
439  if (!extra.empty()) {
440  list<string> extra_values;
441  NStr::Split(extra, " \t\n\r,;", extra_values, NStr::fSplit_MergeDelimiters | NStr::fSplit_Truncate);
442  header << "// extra headers\n";
443  list<string>::const_iterator i;
444  for (i = extra_values.begin(); i != extra_values.end(); ++i) {
445  if (i->at(0) == '\"') {
446  header << "#include "<< *i << "\n";
447  } else {
448  header << "#include <" << *i << ">\n";
449  }
450  }
451  header << "\n";
452  }
453  header <<
454  "// standard includes\n"
455  "#include <serial/serialbase.hpp>\n";
456 
457  if ( !m_HPPIncludes.empty() ) {
458  header <<
459  "\n"
460  "// generated includes\n";
462  header <<
463  "#include " << Include(*i, true) << "\n";
464  }
465  header <<
466  '\n';
467  }
468 
469  CNamespace ns;
470  if ( !m_ForwardDeclarations.empty() ) {
471  bool begin = false;
473  ns.Set(CNamespace(i->first), header);
474  ITERATE( set<string>, s, i->second) {
475  if ( !begin ) {
476  header <<
477  "\n"
478  "// forward declarations\n";
479  begin = true;
480  }
481  header <<
482  "class " << *s << ";\n";
483  }
484  }
485  if ( begin )
486  header << '\n';
487  }
488 
489  if ( !m_Classes.empty() ) {
490  bool begin = false;
491  ITERATE ( TClasses, i, m_Classes ) {
492  if ( !i->hppCode.empty() ) {
493  ns.Set(i->ns, header);
494  if ( !begin ) {
495  header <<
496  "\n"
497  "// generated classes\n"
498  "\n";
500  header
501  << "\n"
502  << "/** @addtogroup ";
504  header << CClassCode::GetDoxygenGroup();
505  } else {
506  header << "dataspec_" << i->code->GetDoxygenModuleName();
507  }
508  header
509  << "\n *\n"
510  << " * @{\n"
511  << " */\n\n";
512  }
513  begin = true;
514  }
515  header << i->hppCode;
516  }
517  }
518  if ( begin ) {
520  header << "\n/* @} */";
521  }
522  header << "\n";
523  }
524  }
525 
526  if ( !m_Classes.empty() ) {
527  bool begin = false;
528  ITERATE ( TClasses, i, m_Classes ) {
529  if ( !i->inlCode.empty() ) {
530  ns.Set(i->ns, header, false);
531  if ( !begin ) {
532  // have inline methods
533  header <<
534  "\n"
535  "\n"
536  "\n"
537  "\n"
538  "\n"
539  "///////////////////////////////////////////////////////////\n"
540  "///////////////////// inline methods //////////////////////\n"
541  "///////////////////////////////////////////////////////////\n";
542  begin = true;
543  }
544  header << i->inlCode;
545  }
546  }
547  if ( begin ) {
548  header <<
549  "///////////////////////////////////////////////////////////\n"
550  "////////////////// end of inline methods //////////////////\n"
551  "///////////////////////////////////////////////////////////\n"
552  "\n"
553  "\n"
554  "\n"
555  "\n"
556  "\n";
557  }
558  }
559  ns.Reset(header);
560  header <<
561  "\n"
562  "#endif // " << hppDefine << "\n";
563  header.close();
564  if ( !header )
565  ERR_POST_X(2, Fatal << "Error writing file " << fileName);
566 }
567 
568 
569 void CFileCode::GenerateCPP(const string& path, string& fileName) const
570 {
571  fileName = Path(path, GetBaseCPPName());
572  CreateFileFolder(fileName);
573  CDelayedOfstream code(fileName);
574  if ( !code ) {
575  ERR_POST_X(3, Fatal << "Cannot create file: " << fileName);
576  return;
577  }
578 
579  WriteCopyright(code, false) <<
580  "\n"
581  "// standard includes\n";
582  if (!m_PchHeader.empty()) {
583  code <<
584  "#include <" << m_PchHeader << ">\n";
585  }
586  string userinc(Include(GetUserHPPName()));
587  code <<
588  "#include <serial/serialimpl.hpp>\n"
589  "\n"
590  "// generated includes\n"
591  "#include " << userinc << "\n";
592 
593  if ( !m_CPPIncludes.empty() ) {
595  string cppinc(Include(m_CodeGenerator->ResolveFileName(*i), true));
596  if (cppinc != userinc) {
597  code << "#include " << cppinc << "\n";
598  }
599  }
600  }
601 
602  CNamespace ns;
603  if ( !m_Classes.empty() ) {
604  bool begin = false;
605  ITERATE ( TClasses, i, m_Classes ) {
606  if ( !i->cppCode.empty() ) {
607  ns.Set(i->ns, code, false);
608  if ( !begin ) {
609  code <<
610  "\n"
611  "// generated classes\n"
612  "\n";
613  begin = true;
614  }
615  code << i->cppCode;
616  }
617  }
618  if ( begin )
619  code << '\n';
620  }
621  ns.Reset(code);
622 
623  code.close();
624  if ( !code )
625  ERR_POST_X(4, Fatal << "Error writing file " << fileName);
626 }
627 
628 
629 bool CFileCode::GenerateUserHPP(const string& path, string& fileName) const
630 {
631  return WriteUserFile(path, GetUserHPPName(), fileName,
633 }
634 
635 
636 bool CFileCode::GenerateUserCPP(const string& path, string& fileName) const
637 {
638  return WriteUserFile(path, GetUserCPPName(), fileName,
640 }
641 
642 bool CFileCode::ModifiedByUser(const string& fileName,
643  const list<string>& newLines) const
644 {
645  // first check if file exists
646  CNcbiIfstream in(fileName.c_str());
647  if ( !in ) {
648  // file doesn't exist -> was not modified by user
649  return false;
650  }
651 
652  CChecksum checksum;
653  bool haveChecksum = false;
654  bool equal = true;
655 
656  list<string>::const_iterator newLinesI = newLines.begin();
657  SIZE_TYPE lineOffset = 0;
658  while ( in ) {
659  char buffer[1024]; // buffer must be as big as checksum line
660  in.getline(buffer, sizeof(buffer), '\n');
661  SIZE_TYPE count = (size_t)in.gcount();
662  if ( count == 0 ) {
663  // end of file
664  break;
665  }
666  if ( haveChecksum || in.eof() ) {
667  // text after checksum -> modified by user
668  // OR
669  // partial last line -> modified by user
670  ERR_POST_X(5, Info <<
671  "Will not overwrite modified user file: "<<fileName);
672  return true;
673  }
674 
675  bool eol;
676  // check where EOL was read
677  if ( in.fail() ) {
678  // very long line
679  // reset fail flag
680  in.clear(in.rdstate() & ~in.failbit);
681  eol = false;
682  }
683  else {
684  // full line was read
685  --count; // do not include EOL symbol
686  eol = true;
687  }
688 
689  // check for checksum line
690  if ( lineOffset == 0 && eol ) {
691  haveChecksum = checksum.ValidChecksumLine(buffer, count);
692  if ( haveChecksum )
693  continue;
694  }
695 
696  // update checksum
697  checksum.AddChars(buffer, count);
698  // update equal flag
699  if ( equal ) {
700  if ( newLinesI == newLines.end() )
701  equal = false;
702  else if ( newLinesI->size() < lineOffset + count )
703  equal = false;
704  else {
705  const char* ptr = newLinesI->data() + lineOffset;
706  equal = memcmp(ptr, buffer, count) == 0;
707  }
708  }
709  lineOffset += count;
710  if ( eol ) {
711  checksum.NextLine();
712  if ( equal ) {
713  // check for end of line in newLines
714  equal = newLinesI->size() == lineOffset;
715  ++newLinesI;
716  }
717  lineOffset = 0;
718  }
719  }
720 
721  if ( haveChecksum ) {
722  // file contains valid checksum -> it was not modified by user
723  return false;
724  }
725 
726  // file doesn't have checksum
727  // we assume it modified if its content different from newLines
728  return !equal || newLinesI != newLines.end();
729 }
730 
731 
732 void CFileCode::LoadLines(TGenerateMethod method, list<string>& lines) const
733 {
735 
736  // generate code
737  (this->*method)(code);
738 
739  // get code length
740  size_t count = (size_t)GetOssSize(code);
741  if ( count == 0 ) {
742  NCBI_THROW(CDatatoolException,eInvalidData,"empty generated code");
743  }
744 
745  // get code string pointer
746  string codeStr = CNcbiOstrstreamToString(code);
747  const char* codePtr = codeStr.data();
748 
749  // split code by lines
750  while ( count > 0 ) {
751  // find end of next line
752  const char* eolPtr = (const char*)memchr(codePtr, '\n', count);
753  if ( !eolPtr ) {
754  NCBI_THROW(CDatatoolException,eInvalidData,
755  "unended line in generated code");
756  }
757 
758  // add next line to list
759  lines.push_back(kEmptyStr);
760  lines.back().assign(codePtr, eolPtr);
761 
762  // skip EOL symbol ('\n')
763  ++eolPtr;
764 
765  // update code length
766  count -= (eolPtr - codePtr);
767  // update code pointer
768  codePtr = eolPtr;
769  }
770 }
771 
772 
773 bool CFileCode::WriteUserFile(const string& path, const string& name,
774  string& fileName, TGenerateMethod method) const
775 {
776  // parse new code lines
777  list<string> newLines;
778  LoadLines(method, newLines);
779 
780  fileName = Path(path, name);
781  CreateFileFolder(fileName);
782  if ( ModifiedByUser(fileName, newLines) ) {
783  // do nothing on user modified files
784  return false;
785  }
786 
787  // write new contents of nonmodified file
788  CDelayedOfstream out(fileName);
789  if ( !out ) {
790  ERR_POST_X(6, Fatal << "Cannot create file: " << fileName);
791  return false;
792  }
793 
794  CChecksum checksum;
795  ITERATE ( list<string>, i, newLines ) {
796  checksum.AddLine(*i);
797  out << *i << '\n';
798  }
799  out << checksum;
800 
801  out.close();
802  if ( !out ) {
803  ERR_POST_X(7, "Error writing file " << fileName);
804  return false;
805  }
806  return true;
807 }
808 
809 
811 {
812  string hppDefine = GetUserHPPDefine();
813  WriteUserCopyright(header, true) <<
814  "\n"
815  "#ifndef " << hppDefine << "\n"
816  "#define " << hppDefine << "\n"
817  "\n";
818 
819  header <<
820  "\n"
821  "// generated includes\n"
822  "#include " << Include(GetBaseHPPName()) << "\n";
823 
824  CNamespace ns;
825  if ( !m_Classes.empty() ) {
826  header <<
827  "\n"
828  "// generated classes\n"
829  "\n";
830  ITERATE ( TClasses, i, m_Classes ) {
831  ns.Set(i->ns, header, false);
832  i->code->GenerateUserHPPCode(header);
833  }
834  }
835  ns.Reset(header);
836 
837  WriteLogKeyword(header);
838  header <<
839  "\n"
840  "#endif // " << hppDefine << "\n";
841 }
842 
843 
845 {
846  WriteUserCopyright(code, false) <<
847  "\n"
848  "// standard includes\n";
849  if (!m_PchHeader.empty()) {
850  code <<
851  "#include <" << m_PchHeader << ">\n";
852  }
853  code <<
854  "\n"
855  "// generated includes\n"
856  "#include " << Include(GetUserHPPName()) << "\n";
857 
858  CNamespace ns;
859  if ( !m_Classes.empty() ) {
860  code <<
861  "\n"
862  "// generated classes\n"
863  "\n";
864  ITERATE ( TClasses, i, m_Classes ) {
865  ns.Set(i->ns, code, false);
866  i->code->GenerateUserCPPCode(code);
867  }
868  }
869  ns.Reset(code);
871 }
872 
874 {
875  m_CurrentClass = &*(m_Classes.begin());
876  return m_CurrentClass->code.get();
877 }
878 
879 bool CFileCode::GetClasses(list<CTypeStrings*>& types)
880 {
881  m_CurrentClass = &*(m_Classes.begin());
882  types.clear();
883  ITERATE ( TClasses, i, m_Classes ) {
884  types.push_back(i->code.get());
885  }
886  return !types.empty();
887 }
888 
890 {
891  ITERATE ( TClasses, i, m_Classes ) {
892  if (type == i->code.get()) {
893  return i->ns;
894  }
895  }
896  return m_CurrentClass->ns;
897 }
898 
900 {
901  string idName = type->IdName() + type->GetNamespaceName();
902  if ( m_AddedClasses.find(idName) != m_AddedClasses.end() )
903  return false;
904  m_AddedClasses.insert(idName);
905  _TRACE("AddType: " << idName << ": " << typeid(*type).name());
906  m_SourceFiles.insert(type->GetSourceFileName());
907  AutoPtr<CTypeStrings> code = type->GenerateCode();
908  code->SetModuleName(type->GetModule()->GetName());
909  m_Classes.push_front(SClassInfo(type->Namespace(), code));
910  return true;
911 }
912 
913 void CFileCode::GetModuleNames( map<string, pair<string,string> >& names) const
914 {
915  CNcbiOstrstream ostr;
916  WriteSourceFile(ostr);
917 // ostr.put('\0');
918  string src_file = string(CNcbiOstrstreamToString(ostr));
919  string doxmodule_name, module_name;
920 
921  ITERATE ( TClasses, i, m_Classes ) {
922  doxmodule_name = i->code->GetDoxygenModuleName();
923  module_name = i->code->GetModuleName();
924  if (names.find(module_name) == names.end()) {
925  names[module_name] = make_pair(src_file,doxmodule_name);
926  }
927  }
928 }
929 
930 
Checksum and hash calculation classes.
CChecksum – Checksum calculator.
Definition: checksum.hpp:302
static const string & GetDocRootURL(void)
Definition: code.cpp:117
static const string & GetDoxygenGroup(void)
Definition: code.cpp:107
static bool GetDoxygenComments(void)
Definition: code.cpp:97
const string & GetRootDir(void) const
Definition: generate.hpp:118
virtual const CMemoryRegistry & GetConfig(void) const override
Definition: generate.cpp:72
const string & GetDefFile(void) const
Definition: generate.hpp:110
const string & ResolveFileName(const string &name) const
Definition: generate.cpp:225
void close(void)
Definition: fileutil.cpp:447
CDirEntry –.
Definition: ncbifile.hpp:262
CDir –.
Definition: ncbifile.hpp:1695
bool GetClasses(list< CTypeStrings * > &types)
Definition: filecode.cpp:879
TClasses m_Classes
Definition: filecode.hpp:148
void GenerateCode(void)
Definition: filecode.cpp:236
CNcbiOstream & WriteSourceFile(CNcbiOstream &out) const
Definition: filecode.cpp:281
string GetBaseFileBaseName(void) const
Definition: filecode.cpp:78
string GetBaseHPPDefine(void) const
Definition: filecode.cpp:140
virtual void AddForwardDeclaration(const string &className, const CNamespace &ns) override
Definition: filecode.cpp:191
CNcbiOstream & WriteSpecRefs(CNcbiOstream &out) const
Definition: filecode.cpp:295
void GenerateCPP(const string &path, string &fileName) const
Definition: filecode.cpp:569
void GenerateHPP(const string &path, string &fileName) const
Definition: filecode.cpp:422
CTypeStrings * GetPrimaryClass(void)
Definition: filecode.cpp:873
CNcbiOstream & WriteUserCopyright(CNcbiOstream &out, bool header) const
Definition: filecode.cpp:365
static CNcbiOstream & WriteLogKeyword(CNcbiOstream &out)
Definition: filecode.cpp:407
void UseQuotedForm(bool use)
Definition: filecode.cpp:224
virtual void AddHPPCode(const CNcbiOstrstream &code) override
Definition: filecode.cpp:204
virtual TIncludes & HPPIncludes(void) override
Definition: filecode.cpp:179
virtual void AddCPPCode(const CNcbiOstrstream &code) override
Definition: filecode.cpp:218
virtual void AddINLCode(const CNcbiOstrstream &code) override
Definition: filecode.cpp:211
string GetUserHPPName(void) const
Definition: filecode.cpp:97
bool WriteUserFile(const string &path, const string &name, string &fileName, TGenerateMethod method) const
Definition: filecode.cpp:773
string GetUserFileBaseName(void) const
Definition: filecode.cpp:85
TAddedClasses m_AddedClasses
Definition: filecode.hpp:147
string GetUserCPPName(void) const
Definition: filecode.cpp:109
void GenerateUserHPPCode(CNcbiOstream &code) const
Definition: filecode.cpp:810
virtual const CNamespace & GetNamespace(void) const override
Definition: filecode.cpp:197
~CFileCode(void)
Definition: filecode.cpp:65
const string & ChangeFileBaseName(void)
Definition: filecode.cpp:71
bool ModifiedByUser(const string &fileName, const list< string > &newLines) const
Definition: filecode.cpp:642
const string & GetFileBaseName(void) const
Definition: filecode.hpp:77
string GetDefineBase(void) const
Definition: filecode.cpp:115
virtual string GetMethodPrefix(void) const override
Definition: filecode.cpp:173
void LoadLines(TGenerateMethod method, list< string > &lines) const
Definition: filecode.cpp:732
TIncludes m_CPPIncludes
Definition: filecode.hpp:141
static string m_PchHeader
Definition: filecode.hpp:149
CNamespace GetClassNamespace(CTypeStrings *type)
Definition: filecode.cpp:889
void GetModuleNames(map< string, pair< string, string > > &names) const
Definition: filecode.cpp:913
string GetBaseHPPName(void) const
Definition: filecode.cpp:91
bool GenerateUserCPP(const string &path, string &fileName) const
Definition: filecode.cpp:636
string GetBaseCPPName(void) const
Definition: filecode.cpp:103
CFileCode(const CCodeGenerator *codeGenerator, const string &baseName)
Definition: filecode.cpp:56
SClassInfo * m_CurrentClass
Definition: filecode.hpp:143
bool AddType(const CDataType *type)
Definition: filecode.cpp:899
static CNcbiOstream & WriteCopyrightHeader(CNcbiOstream &out)
Definition: filecode.cpp:250
bool m_UseQuotedForm
Definition: filecode.hpp:135
string GetUserHPPDefine(void) const
Definition: filecode.cpp:146
void CreateFileFolder(const string &fileName) const
Definition: filecode.cpp:229
string Include(const string &s, bool addExt=false) const
Definition: filecode.cpp:152
virtual TIncludes & CPPIncludes(void) override
Definition: filecode.cpp:185
void GenerateUserCPPCode(CNcbiOstream &code) const
Definition: filecode.cpp:844
list< SClassInfo > TClasses
Definition: filecode.hpp:67
TIncludes m_HPPIncludes
Definition: filecode.hpp:140
set< string > m_SourceFiles
Definition: filecode.hpp:145
TForwards m_ForwardDeclarations
Definition: filecode.hpp:142
const CCodeGenerator * m_CodeGenerator
Definition: filecode.hpp:134
string m_BaseName
Definition: filecode.hpp:137
bool GenerateUserHPP(const string &path, string &fileName) const
Definition: filecode.cpp:629
CNcbiOstream & WriteCopyright(CNcbiOstream &out, bool header) const
Definition: filecode.cpp:332
bool InNCBI(void) const
Definition: namespace.hpp:112
void Set(const CNamespace &ns, CNcbiOstream &out, bool mainHeader=true)
Definition: namespace.cpp:89
string ToString(void) const
Definition: namespace.hpp:80
void Reset(void)
Definition: namespace.hpp:61
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
virtual void GenerateCode(CClassContext &ctx) const
Definition: typestr.cpp:215
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
bool empty() const
Definition: map.hpp:149
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
static const struct name_t names[]
std::ofstream out("events_result.xml")
main entry point for tests
string Path(const string &dir, const string &file)
Definition: fileutil.cpp:243
string GetStdPath(const string &path)
Definition: fileutil.cpp:291
string MakeAbsolutePath(const string &path)
Definition: fileutil.cpp:233
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
string
Definition: cgiapp.hpp:687
void AddLine(const char *line, size_t len)
Definition: checksum.hpp:609
bool ValidChecksumLine(const char *line, size_t len) const
Check for checksum line.
Definition: checksum.hpp:622
void NextLine(void)
Definition: checksum.cpp:365
void AddChars(const char *str, size_t len)
Update current control sum with data provided.
Definition: checksum.hpp:602
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void Fatal(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1209
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
string GetDir(EIfEmptyPath mode=eIfEmptyPath_Current) const
Get the directory component for this directory entry.
Definition: ncbifile.cpp:475
string GetBase(void) const
Get the base entry name without extension.
Definition: ncbifile.hpp:3924
bool CreatePath(TCreateFlags flags=fCreate_Default) const
Create the directory path recursively possibly more than one at a time.
Definition: ncbifile.cpp:4106
string GetName(void) const
Get the base entry name with extension (if any).
Definition: ncbifile.hpp:3916
const string & GetPath(void) const
Get entry path.
Definition: ncbifile.hpp:3910
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
Int8 GetOssSize(CNcbiOstrstream &oss)
Definition: ncbistre.hpp:821
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define kEmptyStr
Definition: ncbistr.hpp:123
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3310
@ fSplit_Truncate
Definition: ncbistr.hpp:2501
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
int i
constexpr bool empty(list< Ts... >) noexcept
EIPRangeType t
Definition: ncbi_localip.c:101
int isalnum(Uchar c)
Definition: ncbictype.hpp:62
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
std::istream & in(std::istream &in_, double &x_)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
AutoPtr< CTypeStrings > code
Definition: filecode.hpp:64
Definition: inftrees.h:24
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
static const struct type types[]
Definition: type.c:22
Modified on Sat Dec 02 09:22:15 2023 by modify_doxy.py rev. 669887