Formatter.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #ifndef _OASYS_FORMATTER_H_
00019 #define _OASYS_FORMATTER_H_
00020 
00021 #include <stdio.h>
00022 #include <stdarg.h>
00023 
00024 #include "DebugDumpBuf.h"
00025 #include "DebugUtils.h"
00026 
00027 namespace oasys {
00028 
00053 class Formatter {
00054 public:
00068     virtual int format(char* buf, size_t sz) const = 0;
00069 
00076     static inline void assert_valid(const Formatter* obj);
00077 
00083     int debug_dump();
00084 
00085     virtual ~Formatter() {}
00086 
00087 #ifndef NDEBUG
00088 #define FORMAT_MAGIC 0xffeeeedd
00089     Formatter() : format_magic_(FORMAT_MAGIC) {}
00090     Formatter(const Formatter&) : format_magic_(FORMAT_MAGIC) {}
00091     unsigned int format_magic_;
00092 #else
00093     Formatter() {}
00094     Formatter(const Formatter&) {}
00095 #endif // NDEBUG
00096 
00097     
00098 };
00099 
00100 void __log_assert(bool x, const char* what, const char* file, int line);
00101 
00102 inline void
00103 Formatter::assert_valid(const Formatter* obj)
00104 {
00105     (void)obj; // avoid unused variable warning
00106 #ifndef NDEBUG
00107     __log_assert(obj->format_magic_ == FORMAT_MAGIC,
00108                  "Formatter object invalid -- maybe need a cast to Formatter*",
00109                  __FILE__, __LINE__);
00110 #endif
00111 }
00112 
00113 } // namespace oasys
00114 
00115 #endif /* _OASYS_FORMATTER_H_ */

Generated on Sat Sep 8 08:36:16 2007 for DTN Reference Implementation by  doxygen 1.5.3