1 #include <Format.h> 2 3 #include <new> 4 5 #include <Locale.h> 6 7 8 BFormat::BFormat() 9 : 10 fInitStatus(B_NO_INIT), 11 fLocale(NULL) 12 { 13 } 14 15 16 BFormat::BFormat(const BFormat &other) 17 : 18 fInitStatus(other.fInitStatus), 19 fLocale(other.fLocale != NULL 20 ? new (std::nothrow) BLocale(*other.fLocale) 21 : NULL) 22 { 23 } 24 25 26 BFormat::~BFormat() 27 { 28 delete fLocale; 29 } 30 31 32 BFormat & 33 BFormat::operator=(const BFormat& other) 34 { 35 if (this == &other) 36 return *this; 37 38 fInitStatus = other.fInitStatus; 39 delete fLocale; 40 fLocale = other.fLocale != NULL 41 ? new (std::nothrow) BLocale(*other.fLocale) : NULL; 42 43 if (fLocale == NULL && other.fLocale != NULL) 44 fInitStatus = B_NO_MEMORY; 45 46 return *this; 47 } 48 49 50 status_t 51 BFormat::InitCheck() const 52 { 53 return fInitStatus; 54 } 55 56 57 status_t 58 BFormat::SetLocale(const BLocale* locale) 59 { 60 if (locale != NULL) { 61 if (fLocale == NULL) { 62 fLocale = new (std::nothrow) BLocale(*locale); 63 if (fLocale == NULL) 64 return B_NO_MEMORY; 65 } else 66 *fLocale = *locale; 67 } else { 68 delete fLocale; 69 fLocale = NULL; 70 } 71 72 return B_OK; 73 } 74