1 // Warnings.h 2 3 #include "Warnings.h" 4 5 #include <stdio.h> 6 7 // constructor 8 Warnings::Warnings() 9 : fWarnings() 10 { 11 } 12 13 // destructor 14 Warnings::~Warnings() 15 { 16 for (int32 i = 0; BString* warning = (BString*)fWarnings.ItemAt(i); i++) 17 delete warning; 18 } 19 20 // GetCurrentWarnings 21 Warnings* 22 Warnings::GetCurrentWarnings() 23 { 24 return fCurrentWarnings; 25 } 26 27 // SetCurrentWarnings 28 void 29 Warnings::SetCurrentWarnings(Warnings* warnings) 30 { 31 fCurrentWarnings = warnings; 32 } 33 34 // AddWarning 35 void 36 Warnings::AddWarning(BString warning) 37 { 38 fWarnings.AddItem(new BString(warning)); 39 } 40 41 // AddWarning 42 void 43 Warnings::AddWarning(const char* format,...) 44 { 45 va_list args; 46 va_start(args, format); 47 AddWarningV(format, args); 48 va_end(args); 49 } 50 51 // AddWarningV 52 void 53 Warnings::AddWarningV(const char* format, va_list arg) 54 { 55 char buffer[2048]; 56 vsprintf(buffer, format, arg); 57 AddWarning(BString(buffer)); 58 } 59 60 // AddCurrentWarning 61 void 62 Warnings::AddCurrentWarning(BString warning) 63 { 64 if (Warnings* currentWarnings = GetCurrentWarnings()) 65 currentWarnings->AddWarning(warning); 66 } 67 68 // AddCurrentWarning 69 void 70 Warnings::AddCurrentWarning(const char* format,...) 71 { 72 va_list args; 73 va_start(args, format); 74 AddCurrentWarningV(format, args); 75 va_end(args); 76 } 77 78 // AddCurrentWarningV 79 void 80 Warnings::AddCurrentWarningV(const char* format, va_list arg) 81 { 82 char buffer[2048]; 83 vsprintf(buffer, format, arg); 84 AddCurrentWarning(BString(buffer)); 85 } 86 87 // CountWarnings 88 int32 89 Warnings::CountWarnings() const 90 { 91 return fWarnings.CountItems(); 92 } 93 94 // WarningAt 95 const char* 96 Warnings::WarningAt(int32 index) const 97 { 98 const char* result = NULL; 99 if (BString* warning = (BString*)fWarnings.ItemAt(index)) 100 result = warning->String(); 101 return result; 102 } 103 104 // fCurrentWarnings 105 Warnings* Warnings::fCurrentWarnings = NULL; 106 107